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 7 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
15 changes: 15 additions & 0 deletions src/components/copy/__snapshots__/copy.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiCopy is rendered 1`] = `
<EuiToolTip
delay="regular"
onMouseOut={[Function]}
position="top"
>
<button
onClick={[Function]}
>
Click to copy input text
</button>
</EuiToolTip>
`;
23 changes: 23 additions & 0 deletions src/components/copy/copy.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { shallow } from 'enzyme';
import { EuiCopy } from './copy';

describe('EuiCopy', () => {
test('is rendered', () => {
const component = shallow(
<EuiCopy textToCopy="some text">
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
{copy => <button onClick={copy}>Click to copy input text</button>}
</EuiCopy>
);
expect(component).toMatchSnapshot();
});

test('beforeMessage', () => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
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');
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
});
});
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');
});
});
8 changes: 8 additions & 0 deletions src/components/tabs/tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ describe('EuiTab', () => {
expect(onClickHandler).toBeCalled();
});
});

describe('href', () => {
test('has href assigned to it', () => {
const component = render(<EuiTab href="/test">Click Me</EuiTab>);

expect(component[0].attribs.href).toBe('/test');
});
});
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
});
});
24 changes: 24 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,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiTextAlign in center direction 1`] = `
<div
aria-label="aria-label"
class="euiTextAlign euiTextAlign--center testClass1 testClass2"
data-test-subj="test subject string"
/>
`;

exports[`EuiTextAlign in left direction 1`] = `
<div
aria-label="aria-label"
class="euiTextAlign euiTextAlign--left testClass1 testClass2"
data-test-subj="test subject string"
/>
`;

exports[`EuiTextAlign in right direction 1`] = `
<div
aria-label="aria-label"
class="euiTextAlign euiTextAlign--right testClass1 testClass2"
data-test-subj="test subject string"
/>
`;

exports[`EuiTextAlign is rendered 1`] = `
<div
aria-label="aria-label"
Expand Down
15 changes: 14 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,25 @@ import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test';

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

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

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

['left', 'right', 'center'].forEach(direction => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
test(`in ${direction} direction`, () => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const component = render(
<EuiTextAlign
{...requiredProps}
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
textAlign={direction as TextAlignment}
/>
);

expect(component).toMatchSnapshot();
});
});
});
44 changes: 44 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,47 @@ exports[`EuiToggle is rendered 1`] = `
/>
</div>
`;

exports[`EuiToggle props is checked 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 is disabled 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"
disabled=""
type="checkbox"
/>
</div>
`;

exports[`EuiToggle props is rendered with onChange provided 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>
`;
35 changes: 35 additions & 0 deletions src/components/toggle/toggle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,39 @@ describe('EuiToggle', () => {

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

describe('props', () => {
test('is disabled', () => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const component = render(
<EuiToggle label="Is toggle on?" isDisabled {...requiredProps} />
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
);

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

test('is rendered with onChange provided', () => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const component = render(
<EuiToggle
label="Is toggle on?"
onChange={jest.fn()}
{...requiredProps}
/>
);

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

test('is checked', () => {
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
const component = render(
<EuiToggle
label="Is toggle on?"
checked
onChange={jest.fn()}
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
{...requiredProps}
/>
);

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