-
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
4 changed files
with
133 additions
and
6 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
93 changes: 93 additions & 0 deletions
93
web/client/components/resources/modals/fragments/__tests__/Details-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,93 @@ | ||
/* | ||
* 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 Details from '../Details'; | ||
import { htmlToDraftJSEditorState } from '../../../../../utils/EditorUtils'; | ||
|
||
describe('Details 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('Details with defaults', () => { | ||
ReactDOM.render(<Details/>, document.getElementById('container')); | ||
const detailsSheet = document.getElementsByClassName('ms-details-sheet')[0]; | ||
expect(detailsSheet).toExist(); | ||
const buttons = detailsSheet.getElementsByTagName('button'); | ||
expect(buttons).toExist(); | ||
expect(buttons.length).toBe(1); | ||
}); | ||
it('Details with savedDetailsText', () => { | ||
ReactDOM.render(<Details savedDetailsText="text"/>, document.getElementById('container')); | ||
const detailsSheet = document.getElementsByClassName('ms-details-sheet')[0]; | ||
expect(detailsSheet).toExist(); | ||
const buttons = detailsSheet.getElementsByTagName('button'); | ||
expect(buttons).toExist(); | ||
expect(buttons.length).toBe(5); | ||
}); | ||
it('Details undo sets linkedResource to detailsBackup', () => { | ||
const handlers = { | ||
onUpdateLinkedResource: () => {}, | ||
setDetailsBackup: () => {} | ||
}; | ||
|
||
const updLinkedResourceSpy = expect.spyOn(handlers, 'onUpdateLinkedResource'); | ||
const setDetailsBackupSpy = expect.spyOn(handlers, 'setDetailsBackup'); | ||
|
||
ReactDOM.render(<Details detailsBackup="text" onUpdateLinkedResource={handlers.onUpdateLinkedResource} setDetailsBackup={handlers.setDetailsBackup}/>, document.getElementById('container')); | ||
const detailsSheet = document.getElementsByClassName('ms-details-sheet')[0]; | ||
expect(detailsSheet).toExist(); | ||
const buttons = detailsSheet.getElementsByTagName('button'); | ||
expect(buttons).toExist(); | ||
expect(buttons.length).toBe(2); | ||
const undoButton = [buttons[0], buttons[1]].filter(but => but.childNodes[0]?.className?.indexOf('glyphicon-undo') > -1)[0]; | ||
expect(undoButton).toExist(); | ||
|
||
TestUtils.Simulate.click(undoButton); | ||
|
||
expect(updLinkedResourceSpy).toHaveBeenCalled(); | ||
expect(setDetailsBackupSpy).toHaveBeenCalled(); | ||
expect(updLinkedResourceSpy).toHaveBeenCalledWith('details', 'text', 'DETAILS'); | ||
}); | ||
it('hideDetailsSheet is called on close and save of the Details sheet', () => { | ||
const handlers = { | ||
onHideDetailsSheet: () => {} | ||
}; | ||
const onHideDetailsSheetSpy = expect.spyOn(handlers, 'onHideDetailsSheet'); | ||
|
||
ReactDOM.render(<Details showDetailsSheet editorState={htmlToDraftJSEditorState('')} onHideDetailsSheet={handlers.onHideDetailsSheet}/>, document.getElementById('container')); | ||
const detailsSheet = document.getElementsByClassName('ms-details-sheet')[0]; | ||
expect(detailsSheet).toExist(); | ||
const sheetModal = document.getElementsByClassName('modal-fixed')[0]; | ||
expect(sheetModal).toExist(); | ||
const sheetModalFooter = sheetModal.getElementsByClassName('modal-footer')[0]; | ||
expect(sheetModalFooter).toExist(); | ||
const buttons = sheetModalFooter.getElementsByTagName('button'); | ||
expect(buttons).toExist(); | ||
expect(buttons.length).toBe(2); | ||
|
||
TestUtils.Simulate.click(buttons[0]); | ||
|
||
expect(onHideDetailsSheetSpy).toHaveBeenCalled(); | ||
expect(onHideDetailsSheetSpy.calls.length).toBe(1); | ||
|
||
TestUtils.Simulate.click(buttons[1]); | ||
|
||
expect(onHideDetailsSheetSpy.calls.length).toBe(2); | ||
}); | ||
}); |