Skip to content

Commit

Permalink
Added additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed May 11, 2017
1 parent 1788c9c commit e9076cd
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 3 deletions.
109 changes: 108 additions & 1 deletion web/client/components/data/query/__tests__/FilterField-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ describe('FilterField', () => {
{id: "attribute10", name: "attribute10"}
],
valueId: "id",
valueLabel: "name"
valueLabel: "name",
dependson: {
field: "Attribute1"
}
}
];

Expand Down Expand Up @@ -110,6 +113,9 @@ describe('FilterField', () => {

const valueSelect = filterFieldDOMNode.actual.getElementsByClassName('rw-input')[2];
expect(valueSelect.childNodes[0].nodeValue).toBe("attribute1");

filterfield.updateFieldElement(200, "value", "value", "string");
filterfield.updateExceptionFieldElement(200, "error");
});

it('creates the FilterField component with fieldOptions', () => {
Expand Down Expand Up @@ -185,4 +191,105 @@ describe('FilterField', () => {
expect(valueSelectContainer.style.display).toBe('none');

});

it('tests the FilterField actions', () => {

const actions = {
onUpdateField: () => {},
onUpdateExceptionField: () => {},
onChangeCascadingValue: () => {}
};

const filterField = {
attribute: "attribute"
};

const attributes = [
{
attribute: "Attribute1",
label: "Attribute1",
type: "list",
values: [
{id: "attribute1", name: "attribute1"},
{id: "Attribute2", name: "attribute2"},
{id: "attribute3", name: "attribute3"},
{id: "attribute4", name: "attribute4"},
{id: "attribute5", name: "attribute5"}
],
valueId: "id",
valueLabel: "name",
fieldOptions: {"style": {display: "none"}},
dependson: {
field: "attribute"
}
}
];

const spyUpdateField = expect.spyOn(actions, 'onUpdateField');
const spyUpdateExceptionField = expect.spyOn(actions, 'onUpdateExceptionField');
const spyChangeCascadingValue = expect.spyOn(actions, 'onChangeCascadingValue');

const filterfield = ReactDOM.render(<FilterField filterField={filterField} attributes={attributes} onUpdateField={actions.onUpdateField} onChangeCascadingValue={actions.onChangeCascadingValue} onUpdateExceptionField={actions.onUpdateExceptionField}/>, document.getElementById("container"));

filterfield.props.onUpdateField();
expect(filterfield).toExist();
filterfield.updateFieldElement(200, "name", "value", "string");
expect(spyUpdateField).toHaveBeenCalled();
expect(spyChangeCascadingValue).toNotHaveBeenCalled();
expect(spyUpdateField).toHaveBeenCalledWith(200, "name", "value", "string");
filterfield.updateFieldElement(200, "value", "value", "boolean");
expect(spyUpdateField).toHaveBeenCalled();
expect(spyChangeCascadingValue).toHaveBeenCalled();
expect(spyUpdateField).toHaveBeenCalledWith(200, "name", "value", "string");
expect(spyChangeCascadingValue).toHaveBeenCalledWith(attributes);
filterfield.updateExceptionFieldElement(200, 'error');
expect(spyUpdateExceptionField).toHaveBeenCalled();
expect(spyUpdateExceptionField).toHaveBeenCalledWith(200, 'error');
expect.restoreSpies();
});

it('tests the FilterField actions without dependson field attribute', () => {

const actions = {
onUpdateField: () => {},
onUpdateExceptionField: () => {},
onChangeCascadingValue: () => {}
};

const filterField = {
attribute: "attribute"
};

const attributes = [
{
attribute: "Attribute1",
label: "Attribute1",
type: "list",
values: [
{id: "attribute1", name: "attribute1"},
{id: "Attribute2", name: "attribute2"},
{id: "attribute3", name: "attribute3"},
{id: "attribute4", name: "attribute4"},
{id: "attribute5", name: "attribute5"}
],
valueId: "id",
valueLabel: "name",
fieldOptions: {"style": {display: "none"}},
dependson: {}
}
];

const spyUpdateField = expect.spyOn(actions, 'onUpdateField');
const spyChangeCascadingValue = expect.spyOn(actions, 'onChangeCascadingValue');

const filterfield = ReactDOM.render(<FilterField filterField={filterField} attributes={attributes} onUpdateField={actions.onUpdateField} onChangeCascadingValue={actions.onChangeCascadingValue} onUpdateExceptionField={actions.onUpdateExceptionField}/>, document.getElementById("container"));

expect(filterfield).toExist();
filterfield.updateFieldElement(200, "value", "value", "string");
expect(spyUpdateField).toHaveBeenCalled();
expect(spyUpdateField).toHaveBeenCalledWith(200, "value", "value", "string");
expect(spyChangeCascadingValue).toNotHaveBeenCalled();

expect.restoreSpies();
});
});
19 changes: 17 additions & 2 deletions web/client/components/data/query/__tests__/GroupField-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ReactDOM = require('react-dom');

const expect = require('expect');

const GroupField = require('../QueryBuilder.jsx');
const GroupField = require('../GroupField.jsx');

describe('GroupField', () => {

Expand Down Expand Up @@ -114,7 +114,22 @@ describe('GroupField', () => {
}

const buttons = document.getElementsByClassName('btn btn-default');
expect(buttons.length).toBe(6);
expect(buttons.length).toBe(4);

const list = groupfield.getOperator({type: "list"});
expect(list).toEqual(["="]);
const string = groupfield.getOperator({type: "string"});
expect(string).toEqual(["=", "like", "ilike", "isNull"]);
const boolean = groupfield.getOperator({type: "boolean"});
expect(boolean).toEqual(["="]);
const noType = groupfield.getOperator();
expect(noType).toEqual(["=", ">", "<", ">=", "<=", "<>", "><"]);

const noSelected = groupfield.getComboValues();
expect(noSelected).toBe(null);

const selectedDependsOn = groupfield.getComboValues({dependson: { field: 'field'}}, attributes);
expect(selectedDependsOn).toBe(null);
});

it('creates the GroupField with cascading', () => {
Expand Down

0 comments on commit e9076cd

Please sign in to comment.