Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Add terra enzyme intl to jest config #375

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
extends: "@cerner/terra"
rules:
react/forbid-prop-types: off
globals:
enzyme: readonly
enzymeIntl: readonly
overrides:
- files:
- "packages/**/jest/**/*"
Expand Down
7 changes: 4 additions & 3 deletions jest.enzymeSetup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Make Enzyme functions available in all test files without importing
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable object-curly-newline */
import Enzyme, { mount, render, shallow } from 'enzyme';
import { mockIntl, mountWithIntl, renderWithIntl, shallowWithIntl } from 'terra-enzyme-intl';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });

global.shallow = shallow;
global.render = render;
global.mount = mount;
global.enzyme = { mount, render, shallow };
global.enzymeIntl = { mockIntl, mountWithIntl, renderWithIntl, shallowWithIntl };
663 changes: 366 additions & 297 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ MockComponent.interactiveType = false;

describe('ActionMenu', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenu label="test menu" />
));
expect(wrapper).toMatchSnapshot();
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenu
label="test menu"
isHeaderDisplayed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionMenuCheckbox from '../../../src/action-menu/ActionMenuCheckbox';

describe('ActionMenuCheckbox', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuCheckbox
actionKey="test key"
label="test label"
Expand All @@ -14,7 +14,7 @@ describe('ActionMenuCheckbox', () => {
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuCheckbox
actionKey="test key"
label="test label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionMenuDivider from '../../../src/action-menu/ActionMenuDivider';

describe('ActionMenuDivider', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuDivider />
));
expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionMenuGroup from '../../../src/action-menu/ActionMenuGroup';

describe('ActionMenuGroup', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuGroup
actionKey="test key"
label="test label"
Expand All @@ -14,7 +14,7 @@ describe('ActionMenuGroup', () => {
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuGroup
onArrow={jest.fn()}
onClose={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionMenuItem from '../../../src/action-menu/ActionMenuItem';

describe('ActionMenuItem', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuItem
actionKey="test key"
label="test label"
Expand All @@ -14,7 +14,7 @@ describe('ActionMenuItem', () => {
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuItem
actionKey="test key"
label="test label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionMenuLink from '../../../src/action-menu/ActionMenuLink';

describe('ActionMenuItem', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuLink
actionKey="test key"
label="test label"
Expand All @@ -14,7 +14,7 @@ describe('ActionMenuItem', () => {
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuLink
actionKey="test key"
label="test label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionMenuRadio from '../../../src/action-menu/ActionMenuRadio';

describe('ActionMenuRadio', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuRadio
actionKey="test key"
label="test label"
Expand All @@ -14,7 +14,7 @@ describe('ActionMenuRadio', () => {
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ActionMenuRadio
actionKey="test key"
label="test label"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import { shallowWithIntl } from 'terra-enzyme-intl';
import ActionMenuHeader from '../../../src/action-menu/_ActionMenuHeader';

describe('ActionMenuHeader', () => {
it('should render with minimal props', () => {
const wrapper = shallowWithIntl((
const wrapper = enzymeIntl.shallowWithIntl((
<ActionMenuHeader
label="test label"
/>
Expand All @@ -13,7 +12,7 @@ describe('ActionMenuHeader', () => {
});

it('should render with all props', () => {
const wrapper = shallowWithIntl((
const wrapper = enzymeIntl.shallowWithIntl((
<ActionMenuHeader
label="test label"
onClose={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ApplicationBase from '../../../src/application-base/ApplicationBase';

describe('ApplicationBase', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationBase locale="en">
<div>content</div>
</ApplicationBase>
Expand All @@ -12,7 +12,7 @@ describe('ApplicationBase', () => {
});

it('should render with all props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationBase
locale="en"
customTranslatedMessages={{ custom: 'messages' }}
Expand All @@ -28,15 +28,15 @@ describe('ApplicationBase', () => {
});

it('should render with the preferred browser local', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationBase>
<div>content</div>
</ApplicationBase>
));
expect(wrapper).toMatchSnapshot();
});
it('should render without scroll', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationBase noScroll>
<div>content</div>
</ApplicationBase>
Expand All @@ -45,7 +45,7 @@ describe('ApplicationBase', () => {
});

it('should render with theme and density', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationBase themeName="test-theme" themeDensity="compact">
<div>content</div>
</ApplicationBase>
Expand All @@ -60,7 +60,7 @@ describe('ApplicationBase', () => {
});

it('should render with density', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationBase themeDensity="compact">
<div>content</div>
</ApplicationBase>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React from 'react';
import { shallowWithIntl, mountWithIntl } from 'terra-enzyme-intl';
import ApplicationErrorBoundary from '../../../src/application-error-boundary/ApplicationErrorBoundary';
import Logger from '../../../src/utils/logger';

describe('ApplicationErrorBoundary', () => {
describe('Snapshots', () => {
it('should render with minimal props', () => {
const wrapper = shallowWithIntl((
const wrapper = enzymeIntl.shallowWithIntl((
<ApplicationErrorBoundary />
));

expect(wrapper).toMatchSnapshot();
});

it('should render with children', () => {
const wrapper = shallowWithIntl((
const wrapper = enzymeIntl.shallowWithIntl((
<ApplicationErrorBoundary>
<div>Test child</div>
</ApplicationErrorBoundary>
Expand All @@ -27,7 +26,7 @@ describe('ApplicationErrorBoundary', () => {
const spy = jest.spyOn(Logger, 'error').mockImplementation(() => {});
const ErrorComponent = () => <div />;

const wrapper = mountWithIntl((
const wrapper = enzymeIntl.mountWithIntl((
<ApplicationErrorBoundary>
<ErrorComponent />
</ApplicationErrorBoundary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';
import { mountWithIntl } from 'terra-enzyme-intl';
import ApplicationIntlContext from '../../../src/application-intl/ApplicationIntlContext';
import ApplicationIntlProvider from '../../../src/application-intl/ApplicationIntlProvider';

describe('ApplicationIntlProvider', () => {
describe('Snapshots', () => {
it('should render an ApplicationIntlContext.Provider', () => {
const wrapper = mountWithIntl((
const wrapper = enzymeIntl.mountWithIntl((
<ApplicationIntlProvider>
<ApplicationIntlContext.Consumer>
{(intl) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ApplicationLoadingOverlay', () => {
});

it('should render loading overlay as closed', () => {
const wrapper = mount(
const wrapper = enzyme.mount(
<ApplicationLoadingOverlay />,
);

Expand All @@ -39,7 +39,7 @@ describe('ApplicationLoadingOverlay', () => {
});

it('should render loading overlay as open', () => {
const wrapper = mount(
const wrapper = enzyme.mount(
<ApplicationLoadingOverlay isOpen />,
);

Expand All @@ -56,7 +56,7 @@ describe('ApplicationLoadingOverlay', () => {
});

it('should transition from open to closed', () => {
const wrapper = mount(
const wrapper = enzyme.mount(
<ApplicationLoadingOverlay isOpen />,
);

Expand All @@ -74,7 +74,7 @@ describe('ApplicationLoadingOverlay', () => {
});

it('should redisplay loading overlay with new props', () => {
const wrapper = mount(
const wrapper = enzyme.mount(
<ApplicationLoadingOverlay isOpen />,
);

Expand All @@ -93,7 +93,7 @@ describe('ApplicationLoadingOverlay', () => {
});

it('should honor backgroundStyle prop', () => {
const wrapper = mount(
const wrapper = enzyme.mount(
<ApplicationLoadingOverlay isOpen backgroundStyle="clear" />,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import ApplicationLoadingOverlayProvider from '../../../src/application-loading-
describe('ApplicationLoadingOverlayProvider', () => {
describe('Snapshots', () => {
it('should render with minimal props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider />
));

expect(wrapper).toMatchSnapshot();
});

it('should render with custom props', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider className="testClassName" />
));

Expand All @@ -21,7 +21,7 @@ describe('ApplicationLoadingOverlayProvider', () => {

it('should render with optional props', () => {
const scrollRefCallback = jest.fn();
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider
scrollRefCallback={scrollRefCallback}
>
Expand All @@ -40,7 +40,7 @@ describe('ApplicationLoadingOverlayProvider', () => {
2: { backgroundStyle: 'clear' },
}, mockSetState]);

const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider>
<div>Test child</div>
</ApplicationLoadingOverlayProvider>
Expand All @@ -59,7 +59,7 @@ describe('ApplicationLoadingOverlayProvider', () => {
2: { backgroundStyle: 'light' },
}, mockSetState]);

const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider>
<div>Test child</div>
</ApplicationLoadingOverlayProvider>
Expand All @@ -78,7 +78,7 @@ describe('ApplicationLoadingOverlayProvider', () => {
2: { backgroundStyle: 'clear' },
}, mockSetState]);

const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider>
<div>Test child</div>
</ApplicationLoadingOverlayProvider>
Expand All @@ -90,7 +90,7 @@ describe('ApplicationLoadingOverlayProvider', () => {
});

it('should render without scroll', () => {
const wrapper = shallow((
const wrapper = enzyme.shallow((
<ApplicationLoadingOverlayProvider noScroll />
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ApplicationNavigation from '../../../src/application-navigation/Applicati

describe('ApplicationNavigation', () => {
it('should render default element', () => {
const shallowComponent = shallow(
const shallowComponent = enzyme.shallow(
<ApplicationNavigation
id="test-application-id"
/>,
Expand All @@ -14,7 +14,7 @@ describe('ApplicationNavigation', () => {
});

it('should render with all props', () => {
const shallowComponent = shallow(
const shallowComponent = enzyme.shallow(
<ApplicationNavigation
id="test-application-id"
activeBreakpoint="large"
Expand Down
Loading
Loading