Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Added basic unit test for testing dependant dropdowns #8

Merged
merged 1 commit into from
Jan 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react"]
}
33 changes: 33 additions & 0 deletions __tests__/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
jest.dontMock('./formSchema.json')
.dontMock('..');

describe('React Form', () => {
it('Should render all three levels', function() {
var React = require('react');
var ReactDOM = require('react-dom');
var TestUtils = require('react-addons-test-utils');
const Form = require("..");

var schema = require('./formSchema.json')
var renderedForm = TestUtils.renderIntoDocument(<Form schema = {schema}/>);
var likeColorSelect = TestUtils.findRenderedDOMComponentWithTag(renderedForm, "select");

//Set value of first dropdown to 'maybe'
// Note: Simply changing property 'value' will not trigger the event, we must also trigger the value onChange event.
likeColorSelect.value = "maybe";
TestUtils.Simulate.change(likeColorSelect, { value : "maybe" });

// Count amount of selects present in form
var count = TestUtils.scryRenderedDOMComponentsWithTag(renderedForm, "select").length
expect(count).toEqual(2);

// Rinse and repeat...
var likeColorSelect2 = TestUtils.scryRenderedDOMComponentsWithTag(renderedForm, "select")[1];
likeColorSelect2.value = "Yes";
TestUtils.Simulate.change(likeColorSelect2, { value : "Yes"});

count = TestUtils.scryRenderedDOMComponentsWithTag(renderedForm, "select").length
expect(count).toEqual(3);
});

});
120 changes: 120 additions & 0 deletions __tests__/formSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"definitions": {
"trueFave": {
"title": "A true favourite",
"type": "object",
"properties": {
"realFave": {
"title": "Yes/No?",
"type": "string"
}
},
"oneOf": [
{
"properties": {
"realFave": {
"enum": [
"No"
]
}
}
},
{
"properties": {
"realFave": {
"enum": [
"Yes"
]
},
"favo": {
"title": "Which one is it?",
"type": "string",
"enum": [
"Red",
"Blueberry",
"rainbow"
]
}
}
}
],
"x-hints": {
"form": {
"selector": "realFave"
}
}
}
},
"title": "Example form",
"description": "A form based on a schema",
"type": "object",
"x-hints": {
"form": {
"classes": "my-nice-form"
}
},
"properties": {
"color": {
"title": "Favourite colour",
"type": "object",
"properties": {
"hasFave": {
"title": "Do you have a favourite colour?",
"type": "string"
}
},
"oneOf": [
{
"properties": {
"hasFave": {
"enum": [
"no"
]
}
}
},
{
"properties": {
"hasFave": {
"enum": [
"maybe"
]
},
"trueFave": {
"title": "You must have a favourite colour!",
"$ref": "#/definitions/trueFave"
}
}
},
{
"properties": {
"hasFave": {
"enum": [
"yes"
]
},
"fave": {
"title": "Your favourite colour",
"type": "string",
"enum": [
"",
"red",
"green",
"blue",
"yellow",
"orange",
"purple",
"other"
]
}
}
}
],
"x-hints": {
"form": {
"selector": "hasFave"
}
}
}
}
}
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"start": "node server.js",
"gh-pages": "webpack --config ./config/webpack.gh-pages.js",
"deploy-gh-pages": "scripts/deploy.sh",
"dist": "webpack --config ./config/webpack.dist.js && webpack --config ./config/webpack.dist.min.js"
"dist": "webpack --config ./config/webpack.dist.js && webpack --config ./config/webpack.dist.min.js",
"test": "jest"
},
"keywords": [
"JSON-Schema",
Expand Down Expand Up @@ -35,20 +36,37 @@
"url": "https://github.com/ismaelga/react-json-editor.git"
},
"devDependencies": {
"babel-jest": "^6.0.1",
"babel-preset-react": "^6.3.13",
"css-loader": "^0.9.1",
"file-loader": "^0.8.1",
"highlight.js": "^8.4.0",
"html-loader": "^0.2.3",
"html-webpack-plugin": "^1.1.0",
"jest-cli": "^0.8.2",
"jsx-loader": "^0.12.2",
"marked": "^0.3.3",
"purecss": "^0.5.0",
"react-ghfork": "^0.3.0",
"react-hot-loader": "^1.1.6",
"react-addons-test-utils": "^0.14.6",
"react-dom": "^0.14.6",
"style-loader": "^0.8.3",
"url-loader": "^0.5.5",
"webpack": "^1.6.0",
"webpack-dev-server": "^1.7.0",
"xtend": "^4.0.0"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom",
"<rootDir>/node_modules/react-addons-test-utils",
"<rootDir>/node_modules/fbjs"
],
"modulePathIgnorePatterns": [
"<rootDir>/node_modules/"
]
}
}