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 issue with accidentally thinking things are roots #5236

Merged
merged 1 commit into from
Jan 14, 2019
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
2 changes: 1 addition & 1 deletion lib/ui/src/core/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const initStoriesApi = ({
parent,
depth: index,
isComponent: index === original.length - 1,
isRoot: index === 0,
isRoot: !!root && index === 0,
},
]);
}, []);
Expand Down
100 changes: 92 additions & 8 deletions lib/ui/src/core/stories.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ describe('stories API', () => {
viewMode: 'components',
});
});

// A hash of stories as it will come over the channel
const parameters = { options: { hierarchyRootSeparator: '|', hierarchySeparator: '/' } };
const storiesHash = {
'a--1': { kind: 'a', name: '1', parameters: { options: {} }, path: 'a--1', id: 'a--1' },
'a--2': { kind: 'a', name: '2', parameters: { options: {} }, path: 'a--2', id: 'a--2' },
'b-c--1': { kind: 'b/c', name: '1', parameters: { options: {} }, path: 'b-c--1', id: 'b-c--1' },
'a--1': { kind: 'a', name: '1', parameters, path: 'a--1', id: 'a--1' },
'a--2': { kind: 'a', name: '2', parameters, path: 'a--2', id: 'a--2' },
'b-c--1': {
kind: 'b/c',
name: '1',
parameters,
path: 'b-c--1',
id: 'b-c--1',
},
};

describe('setStories', () => {
it('stores basic kinds and stories w/ correct keys', () => {
const navigate = jest.fn();
Expand All @@ -45,18 +49,98 @@ describe('stories API', () => {
const { storiesHash: storedStoriesHash } = store.getState();

// We need exact key ordering, even if in theory JS doens't guarantee it
expect(Object.keys(storedStoriesHash)).toEqual(['a', 'a--1', 'a--2', 'b-c', 'b-c--1']);
expect(Object.keys(storedStoriesHash)).toEqual(['a', 'a--1', 'a--2', 'b', 'b-c', 'b-c--1']);
expect(storedStoriesHash.a).toMatchObject({
id: 'a',
children: ['a--1', 'a--2'],
isRoot: false,
isComponent: true,
});

expect(storedStoriesHash['a--1']).toMatchObject({
id: 'a--1',
parent: 'a',
kind: 'a',
name: '1',
parameters: { options: {} },
parameters,
});

expect(storedStoriesHash['a--2']).toMatchObject({
id: 'a--2',
parent: 'a',
kind: 'a',
name: '2',
parameters,
});

expect(storedStoriesHash.b).toMatchObject({
id: 'b',
children: ['b-c'],
isRoot: false,
isComponent: false,
});

expect(storedStoriesHash['b-c']).toMatchObject({
id: 'b-c',
parent: 'b',
children: ['b-c--1'],
isRoot: false,
isComponent: true,
});

expect(storedStoriesHash['b-c--1']).toMatchObject({
id: 'b-c--1',
parent: 'b-c',
kind: 'b/c',
name: '1',
parameters,
});
});

it('handles roots also', () => {
const navigate = jest.fn();
const store = createMockStore();

const {
api: { setStories },
} = initStories({ store, navigate });

setStories({
'a--1': { kind: 'a', name: '1', parameters, path: 'a--1', id: 'a--1' },
'a--2': { kind: 'a', name: '2', parameters, path: 'a--2', id: 'a--2' },
'b-c--1': {
kind: 'b|c',
name: '1',
parameters,
path: 'b-c--1',
id: 'b-c--1',
},
});
const { storiesHash: storedStoriesHash } = store.getState();

// We need exact key ordering, even if in theory JS doens't guarantee it
expect(Object.keys(storedStoriesHash)).toEqual(['a', 'a--1', 'a--2', 'b', 'b-c', 'b-c--1']);
expect(storedStoriesHash.b).toMatchObject({
id: 'b',
children: ['b-c'],
isRoot: true,
isComponent: false,
});

expect(storedStoriesHash['b-c']).toMatchObject({
id: 'b-c',
parent: 'b',
children: ['b-c--1'],
isRoot: false,
isComponent: true,
});

expect(storedStoriesHash['b-c--1']).toMatchObject({
id: 'b-c--1',
parent: 'b-c',
kind: 'b|c',
name: '1',
parameters,
});
});

Expand Down