Skip to content

Commit

Permalink
added more test
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed Sep 27, 2017
1 parent 5548913 commit ba22460
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const React = require('react');
const PropTypes = require('prop-types');
const AttributeEditor = require('./AttributeEditor');
const {AutocompleteCombobox} = require('./AutocompleteCombobox');
const {AutocompleteCombobox} = require('../../../misc/AutocompleteCombobox');
const {createPagedUniqueAutompleteStream} = require('../../../../observables/autocomplete');

class AutocompleteEditor extends AttributeEditor {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const React = require('react');
const ReactDOM = require('react-dom');
const AutocompleteEditor = require('../AutocompleteEditor');
const {createPagedUniqueAutompleteStream} = require('../../../../../observables/autocomplete');

var expect = require('expect');

let testColumn = {
key: 'columnKey'
};
const value = "1.1";
describe('FeatureGrid AutocompleteEditor 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('AutocompleteEditor Editor no stream provided', () => {
const cmp = ReactDOM.render(<AutocompleteEditor
value={value}
rowIdx={1}
column={testColumn}/>, document.getElementById("container"));
expect(cmp.getValue().columnKey).toBe(value);
expect(cmp.validate(value)).toBe(true);
});
it('AutocompleteEditor Editor no stream provided', () => {
const cmp = ReactDOM.render(<AutocompleteEditor
value={value}
rowIdx={1}
autocompleteStreamFactory={createPagedUniqueAutompleteStream}
column={testColumn}/>, document.getElementById("container"));
expect(cmp).toExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const React = require('react');
const {isArray} = require('lodash');
const PagedCombobox = require('../../../misc/PagedCombobox');
const PagedCombobox = require('./PagedCombobox');
const {setObservableConfig, mapPropsStreamWithConfig, compose, withStateHandlers} = require('recompose');
const rxjsConfig = require('recompose/rxjsObservableConfig').default;
setObservableConfig(rxjsConfig);
Expand Down
29 changes: 29 additions & 0 deletions web/client/components/misc/__tests__/AutocompleteCombobox-test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2017, 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 expect = require('expect');
const React = require('react');
const ReactDOM = require('react-dom');
const {AutocompleteCombobox} = require('../AutocompleteCombobox');
const {createPagedUniqueAutompleteStream} = require('../../../observables/autocomplete');

describe("This test for AutocompleteCombobox 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('creates AutocompleteCombobox with defaults', () => {
const comp = ReactDOM.render(<AutocompleteCombobox autocompleteStreamFactory={createPagedUniqueAutompleteStream}/>, document.getElementById("container"));
expect(comp).toExist();
});

});
139 changes: 139 additions & 0 deletions web/client/components/misc/__tests__/PagedCombobox-test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2017, 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 expect = require('expect');
const React = require('react');
const ReactDOM = require('react-dom');
const PagedCombobox = require('../PagedCombobox');
const TestUtils = require('react-dom/test-utils');
const {Tooltip} = require('react-bootstrap');

describe("This test for PagedCombobox 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('creates PagedCombobox with defaults', () => {
const comp = ReactDOM.render(<PagedCombobox/>, document.getElementById("container"));
expect(comp).toExist();

const input = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-input")[0]);
// triggering default actions
TestUtils.Simulate.change(input, {
target: {
value: "other"
}
});
TestUtils.Simulate.focus(input);

});
it('creates PagedCombobox with defaults and with basic tooltip', () => {
const tooltip = {
message: "wow",
enabled: true,
id: "1",
overlayTriggerKey: "key",
placement: "top"
};
const comp = ReactDOM.render(<PagedCombobox tooltip={tooltip}/>, document.getElementById("container"));
expect(comp).toExist();
});
it('creates PagedCombobox with defaults and with customized tooltip', () => {
const tooltip = <Tooltip id={"wonderfulId"}>"a message for the tooltip"</Tooltip>;

const comp = ReactDOM.render(<PagedCombobox tooltip={{customizedTooltip: tooltip}}/>, document.getElementById("container"));
expect(comp).toExist();
});
it('tests PagedCombobox onToggle and opening of option lists', () => {
const actions = {
onToggle: () => {}
};
const spy = expect.spyOn(actions, "onToggle");
const data = [{
label: "label", value: "value"
}];
const comp = ReactDOM.render(<PagedCombobox onToggle={actions.onToggle} data={data}/>, document.getElementById("container"));
expect(comp).toExist();
const domNode = ReactDOM.findDOMNode(comp);
expect(domNode).toExist();
const tool = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-i rw-i-caret-down")[0]);
tool.click();
expect(spy.calls.length).toBe(1);
// this tests if the option list is opened
const firstOption = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-list-option")[0]);
expect(firstOption).toExist();
const valueOption = firstOption.getElementsByTagName("span")[0];
expect(valueOption).toExist();
expect(valueOption.innerText).toBe("label");
});
it('tests PagedCombobox onChange', () => {
const actions = {
onChange: () => {}
};
const spy = expect.spyOn(actions, "onChange");
const data = [{
label: "label", value: "value"
}];
const comp = ReactDOM.render(<PagedCombobox onChange={actions.onChange} data={data}/>, document.getElementById("container"));
expect(comp).toExist();
const input = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-input")[0]);
TestUtils.Simulate.change(input, {
target: {
value: "other"
}
});
expect(spy.calls.length).toBe(1);
});
it('tests PagedCombobox onFocus', (done) => {
const actions = {
onFocus: () => {}
};
const spy = expect.spyOn(actions, "onFocus");
const data = [{
label: "label", value: "value"
}];
const comp = ReactDOM.render(<PagedCombobox onFocus={actions.onFocus} data={data}/>, document.getElementById("container"));
expect(comp).toExist();
const input = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-input")[0]);
TestUtils.Simulate.focus(input);
setTimeout(() => {
expect(spy.calls.length).toEqual(1);
done();
}, 50);
});

it('tests PagedCombobox onSelect and opening of option lists', (done) => {
const actions = {
onSelect: () => {}
};
const spy = expect.spyOn(actions, "onSelect");
const data = [{
label: "label", value: "value"
}];
const comp = ReactDOM.render(<PagedCombobox onSelect={actions.onSelect} data={data}/>, document.getElementById("container"));
expect(comp).toExist();
const domNode = ReactDOM.findDOMNode(comp);
expect(domNode).toExist();
const tool = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-i rw-i-caret-down")[0]);
tool.click();
// this tests if the option list is opened
const firstOption = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "rw-list-option")[0]);
expect(firstOption).toExist();
const valueOption = firstOption.getElementsByTagName("span")[0];
expect(valueOption).toExist();
TestUtils.Simulate.click(firstOption);
setTimeout(() => {
expect(spy.calls.length).toEqual(1);
done();
}, 50);
});
});

0 comments on commit ba22460

Please sign in to comment.