mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
improved tests touched files
This commit is contained in:
parent
283c7cef0b
commit
f6775ceac0
@ -2,12 +2,16 @@ import { shallow, mount } from 'enzyme';
|
||||
import React from 'react';
|
||||
import Stories from './index';
|
||||
import { setContext } from '../../../../../compose';
|
||||
import { createHierarchies, createHierarchyRoot, prepareStoriesForHierarchy } from '../../../libs/hierarchy';
|
||||
import {
|
||||
createHierarchies,
|
||||
createHierarchyRoot,
|
||||
prepareStoriesForHierarchy,
|
||||
} from '../../../libs/hierarchy';
|
||||
import { storyFilter } from '../../../libs/filters';
|
||||
|
||||
const leftClick = { button: 0 };
|
||||
|
||||
describe('manager.ui.components.left_panel.stories', () => {
|
||||
describe('manager.ui.components.stories_panel.stories_tree', () => {
|
||||
beforeEach(() =>
|
||||
setContext({
|
||||
clientStore: {
|
||||
|
@ -0,0 +1,12 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import TreeHeader from './tree_header';
|
||||
|
||||
describe('manager.ui.components.stories_panel.stories_tree.tree_header', () => {
|
||||
test('should render tree header content', () => {
|
||||
const content = 'abcd';
|
||||
const wrap = shallow(<TreeHeader>{content}</TreeHeader>);
|
||||
|
||||
expect(wrap.text()).toEqual(content);
|
||||
});
|
||||
});
|
@ -8,15 +8,15 @@ describe('manager.ui.libs.filters', () => {
|
||||
});
|
||||
|
||||
test('should original stories if there is no filter', () => {
|
||||
const stories = [{ kind: ['aa'], namespaces: ['aa'], stories: ['bb'] }];
|
||||
const stories = [{ kind: ['aa'], namespaces: ['aa'], stories: ['bb'], rootName: '' }];
|
||||
const res = storyFilter(stories);
|
||||
expect(res).toBe(stories);
|
||||
});
|
||||
|
||||
test('should always return the selectedKind', () => {
|
||||
const stories = [
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'], rootName: '' },
|
||||
];
|
||||
|
||||
const selectedKind = 'bb';
|
||||
@ -28,8 +28,8 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should always return the selectedKind with the single selectedStory', () => {
|
||||
const stories = [
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb', 'cc', 'dd'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb', 'cc', 'dd'], rootName: '' },
|
||||
];
|
||||
|
||||
const selectedKind = 'bb';
|
||||
@ -41,9 +41,9 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should filter kinds correctly', () => {
|
||||
const stories = [
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'] },
|
||||
{ kind: 'ss', namespaces: ['ss'], stories: ['bb'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'ss', namespaces: ['ss'], stories: ['bb'], rootName: '' },
|
||||
];
|
||||
const selectedKind = 'bb';
|
||||
const selectedStory = 'bb';
|
||||
@ -54,9 +54,9 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should not sort stories by kind', () => {
|
||||
const stories = [
|
||||
{ kind: 'ss', namespaces: ['ss'], stories: ['bb'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'] },
|
||||
{ kind: 'ss', namespaces: ['ss'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'], rootName: '' },
|
||||
];
|
||||
const res = storyFilter(stories);
|
||||
|
||||
@ -65,9 +65,9 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should sort stories by kind', () => {
|
||||
const stories = [
|
||||
{ kind: 'ss', namespaces: ['ss'], stories: ['bb'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'] },
|
||||
{ kind: 'ss', namespaces: ['ss'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'bb', namespaces: ['bb'], stories: ['bb'], rootName: '' },
|
||||
];
|
||||
const res = storyFilter(stories, null, null, null, true);
|
||||
|
||||
@ -76,9 +76,9 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should filter on story level', () => {
|
||||
const stories = [
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd'] },
|
||||
{ kind: 'ee', namespaces: ['ee'], stories: ['ff'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd'], rootName: '' },
|
||||
{ kind: 'ee', namespaces: ['ee'], stories: ['ff'], rootName: '' },
|
||||
];
|
||||
const selectedKind = 'aa';
|
||||
const selectedStory = 'bb';
|
||||
@ -89,21 +89,21 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should filter out unmatched stories at lowest level', () => {
|
||||
const stories = [
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd'] },
|
||||
{ kind: 'ee', namespaces: ['ee'], stories: ['ff', 'gg'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd'], rootName: '' },
|
||||
{ kind: 'ee', namespaces: ['ee'], stories: ['ff', 'gg'], rootName: '' },
|
||||
];
|
||||
const selectedKind = 'aa';
|
||||
const selectedStory = 'bb';
|
||||
const res = storyFilter(stories, 'ff', selectedKind, selectedStory);
|
||||
|
||||
expect(res).toMatchObject([stories[0], { kind: 'ee', stories: ['ff'] }]);
|
||||
expect(res).toMatchObject([stories[0], { kind: 'ee', stories: ['ff'], rootName: '' }]);
|
||||
});
|
||||
|
||||
test('should be case insensitive at tree level', () => {
|
||||
const stories = [
|
||||
{ kind: 'Aa', namespaces: ['aA'], stories: ['bb'] },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd'] },
|
||||
{ kind: 'Aa', namespaces: ['aA'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd'], rootName: '' },
|
||||
];
|
||||
const selectedKind = 'aA';
|
||||
const res = storyFilter(stories, 'aa', selectedKind);
|
||||
@ -113,14 +113,14 @@ describe('manager.ui.libs.filters', () => {
|
||||
|
||||
test('should be case insensitive at story level', () => {
|
||||
const stories = [
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'] },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd', 'eE'] },
|
||||
{ kind: 'aa', namespaces: ['aa'], stories: ['bb'], rootName: '' },
|
||||
{ kind: 'cc', namespaces: ['cc'], stories: ['dd', 'eE'], rootName: '' },
|
||||
];
|
||||
const selectedKind = 'aa';
|
||||
const selectedStory = 'bb';
|
||||
const res = storyFilter(stories, 'ee', selectedKind, selectedStory);
|
||||
|
||||
expect(res).toMatchObject([stories[0], { kind: 'cc', stories: ['eE'] }]);
|
||||
expect(res).toMatchObject([stories[0], { kind: 'cc', stories: ['eE'], rootName: '' }]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user