Skip to content

Commit

Permalink
feat(tests): add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed Dec 28, 2023
1 parent a809464 commit 525931b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,17 @@ describe('testing default X API', () => {
await vue.nextTick();
expect(storeElement).toHaveTextContent('Portugal');
});

it('should allow set the snippetConfig getter', () => {
const snippetConfig: SnippetConfig = {
instance: 'test',
scope: 'test',
lang: 'es'
};
defaultXAPI?.setSnippetConfigGetter(() => snippetConfig);

const snippet = defaultXAPI?.getSnippetConfig();

expect(snippet).toEqual(snippetConfig);
});
});
2 changes: 1 addition & 1 deletion packages/x-components/src/x-installer/api/base-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BaseXAPI implements XAPI {
*
* @public
*/
protected getSnippetConfig!: () => SnippetConfig;
public getSnippetConfig!: () => SnippetConfig;

/**
* Callback that allows to update the snippet config. The logic of initialization is out of this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { XComponentsAdapterDummy } from '../../../__tests__/adapter.dummy';
import { AnyXModule } from '../../../x-modules/x-modules.types';
import { InitWrapper, InstallXOptions } from '../types';
import { XInstaller } from '../x-installer';
import { SnippetConfig } from '../../api/index';
import { BaseXAPI, SnippetConfig } from '../../api/index';

describe('testing `XInstaller` utility', () => {
const adapter = XComponentsAdapterDummy;
Expand Down Expand Up @@ -188,6 +188,20 @@ describe('testing `XInstaller` utility', () => {
expect(app?.$el).toHaveTextContent('test-2');
});

it('should allow set the snippetConfig getter', () => {
const defaultXAPI = new BaseXAPI();
const snippetConfig: SnippetConfig = {
instance: 'test',
scope: 'test',
lang: 'es'
};
defaultXAPI?.setSnippetConfigGetter(() => snippetConfig);

const snippet = defaultXAPI?.getSnippetConfig();

expect(snippet).toEqual(snippetConfig);
});

// eslint-disable-next-line max-len
it('initializes the app when window.initX is a function retrieving the snippet config', async () => {
const vue = createLocalVue();
Expand Down

0 comments on commit 525931b

Please sign in to comment.