add freeboard smoke test

pull/39/head
Kyle Campbell 2014-07-28 09:22:37 -04:00
parent f6497e8ebb
commit fe87753e50
4 changed files with 227 additions and 0 deletions

View File

@ -0,0 +1,100 @@
var util = require('../util/test_util.js');
casper.test.begin('Freeboard smoke test', function testFunction(test)
{
casper.start(util.FREEBOARD_URL, function()
{
// Test initial page load state
test.assertTitle('freeboard');
test.assertVisible(util.SELECTORS.adminBar);
test.assertNotVisible(util.SELECTORS.modalOverlay);
});
util.addJSONDatasource(test, 'json_input', 'test/fixtures/input.json');
casper.then(function() {
// Click add pane
test.assertNotVisible(util.SELECTORS.allPanes);
test.assertVisible(util.SELECTORS.boardTools);
this.click(util.SELECTORS.addPane);
test.assertVisible(util.SELECTORS.allPanes);
// Click add widget
this.click(util.SELECTORS.addWidget);
test.assertVisible(util.SELECTORS.pluginTypeDropdown);
// Select text widget
util.setValueAndTriggerChange(test, util.SELECTORS.pluginTypeDropdown, 'text_widget');
// Click datasource autofill
test.assertVisible(util.SELECTORS.valueValueInput);
test.assertVisible(util.SELECTORS.autofillDatasource);
this.click(util.SELECTORS.autofillDatasource);
test.assertVisible(util.SELECTORS.autofillMenu);
var valueName = this.fetchText(util.getAutofillMenuItemSelector(1));
test.assertEquals(valueName, 'json_input');
// Select the first (and only) datasource
this.mouseEvent('mousedown', util.getAutofillMenuItemSelector(1));
test.assertVisible(util.SELECTORS.autofillMenu);
// Select the "meta" sub-object of the datasource
valueName = this.fetchText(util.getAutofillMenuItemSelector(4));
test.assertEquals(valueName, 'meta');
this.mouseEvent('mousedown', util.getAutofillMenuItemSelector(4));
test.assertVisible(util.SELECTORS.autofillMenu);
// Select the "year" field to be displayed
valueName = this.fetchText(util.getAutofillMenuItemSelector(5));
test.assertEquals(valueName, 'year');
this.mouseEvent('mousedown', util.getAutofillMenuItemSelector(5));
test.assertNotVisible(util.SELECTORS.autofillMenu);
});
// Click save
util.clickModalOK(test);
casper.then(function() {
// Assert that the new text widget displays the correct value
test.assertVisible(util.SELECTORS.singlePaneTextWidget);
var textValue = this.fetchText(util.SELECTORS.singlePaneTextWidget);
test.assertEquals(textValue, '2018');
// Click and confirm delete widget
this.click(util.SELECTORS.trashWidget);
});
util.clickModalOK(test);
casper.then(function() {
// Assert widget deleted, pane not deleted
test.assertNotVisible(util.SELECTORS.allWidgets);
test.assertVisible(util.SELECTORS.allPanes);
// Click and confirm delete pane
this.click(util.SELECTORS.trashPane);
});
util.clickModalOK(test);
casper.then(function() {
// Confirm pane deleted
test.assertNotVisible(util.SELECTORS.allPanes);
// Click and confirm delete datasource
test.assertVisible(util.SELECTORS.datasourceTable);
this.click(util.SELECTORS.trashDatasource);
});
util.clickModalOK(test);
casper.then(function() {
// Confirm datasource deleted
test.assertNotVisible(util.SELECTORS.datasourceTable);
});
casper.run(function() {
this.reload();
test.done();
});
});

View File

@ -0,0 +1,84 @@
var fs = require('fs');
exports.FREEBOARD_URL = fs.workingDirectory + '/index.html';
exports.BOGUS = 'json_input';
var SELECTORS = {
adminBar : '#admin-bar',
modelOverlay : '#modal_overlay',
addDatasource : '#datasources span.text-button',
pluginTypeDropdown : '#modal_overlay #setting-value-container-plugin-types select',
nameValueInput : '#modal_overlay #setting-value-container-name input',
urlValueInput : '#modal_overlay #setting-value-container-url input',
valueValueInput : '#modal_overlay #setting-value-container-value textarea',
modalOK : '#modal_overlay #dialog-ok',
modalValidationError : '#modal_overlay validation-error',
datasourceTable : '#datasources table#datasources-list',
datasourceName : '#datasources table#datasources-list span.datasource-name',
datasoureUpdated : '#datasources table#datasources-list tr td:nth-child(2)',
allPanes : '#board-content li',
allWidgets : '#board-content li section',
boardTools : '#board-tools',
addPane : '#board-tools #add-pane',
addWidget : '#board-content li header li i.icon-plus',
autofillDatasource : '#modal_overlay #setting-value-container-value li i.icon-plus',
autofillMenu : '#modal_overlay #value-selector',
autofillMenuItem : '#modal_overlay #value-selector li:nth-child(%s)',
singlePaneTextWidget : '#board-content li section div.text-widget-regular-value',
trashWidget : '#board-content li section i.icon-trash',
trashPane : '#board-content li header i.icon-trash',
trashDatasource : '#datasources table#datasources-list i.icon-trash'
};
exports.SELECTORS = SELECTORS;
function setValueAndTriggerChange(test, selector, value) {
test.assertVisible(selector);
casper.evaluate(function(selector, value) {
$(selector).val(value).change();
}, selector, value);
}
exports.setValueAndTriggerChange = setValueAndTriggerChange;
function clickModalOK(test) {
casper.then(function() {
test.assertVisible(SELECTORS.modalOK);
casper.click(SELECTORS.modalOK);
test.assertNotVisible(SELECTORS.modalValidationError);
});
casper.waitWhileVisible('#modal_overlay');
}
exports.clickModalOK = clickModalOK;
exports.getAutofillMenuItemSelector = function(index) {
return SELECTORS.autofillMenuItem.replace('%s', index);
}
exports.addJSONDatasource = function(test, name, url) {
casper.then(function() {
// Click Add datasource
casper.click(SELECTORS.addDatasource);
// Select JSON
setValueAndTriggerChange(test, SELECTORS.pluginTypeDropdown, 'JSON');
// Name the datasource "json_input"
setValueAndTriggerChange(test, SELECTORS.nameValueInput, name);
// Specify fixtures/input.json as the source
setValueAndTriggerChange(test, SELECTORS.urlValueInput, url);
});
// Click ok
clickModalOK(test);
casper.then(function() {
// Assert that the datasource displays correctly
test.assertVisible(SELECTORS.datasourceName);
var datasourceName = casper.fetchText(SELECTORS.datasourceName);
test.assertEquals(datasourceName, name);
var datasourceTime = casper.fetchText(SELECTORS.datasourceUpdated);
test.assertNotEquals(datasourceTime, 'never');
});
};

40
test/fixtures/input.json vendored 100644
View File

@ -0,0 +1,40 @@
{
"x" : 42,
"y" : 19,
"z" : 313,
"meta" : {
"owner" :
{
"first_name" : "Alfonso",
"last_name" : "Jones",
"maiden_name" : "Smith"
},
"country" : "USA",
"make" : "BMW",
"model" : "XL",
"year" : "2018"
},
"entries" : ["2000", "2003", "2004", "2006", "2011", "2014"],
"previous_owners" : [
{
"owner" : "Zelnit",
"country" : "Russia"
},
{
"owner" : "Yolga",
"country" : "Venezuela"
},
{
"owner" : "Xavier",
"country" : "Poland"
},
{
"owner" : "Voltron",
"country" : "Greenland"
},
{
"owner" : "Uther",
"country" : "Cambodia"
}
]
}

View File

@ -0,0 +1,3 @@
cd "$( dirname "$0" )"
cd ..
casperjs test test/casper/tests/