Skip to content

Commit

Permalink
improved tests touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
havelaer committed Dec 9, 2017
1 parent c82e426 commit 39c0454
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
52 changes: 26 additions & 26 deletions lib/ui/src/modules/ui/libs/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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';
Expand All @@ -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);
Expand All @@ -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: '' }]);
});
});
});

0 comments on commit 39c0454

Please sign in to comment.