-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
131 additions
and
4 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
48 changes: 48 additions & 0 deletions
48
src/Sulu/Bundle/AdminBundle/Resources/js/components/Modal/tests/ClickModal.test.js
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
import ClickModal from '../ClickModal'; | ||
import React from 'react'; | ||
import {mount} from 'enzyme'; | ||
import pretty from 'pretty'; | ||
|
||
afterEach(() => document.body.innerHTML = ''); | ||
|
||
test('The modal should initially not be rendered', () => { | ||
const body = document.body; | ||
const view = mount( | ||
<ClickModal clickElement={<button>Open modal</button>}> | ||
<p>Modal content</p> | ||
</ClickModal> | ||
).render(); | ||
expect(view).toMatchSnapshot(); | ||
expect(body.innerHTML).toBe(''); | ||
}); | ||
|
||
test('The modal should be rendered when the button got clicked', () => { | ||
const body = document.body; | ||
const view = mount( | ||
<ClickModal clickElement={<button>Open modal</button>}> | ||
<p>Modal content</p> | ||
</ClickModal> | ||
); | ||
view.render(); | ||
|
||
expect(body.innerHTML).toBe(''); | ||
view.find('button').simulate('click'); | ||
expect(pretty(body.innerHTML)).toMatchSnapshot(); | ||
}); | ||
|
||
test('The modal should close again when backdrop got clicked', () => { | ||
const body = document.body; | ||
const view = mount( | ||
<ClickModal clickElement={<button>Open modal</button>}> | ||
<p>Modal content</p> | ||
</ClickModal> | ||
); | ||
view.render(); | ||
|
||
expect(body.innerHTML).toBe(''); | ||
view.find('button').simulate('click'); | ||
expect(pretty(body.innerHTML)).toMatchSnapshot(); | ||
body.getElementsByClassName('backdrop')[0].click(); | ||
expect(body.innerHTML).toBe(''); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/Sulu/Bundle/AdminBundle/Resources/js/components/Modal/tests/Modal.test.js
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
import {mount, shallow} from 'enzyme'; | ||
import Modal from '../Modal'; | ||
import React from 'react'; | ||
import pretty from 'pretty'; | ||
|
||
afterEach(() => document.body.innerHTML = ''); | ||
|
||
test('The component should render in body when open', () => { | ||
const body = document.body; | ||
const view = mount(<Modal isOpen={true}><p>Modal content</p></Modal>).render(); | ||
expect(view.html()).toBe(null); | ||
expect(pretty(body.innerHTML)).toMatchSnapshot(); | ||
}); | ||
|
||
test('The component should not render in body when closed', () => { | ||
const body = document.body; | ||
const view = mount(<Modal isOpen={false}><p>Modal content</p></Modal>).render(); | ||
expect(view.html()).toBe(null); | ||
expect(body.innerHTML).toBe(''); | ||
}); | ||
|
||
test('The component should request to be closed on click on backdrop', () => { | ||
const requestCloseSpy = jest.fn(); | ||
const view = shallow(<Modal isOpen={false} onRequestClose={requestCloseSpy}><p>Modal content</p></Modal>); | ||
const backdrop = view.find('.backdrop'); | ||
expect(backdrop.length).toBe(1); | ||
|
||
expect(requestCloseSpy).toHaveBeenCalledTimes(0); | ||
backdrop.simulate('click'); | ||
expect(requestCloseSpy).toHaveBeenCalledTimes(1); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...dle/AdminBundle/Resources/js/components/Modal/tests/__snapshots__/ClickModal.test.js.snap
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`The modal should be rendered when the button got clicked 1`] = ` | ||
"<div> | ||
<div data-reactroot=\\"\\" class=\\"container\\"> | ||
<div class=\\"modal\\"> | ||
<p>Modal content</p> | ||
</div> | ||
<div class=\\"backdrop\\"></div> | ||
</div> | ||
</div>" | ||
`; | ||
exports[`The modal should close again when backdrop got clicked 1`] = ` | ||
"<div> | ||
<div data-reactroot=\\"\\" class=\\"container\\"> | ||
<div class=\\"modal\\"> | ||
<p>Modal content</p> | ||
</div> | ||
<div class=\\"backdrop\\"></div> | ||
</div> | ||
</div>" | ||
`; | ||
exports[`The modal should initially not be rendered 1`] = ` | ||
<div> | ||
<button> | ||
Open modal | ||
</button> | ||
</div> | ||
`; |
12 changes: 12 additions & 0 deletions
12
...u/Bundle/AdminBundle/Resources/js/components/Modal/tests/__snapshots__/Modal.test.js.snap
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`The component should render in body when open 1`] = ` | ||
"<div> | ||
<div data-reactroot=\\"\\" class=\\"container\\"> | ||
<div class=\\"modal\\"> | ||
<p>Modal content</p> | ||
</div> | ||
<div class=\\"backdrop\\"></div> | ||
</div> | ||
</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