diff --git a/src/components/copy/__snapshots__/copy.test.tsx.snap b/src/components/copy/__snapshots__/copy.test.tsx.snap new file mode 100644 index 00000000000..c5a84cdc51e --- /dev/null +++ b/src/components/copy/__snapshots__/copy.test.tsx.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`EuiCopy is rendered 1`] = ` + + + +`; diff --git a/src/components/copy/copy.test.tsx b/src/components/copy/copy.test.tsx new file mode 100644 index 00000000000..6e9d6336b15 --- /dev/null +++ b/src/components/copy/copy.test.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import { EuiCopy } from './copy'; +import { requiredProps } from '../../test'; + +describe('EuiCopy', () => { + test('is rendered', () => { + const component = shallow( + + {copy => } + + ); + expect(component).toMatchSnapshot(); + }); + + describe('props', () => { + test('beforeMessage', () => { + const component = shallow( + + {copy => } + + ); + expect(component.state('tooltipText')).toBe('copy this'); + }); + + test('afterMessage', () => { + const component = shallow( + + {copy => } + + ); + const instance = component.instance(); + expect(instance.props.afterMessage).toBe('successfuly copied'); + }); + }); +}); diff --git a/src/components/date_picker/super_date_picker/date_modes.test.js b/src/components/date_picker/super_date_picker/date_modes.test.js new file mode 100644 index 00000000000..e37eb42970f --- /dev/null +++ b/src/components/date_picker/super_date_picker/date_modes.test.js @@ -0,0 +1,44 @@ +import { getDateMode, toAbsoluteString, toRelativeString } from './date_modes'; + +jest.mock('@elastic/datemath', () => { + const moment = jest.requireActual('moment'); + const datemath = jest.requireActual('@elastic/datemath'); + const anchor = '2019-03-19T00:00:00.000Z'; + const anchoredDate = new Date(Date.parse(anchor)); + // https://momentjs.com/docs/#/customization/now/ + const offset = anchoredDate.getTime() - Date.now(); + moment.now = () => offset + Date.now(); + return { + ...datemath, + parse: (text, options) => + datemath.parse(text, { + forceNow: anchoredDate, // For `toAbsoluteString` + momentInstance: moment, // For `toRelativeString` + ...options, + }), + }; +}); + +describe('dateMode', () => { + test('getDateMode', () => { + expect(getDateMode('now')).toBe('now'); + expect(getDateMode('now/1d')).toBe('relative'); + expect(getDateMode('2020-03-19T00:00:00.000Z')).toBe('absolute'); + }); + + test('toAbsoluteString', () => { + expect(toAbsoluteString('now')).toBe('2019-03-19T00:00:00.000Z'); + expect(toAbsoluteString('now+y')).toBe('2020-03-19T00:00:00.000Z'); + expect(toAbsoluteString('now+y', true)).toBe('2020-03-19T00:00:00.000Z'); + expect(toAbsoluteString('now-1w')).toBe('2019-03-12T00:00:00.000Z'); + expect(toAbsoluteString('now-1w', true)).toBe('2019-03-12T00:00:00.000Z'); + }); + + test('toRelativeString', () => { + expect(toRelativeString('2019-03-19T00:00:00.000Z')).toBe('now'); + expect(toRelativeString('2020-03-19T00:00:00.000Z')).toBe('now+1y'); + expect(toRelativeString('2019-03-12T00:00:00.000Z')).toBe('now-1w'); + expect(toRelativeString('2019-03-17T00:00:00.000Z')).toBe('now-2d'); + expect(toRelativeString('2018-04-15T00:00:00.000Z')).toBe('now-11M'); + }); +}); diff --git a/src/components/tabs/__snapshots__/tab.test.tsx.snap b/src/components/tabs/__snapshots__/tab.test.tsx.snap index c239dab5f7e..2424b59b0aa 100644 --- a/src/components/tabs/__snapshots__/tab.test.tsx.snap +++ b/src/components/tabs/__snapshots__/tab.test.tsx.snap @@ -1,5 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`EuiTab Props is disabled 1`] = ` + +`; + exports[`EuiTab renders anchor 1`] = ` { expect(onClickHandler).toBeCalled(); }); }); + + test('is disabled', () => { + const component = render(Click Me); + + expect(component).toMatchSnapshot(); + }); }); }); diff --git a/src/components/text/__snapshots__/text_align.test.tsx.snap b/src/components/text/__snapshots__/text_align.test.tsx.snap index 7f40c0ee1ee..8853021b7dc 100644 --- a/src/components/text/__snapshots__/text_align.test.tsx.snap +++ b/src/components/text/__snapshots__/text_align.test.tsx.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`EuiTextAlign direction prop center is rendered 1`] = ` +
+`; + +exports[`EuiTextAlign direction prop left is rendered 1`] = ` +
+`; + +exports[`EuiTextAlign direction prop right is rendered 1`] = ` +
+`; + exports[`EuiTextAlign is rendered 1`] = `
{ test('is rendered', () => { @@ -10,4 +10,14 @@ describe('EuiTextAlign', () => { expect(component).toMatchSnapshot(); }); + + describe('direction prop', () => { + ALIGNMENTS.forEach(direction => { + test(`${direction} is rendered`, () => { + const component = render(); + + expect(component).toMatchSnapshot(); + }); + }); + }); }); diff --git a/src/components/toggle/__snapshots__/toggle.test.tsx.snap b/src/components/toggle/__snapshots__/toggle.test.tsx.snap index 0b074772d8a..633f9960588 100644 --- a/src/components/toggle/__snapshots__/toggle.test.tsx.snap +++ b/src/components/toggle/__snapshots__/toggle.test.tsx.snap @@ -13,3 +13,59 @@ exports[`EuiToggle is rendered 1`] = ` />
`; + +exports[`EuiToggle props checked is rendered 1`] = ` +
+ +
+`; + +exports[`EuiToggle props isDisabled is rendered 1`] = ` +
+ +
+`; + +exports[`EuiToggle props onChange is rendered 1`] = ` +
+ +
+`; + +exports[`EuiToggle props type is rendered 1`] = ` +
+ +
+`; diff --git a/src/components/toggle/toggle.test.tsx b/src/components/toggle/toggle.test.tsx index 95b5f4ef27c..1c89f79c0a9 100644 --- a/src/components/toggle/toggle.test.tsx +++ b/src/components/toggle/toggle.test.tsx @@ -12,4 +12,45 @@ describe('EuiToggle', () => { expect(component).toMatchSnapshot(); }); + + describe('props', () => { + test('isDisabled is rendered', () => { + const component = render(); + + expect(component).toMatchSnapshot(); + }); + + test('onChange is rendered', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); + + test('type is rendered', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); + + test('checked is rendered', () => { + const component = render( + + ); + + expect(component).toMatchSnapshot(); + }); + }); }); diff --git a/src/components/tree_view/tree_view.test.tsx b/src/components/tree_view/tree_view.test.tsx index a6c72de6667..3112a114e12 100644 --- a/src/components/tree_view/tree_view.test.tsx +++ b/src/components/tree_view/tree_view.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { EuiIcon } from '../icon'; import { EuiToken } from '../token'; -import { render } from 'enzyme'; +import { render, shallow } from 'enzyme'; import { requiredProps } from '../../test/required_props'; import { EuiTreeView } from './tree_view'; @@ -11,71 +11,109 @@ jest.mock('../../services/accessibility/html_id_generator', () => ({ htmlIdGenerator: () => () => 'htmlId', })); -describe('EuiTreeView', () => { - test('is rendered', () => { - const component = render( - , + iconWhenExpanded: , + isExpanded: true, + children: [ + { + label: 'Item A', + id: 'item_a', + icon: , + }, + { + label: 'Item B', + id: 'item_b', + icon: , + iconWhenExpanded: , + children: [ { - label: 'Item One', - id: 'item_one', - icon: , - iconWhenExpanded: , - isExpanded: true, - children: [ - { - label: 'Item A', - id: 'item_a', - icon: , - }, - { - label: 'Item B', - id: 'item_b', - icon: , - iconWhenExpanded: , - children: [ - { - label: 'A Cloud', - id: 'item_cloud', - icon: , - }, - { - label: "I'm a Bug", - id: 'item_bug', - icon: , - className: 'classForBug', - }, - ], - }, - { - label: 'Item C', - id: 'item_c', - icon: , - iconWhenExpanded: , - children: [ - { - label: 'Another Cloud', - id: 'item_cloud2', - icon: , - }, - { - label: 'Another Bug', - id: 'item_bug2', - icon: , - }, - ], - }, - ], + label: 'A Cloud', + id: 'item_cloud', + icon: , }, { - label: 'Item Two', - id: 'item_two', + label: "I'm a Bug", + id: 'item_bug', + icon: , + className: 'classForBug', }, - ]} - {...requiredProps} - /> - ); + ], + }, + { + label: 'Item C', + id: 'item_c', + icon: , + iconWhenExpanded: , + children: [ + { + label: 'Another Cloud', + id: 'item_cloud2', + icon: , + }, + { + label: 'Another Bug', + id: 'item_bug2', + icon: , + }, + ], + }, + ], + }, + { + label: 'Item Two', + id: 'item_two', + }, +]; + +describe('EuiTreeView', () => { + test('is rendered', () => { + const component = render(); expect(component).toMatchSnapshot(); }); + + test('length of open items', () => { + const component = shallow( + + ); + const instance = component.instance(); + + expect(component.state('openItems')).toHaveLength(1); + + instance.handleNodeClick(items[1]); + expect(component.state('openItems')).toHaveLength(2); + }); + + test('activeItem changes', () => { + const component = shallow( + + ); + const instance = component.instance(); + + expect(component.state('activeItem')).toBe(''); + + instance.handleNodeClick(items[1]); + expect(component.state('activeItem')).toBe('item_two'); + }); + + test('open node changes', () => { + const component = shallow( + + ); + const instance = component.instance(); + + expect(instance.isNodeOpen(items[1])).toBe(false); + + instance.handleNodeClick(items[1]); + expect(instance.isNodeOpen(items[1])).toBe(true); + + expect(instance.isNodeOpen(items[0])).toBe(true); + + instance.handleNodeClick(items[0]); + expect(instance.isNodeOpen(items[0])).toBe(false); + }); });