-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enzyme is not being supported long term. The React 17 adapter is unofficial and there may not be an adapter for future versions of React. [category:Test]
- Loading branch information
1 parent
5f58fc1
commit b72dd97
Showing
27 changed files
with
510 additions
and
1,172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,26 @@ | ||
import * as React from 'react'; | ||
import DeprecatedGlobalHeader from '../lib/GlobalHeader'; | ||
import {shallow} from 'enzyme'; | ||
import DeprecatedHeader from '../lib/Header'; | ||
import {SearchForm} from '@workday/canvas-kit-labs-react/search-form'; | ||
import {DeprecatedDubLogoTitle} from '../lib/parts'; | ||
import {DeprecatedHeaderTheme, DeprecatedHeaderVariant} from '../lib/shared/types'; | ||
|
||
declare global { | ||
interface Window { | ||
resizeBy: (x: number, y: number) => void; | ||
} | ||
} | ||
const map: {[key: string]: any} = {}; | ||
window.addEventListener = jest.fn((event, callback) => { | ||
map[event] = callback; | ||
}); | ||
window.removeEventListener = jest.fn((event, callback) => { | ||
if (map[event] && map[event] === callback) { | ||
delete map[event]; | ||
} | ||
}); | ||
window.dispatchEvent = (event: Event) => { | ||
if (map[event.type]) { | ||
map[event.type](); | ||
} | ||
|
||
// TODO: not totally accurate | ||
return false; | ||
}; | ||
|
||
window.resizeBy = (x: number, y: number) => { | ||
// @ts-ignore | ||
window.innerWidth = x; | ||
// @ts-ignore | ||
window.innerHeight = y; | ||
window.dispatchEvent(new Event('resize')); | ||
}; | ||
|
||
// @ts-ignore | ||
window.requestAnimationFrame = cbFn => cbFn(); | ||
import {render} from '@testing-library/react'; | ||
|
||
describe('DeprecatedGlobalHeader', () => { | ||
const cb = jest.fn(); | ||
beforeEach(() => { | ||
window.resizeBy(1280, 1024); | ||
}); | ||
|
||
afterEach(() => { | ||
cb.mockReset(); | ||
}); | ||
|
||
describe('How DeprecatedGlobalHeader children render', () => { | ||
beforeEach(() => { | ||
window.resizeBy(1280, 1024); | ||
}); | ||
|
||
test('Renders non-React child elements as is', () => { | ||
const text = 'not a react element'; | ||
const wrapper = shallow<DeprecatedGlobalHeader>( | ||
<DeprecatedGlobalHeader>{text}</DeprecatedGlobalHeader> | ||
); | ||
it('should render non-element children as is', () => { | ||
const text = 'not an element'; | ||
const {container} = render(<DeprecatedGlobalHeader>{text}</DeprecatedGlobalHeader>); | ||
|
||
expect(wrapper.contains(text)); | ||
expect(container).toContainHTML(text); | ||
}); | ||
|
||
test('Renders a div element as is', () => { | ||
const wrapper = shallow<DeprecatedGlobalHeader>( | ||
<DeprecatedGlobalHeader> | ||
<div>Test</div> | ||
</DeprecatedGlobalHeader> | ||
); | ||
expect( | ||
wrapper | ||
.find('div') | ||
.first() | ||
.contains('Test') | ||
).toBeTruthy(); | ||
}); | ||
|
||
test('Passes props to Header correctly', () => { | ||
const propsHeader1 = { | ||
brand: <div>Brand</div>, | ||
menuToggle: <div>MenuToggle</div>, | ||
onMenuClick: jest.fn(), | ||
leftSlot: <SearchForm onSubmit={jest.fn()} />, | ||
isCollapsed: true, | ||
}; | ||
const propsHeader2 = { | ||
menuToggle: 'abcde', | ||
isCollapsed: false, | ||
themeColor: DeprecatedHeaderTheme.White, | ||
}; | ||
const defaultProps = { | ||
brand: <DeprecatedDubLogoTitle />, | ||
variant: DeprecatedHeaderVariant.Global, | ||
children: undefined, | ||
}; | ||
|
||
const childPropsHeader1 = shallow(<DeprecatedGlobalHeader {...propsHeader1} />) | ||
.find(DeprecatedHeader) | ||
.props(); | ||
const childPropsHeader2 = shallow(<DeprecatedGlobalHeader {...propsHeader2} />) | ||
.find(DeprecatedHeader) | ||
.props(); | ||
it('should render a div element as is', () => { | ||
const html = <div>Test</div>; | ||
const {container} = render(<DeprecatedGlobalHeader>{html}</DeprecatedGlobalHeader>); | ||
|
||
expect(childPropsHeader1).toEqual({...defaultProps, ...propsHeader1}); | ||
expect(childPropsHeader2).toEqual({...defaultProps, ...propsHeader2}); | ||
expect(container).toContainHTML('<div>Test</div>'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.