Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SdkOptions): Fix SdkOptions to return cssBundle even if there no i18n asset #601

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ilc/common/SdkOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class SdkOptions {
}

toJSON() {
if (!this.#i18n) {
return undefined;
}

return {
const json = {
i18n: this.#i18n,
cssBundle: this.#cssBundle,
};

const allValuesUndefined = Object.values(json).every((value) => value === undefined);

return allValuesUndefined ? undefined : json;
}
}

Expand Down
72 changes: 72 additions & 0 deletions ilc/common/SdkOptions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { expect } = require('chai');
const { SdkOptions } = require('./SdkOptions');

describe('SdkOptions Class', () => {
it('should return i18n and cssBundle when both are provided', () => {
const params = {
i18n: { manifestPath: '/path/to/manifest' },
cssBundle: '/path/to/cssBundle',
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.deep.equal({
i18n: params.i18n,
cssBundle: params.cssBundle,
});
});

it('should return only i18n when cssBundle is not provided', () => {
const params = {
i18n: { manifestPath: '/path/to/manifest' },
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.deep.equal({
i18n: params.i18n,
cssBundle: undefined,
});
});

it('should return only cssBundle when i18n is not provided', () => {
const params = {
cssBundle: '/path/to/cssBundle',
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.deep.equal({
i18n: undefined,
cssBundle: params.cssBundle,
});
});

it('should return undefined when no params are provided', () => {
const sdkOptions = new SdkOptions();

const result = sdkOptions.toJSON();
expect(result).to.be.undefined;
});

it('should return undefined when i18n does not have manifestPath and cssBundle is not provided', () => {
const params = {
i18n: {},
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.be.undefined;
});

it('should return undefined when both i18n and cssBundle are undefined', () => {
const params = {
i18n: undefined,
cssBundle: undefined,
};
const sdkOptions = new SdkOptions(params);

const result = sdkOptions.toJSON();
expect(result).to.be.undefined;
});
});
Loading