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

added various unit tests #3071

Merged
merged 21 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
18 changes: 18 additions & 0 deletions src/components/copy/__snapshots__/copy.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiCopy is rendered 1`] = `
<EuiToolTip
aria-label="aria-label"
className="testClass1 testClass2"
data-test-subj="test subject string"
delay="regular"
onMouseOut={[Function]}
position="top"
>
<button
onClick={[Function]}
>
Click to copy input text
</button>
</EuiToolTip>
`;
36 changes: 36 additions & 0 deletions src/components/copy/copy.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<EuiCopy textToCopy="some text" {...requiredProps}>
{copy => <button onClick={copy}>Click to copy input text</button>}
</EuiCopy>
);
expect(component).toMatchSnapshot();
});

describe('props', () => {
test('beforeMessage', () => {
const component = shallow(
<EuiCopy textToCopy="some text" beforeMessage="copy this">
{copy => <button onClick={copy}>Click to copy input text</button>}
</EuiCopy>
);
expect(component.state('tooltipText')).toBe('copy this');
});

test('afterMessage', () => {
const component = shallow(
<EuiCopy textToCopy="some text" afterMessage="successfuly copied">
{copy => <button onClick={copy}>Click to copy input text</button>}
</EuiCopy>
);
const instance = component.instance() as EuiCopy;
expect(instance.props.afterMessage).toBe('successfuly copied');
});
});
});
30 changes: 30 additions & 0 deletions src/components/date_picker/super_date_picker/date_modes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { getDateMode, toAbsoluteString, toRelativeString } from './date_modes';

jest.mock('@elastic/datemath', () => ({
parse: () => ({ toISOString: () => 'gsoc' }),
}));

jest.mock('./relative_utils', () => ({
parseRelativeParts: () => 'in eui',
toRelativeStringFromParts: () => 'now',
}));
thompsongl marked this conversation as resolved.
Show resolved Hide resolved

describe('dateMode', () => {
test('date mode', () => {
expect(getDateMode('now')).toBe('now');
expect(getDateMode('acknowledge')).toBe('relative');
expect(getDateMode('eui')).toBe('absolute');
});

test('absolute string', () => {
expect(toAbsoluteString('now&1d', true)).toBe('gsoc');
expect(toAbsoluteString('now/0.5y', false)).toBe('gsoc');
expect(toAbsoluteString('now-1w/w')).toBe('gsoc');
});

test('relative string', () => {
expect(toRelativeString('now&1d')).toBe('now');
expect(toRelativeString('now/0.5y')).toBe('now');
expect(toRelativeString('now-1w/w')).toBe('now');
});
});
16 changes: 16 additions & 0 deletions src/components/tabs/__snapshots__/tab.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiTab Props is disabled 1`] = `
<button
aria-selected="false"
class="euiTab euiTab-isDisabled"
disabled=""
role="tab"
type="button"
>
<span
class="euiTab__content"
>
Click Me
</span>
</button>
`;

exports[`EuiTab renders anchor 1`] = `
<a
aria-label="aria-label"
Expand Down
6 changes: 6 additions & 0 deletions src/components/tabs/tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ describe('EuiTab', () => {
expect(onClickHandler).toBeCalled();
});
});

test('is disabled', () => {
const component = render(<EuiTab disabled>Click Me</EuiTab>);

expect(component).toMatchSnapshot();
});
});
});
18 changes: 18 additions & 0 deletions src/components/text/__snapshots__/text_align.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiTextAlign direction prop center is rendered 1`] = `
<div
class="euiTextAlign euiTextAlign--center"
/>
`;

exports[`EuiTextAlign direction prop left is rendered 1`] = `
<div
class="euiTextAlign euiTextAlign--left"
/>
`;

exports[`EuiTextAlign direction prop right is rendered 1`] = `
<div
class="euiTextAlign euiTextAlign--right"
/>
`;

exports[`EuiTextAlign is rendered 1`] = `
<div
aria-label="aria-label"
Expand Down
14 changes: 13 additions & 1 deletion src/components/text/text_align.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test';

import { EuiTextAlign } from './text_align';
import { EuiTextAlign, TextAlignment, ALIGNMENTS } from './text_align';

describe('EuiTextAlign', () => {
test('is rendered', () => {
const component = render(<EuiTextAlign {...requiredProps} />);

expect(component).toMatchSnapshot();
});

describe('direction prop', () => {
ALIGNMENTS.forEach(direction => {
test(`${direction} is rendered`, () => {
const component = render(
<EuiTextAlign textAlign={direction as TextAlignment} />
);

expect(component).toMatchSnapshot();
});
});
});
});
56 changes: 56 additions & 0 deletions src/components/toggle/__snapshots__/toggle.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,59 @@ exports[`EuiToggle is rendered 1`] = `
/>
</div>
`;

exports[`EuiToggle props checked is rendered 1`] = `
<div
aria-label="aria-label"
class="euiToggle euiToggle--checked testClass1 testClass2"
>
<input
aria-label="Is toggle on?"
checked=""
class="euiToggle__input"
data-test-subj="test subject string"
type="checkbox"
/>
</div>
`;

exports[`EuiToggle props isDisabled is rendered 1`] = `
<div
class="euiToggle"
>
<input
aria-label="Is toggle on?"
class="euiToggle__input"
disabled=""
type="checkbox"
/>
</div>
`;

exports[`EuiToggle props onChange is rendered 1`] = `
<div
aria-label="aria-label"
class="euiToggle testClass1 testClass2"
>
<input
aria-label="Is toggle on?"
class="euiToggle__input"
data-test-subj="test subject string"
type="checkbox"
/>
</div>
`;

exports[`EuiToggle props type is rendered 1`] = `
<div
aria-label="aria-label"
class="euiToggle testClass1 testClass2"
>
<input
aria-label="Is toggle on?"
class="euiToggle__input"
data-test-subj="test subject string"
type="radio"
/>
</div>
`;
41 changes: 41 additions & 0 deletions src/components/toggle/toggle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,45 @@ describe('EuiToggle', () => {

expect(component).toMatchSnapshot();
});

describe('props', () => {
test('isDisabled is rendered', () => {
const component = render(<EuiToggle label="Is toggle on?" isDisabled />);

expect(component).toMatchSnapshot();
});

test('onChange is rendered', () => {
const component = render(
<EuiToggle
label="Is toggle on?"
onChange={jest.fn()}
{...requiredProps}
/>
);

expect(component).toMatchSnapshot();
});

test('type is rendered', () => {
const component = render(
<EuiToggle label="Is toggle on?" type="single" {...requiredProps} />
);

expect(component).toMatchSnapshot();
});

test('checked is rendered', () => {
const component = render(
<EuiToggle
label="Is toggle on?"
checked
{...requiredProps}
onChange={jest.fn()}
/>
);

expect(component).toMatchSnapshot();
});
});
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
});
Loading