Skip to content

Commit

Permalink
Merge pull request #22301 from storybookjs/tom/add-mapping-tests
Browse files Browse the repository at this point in the history
Core: Add tests for mapping behaviour in #22169
  • Loading branch information
tmeasday committed Apr 28, 2023
2 parents 7090746 + 4ad3dff commit a807565
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 a807565

Please sign in to comment.