-
Notifications
You must be signed in to change notification settings - Fork 416
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
5 changed files
with
254 additions
and
0 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
77 changes: 77 additions & 0 deletions
77
web/client/components/resources/modals/enhancers/__tests__/handleDetails-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,77 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import expect from 'expect'; | ||
import {compose, lifecycle, createSink} from 'recompose'; | ||
|
||
import handleDetails from '../handleDetails'; | ||
|
||
const createTestRun = (onMount = () => {}, testFunc = () => {}) => { | ||
let ranMount = false; | ||
const runOnMount = lifecycle({ | ||
componentDidMount() { | ||
ranMount = true; | ||
onMount(this.props); | ||
} | ||
}); | ||
const testProps = (props) => { | ||
if (ranMount) { | ||
testFunc(props); | ||
} | ||
}; | ||
return {runOnMount, testProps}; | ||
}; | ||
|
||
describe('handleDetails enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('handleDetails handlers', () => { | ||
let run = createTestRun(({onShowDetailsSheet}) => { | ||
expect(onShowDetailsSheet).toExist(); | ||
onShowDetailsSheet(); | ||
}, ({showDetailsSheet}) => { | ||
expect(showDetailsSheet).toBe(true); | ||
}); | ||
|
||
let Sink = compose( | ||
handleDetails, | ||
run.runOnMount | ||
)(createSink(run.testProps)); | ||
ReactDOM.render(<Sink/>, document.getElementById('container')); | ||
|
||
run = createTestRun(({onHideDetailsSheet}) => { | ||
expect(onHideDetailsSheet).toExist(); | ||
onHideDetailsSheet(); | ||
}, ({showDetailsSheet}) => { | ||
expect(showDetailsSheet).toBe(false); | ||
}); | ||
|
||
Sink = compose( | ||
handleDetails, | ||
run.runOnMount | ||
)(createSink(run.testProps)); | ||
ReactDOM.render(<Sink/>, document.getElementById('container')); | ||
}); | ||
it('handleDetails savedDetailsText', () => { | ||
let Sink = handleDetails(createSink(({savedDetailsText}) => expect(savedDetailsText).toBe('text'))); | ||
ReactDOM.render(<Sink linkedResources={{details: {data: 'text'}}}/>, document.getElementById('container')); | ||
}); | ||
it('handleDetails savedDetailsText when data is NODATA', () => { | ||
let Sink = handleDetails(createSink(({savedDetailsText}) => expect(savedDetailsText).toNotExist())); | ||
ReactDOM.render(<Sink linkedResources={{details: {data: 'NODATA'}}}/>, document.getElementById('container')); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
web/client/components/resources/modals/enhancers/__tests__/handleDetailsRow-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,70 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import expect from 'expect'; | ||
import {compose, lifecycle, createSink} from 'recompose'; | ||
|
||
import handleDetailsRow from '../handleDetailsRow'; | ||
|
||
const createTestRun = (onMount = () => {}, testFunc = () => {}) => { | ||
let ranMount = false; | ||
const runOnMount = lifecycle({ | ||
componentDidMount() { | ||
ranMount = true; | ||
onMount(this.props); | ||
} | ||
}); | ||
const testProps = (props) => { | ||
if (ranMount) { | ||
testFunc(props); | ||
} | ||
}; | ||
return {runOnMount, testProps}; | ||
}; | ||
|
||
describe('handleDetailsRow enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('handleDetails handlers', () => { | ||
let run = createTestRun(({onShowPreview}) => { | ||
expect(onShowPreview).toExist(); | ||
onShowPreview(); | ||
}, ({showPreview}) => { | ||
expect(showPreview).toBe(true); | ||
}); | ||
|
||
let Sink = compose( | ||
handleDetailsRow, | ||
run.runOnMount | ||
)(createSink(run.testProps)); | ||
ReactDOM.render(<Sink/>, document.getElementById('container')); | ||
|
||
run = createTestRun(({onHidePreview}) => { | ||
expect(onHidePreview).toExist(); | ||
onHidePreview(); | ||
}, ({showPreview}) => { | ||
expect(showPreview).toBe(false); | ||
}); | ||
|
||
Sink = compose( | ||
handleDetailsRow, | ||
run.runOnMount | ||
)(createSink(run.testProps)); | ||
ReactDOM.render(<Sink/>, document.getElementById('container')); | ||
}); | ||
}); | ||
|
40 changes: 40 additions & 0 deletions
40
web/client/components/resources/modals/fragments/__tests__/DetailsRow-test.jsx
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,40 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import expect from 'expect'; | ||
|
||
import DetailsRow from '../DetailsRow'; | ||
|
||
describe('DetailsRow component', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('DetailsRow with defaults', () => { | ||
ReactDOM.render(<DetailsRow/>, document.getElementById('container')); | ||
const details = document.getElementsByClassName('ms-details-sheet')[0]; | ||
expect(details).toExist(); | ||
const btnGroup = details.getElementsByTagName('button'); | ||
expect(btnGroup.length).toBe(1); | ||
expect(btnGroup[0].getElementsByClassName('glyphicon-pencil-add').length).toBe(1); | ||
}); | ||
it('DetailsRow no buttons when loading', () => { | ||
ReactDOM.render(<DetailsRow loading/>, document.getElementById('container')); | ||
const details = document.getElementsByClassName('ms-details-sheet')[0]; | ||
expect(details).toExist(); | ||
const btnGroup = details.getElementsByTagName('button'); | ||
expect(btnGroup.length).toBe(0); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
web/client/components/resources/modals/fragments/__tests__/DetailsSheet-test.jsx
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,51 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import TestUtils from 'react-dom/test-utils'; | ||
import expect from 'expect'; | ||
|
||
import DetailsSheet from '../DetailsSheet'; | ||
|
||
describe('DetailsSheet component', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('DetailsSheet with show and buttons test', () => { | ||
const handlers = { | ||
onClose: () => {}, | ||
onSave: () => {} | ||
}; | ||
|
||
const onCloseSpy = expect.spyOn(handlers, 'onClose'); | ||
const onSaveSpy = expect.spyOn(handlers, 'onSave'); | ||
|
||
ReactDOM.render(<DetailsSheet show onClose={handlers.onClose} onSave={handlers.onSave}/>, document.getElementById('container')); | ||
|
||
const detailsEditor = document.getElementById('ms-details-editor'); | ||
expect(detailsEditor).toExist(); | ||
const buttons = document.querySelectorAll('.modal-footer .btn-group button'); | ||
expect(buttons.length).toBe(2); | ||
TestUtils.Simulate.click(buttons[0]); | ||
expect(onCloseSpy).toHaveBeenCalled(); | ||
TestUtils.Simulate.click(buttons[1]); | ||
expect(onSaveSpy).toHaveBeenCalled(); | ||
}); | ||
it('DetailsSheet readOnly', () => { | ||
ReactDOM.render(<DetailsSheet show readOnly/>, document.getElementById('container')); | ||
const buttons = document.querySelectorAll('.modal-footer .btn-group button'); | ||
expect(buttons.length).toBe(0); | ||
}); | ||
}); |