Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed May 15, 2018
1 parent d37ae46 commit dcc6a94
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ describe('ChartWidget component', () => {
ReactDOM.render(<ChartWidget />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
expect(el).toExist();
});
it('view only mode', () => {
ReactDOM.render(<ChartWidget canEdit={false} />, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
});
it('Test ChartWidget onEdit callback', () => {
const actions = {
onEdit: () => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ describe('CounterWidget component', () => {
ReactDOM.render(<CounterWidget />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
expect(el).toExist();
});
it('view only mode', () => {
ReactDOM.render(<CounterWidget canEdit={false} />, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
});
it('Test CounterWidget onEdit callback', () => {
const actions = {
onEdit: () => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ describe('LegendWidget component', () => {
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(el).toExist();
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
});
it('view only mode', () => {
ReactDOM.render(<LegendWidget canEdit={false} />, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
});
it('Test LegendWidget onEdit callback', () => {
const actions = {
Expand Down
13 changes: 10 additions & 3 deletions web/client/components/widgets/widget/__tests__/MapWidget-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ describe('MapWidget component', () => {
setTimeout(done);
});
it('MapWidget rendering with defaults', () => {
ReactDOM.render(<Provider store={{subscribe: () => {}, getState: () => ({maptype: {mapType: 'openlayers'}})}} ><MapWidget /></Provider>, document.getElementById("container"));
const el = document.querySelector('div');
expect(el).toExist();
ReactDOM.render(<Provider store={{subscribe: () => {}, getState: () => ({maptype: {mapType: 'openlayers'}})}} ><MapWidget map={{layers: []}}/></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
});
it('view only mode', () => {
ReactDOM.render(<Provider store={{ subscribe: () => { }, getState: () => ({ maptype: { mapType: 'openlayers' } }) }} ><MapWidget map={{ layers: [] }} canEdit={false}/></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ describe('TableWidget component', () => {
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(el).toExist();
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
});
it('view only mode', () => {
ReactDOM.render(<TableWidget canEdit={false} />, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
});
it('Test TableWidget onEdit callback', () => {
const actions = {
Expand Down
57 changes: 57 additions & 0 deletions web/client/components/widgets/widget/__tests__/TextWidget-test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2018, 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.
*/

const React = require('react');
const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-dom/test-utils');

const expect = require('expect');
const TextWidget = require('../TextWidget');

describe('TextWidget 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('rendering with defaults', () => {
ReactDOM.render(<TextWidget />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
expect(el).toExist();
});
it('view only mode', () => {
ReactDOM.render(<TextWidget canEdit={false} />, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
});
it('onEdit callback', () => {
const actions = {
onEdit: () => {}
};
const spyonEdit = expect.spyOn(actions, 'onEdit');
ReactDOM.render(<TextWidget onEdit={actions.onEdit} />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.glyphicon-pencil');
ReactTestUtils.Simulate.click(el); // <-- trigger event callback
expect(spyonEdit).toHaveBeenCalled();
});
it('rendering text', () => {
const TEST_TEXT = '<div id="TEST_TEXT"> TEST </div>';
ReactDOM.render(<TextWidget text={TEST_TEXT} />, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('#TEST_TEXT')).toExist();
});
});

0 comments on commit dcc6a94

Please sign in to comment.