Skip to content

Commit

Permalink
Add tests for mapping behaviour in #22169
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Apr 28, 2023
1 parent 7090746 commit 4ad3dff
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,51 @@ describe('prepareStory', () => {
});
});

describe('mapping', () => {
it('maps labels to values in prepareContext', () => {
const story = prepareStory(
{
id,
name,
argTypes: {
one: { name: 'one', mapping: { 1: 'mapped-1' } },
},
moduleExport,
},
{ id, title },
{ render: jest.fn() }
);

const context = story.prepareContext({ args: { one: 1 }, ...story } as any);
expect(context).toMatchObject({
args: { one: 'mapped-1' },
});
});

it('maps arrays of labels to values in prepareContext', () => {
const story = prepareStory(
{
id,
name,
argTypes: {
one: { name: 'one', mapping: { 1: 'mapped-1' } },
},
moduleExport,
},
{ id, title },
{ render: jest.fn() }
);

const context = story.prepareContext({
args: { one: [1, 1] },
...story,
} as any);
expect(context).toMatchObject({
args: { one: ['mapped-1', 'mapped-1'] },
});
});
});

describe('with `FEATURES.argTypeTargetsV7`', () => {
beforeEach(() => {
global.FEATURES = { argTypeTargetsV7: true };
Expand Down

0 comments on commit 4ad3dff

Please sign in to comment.