From 4ad3dff769f7dd5b495dbc23a0b8d70136b2b4d5 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Fri, 28 Apr 2023 14:52:04 +1000 Subject: [PATCH] Add tests for mapping behaviour in #22169 --- .../modules/store/csf/prepareStory.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts b/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts index 4cf8f51a3860..9ce02ca343a0 100644 --- a/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts +++ b/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts @@ -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 };