mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-08-20 12:10:16 +08:00
Added some tests
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
'use strict';
|
||||
|
||||
/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */
|
||||
|
||||
describe('PhoneCat App', function() {
|
||||
|
||||
it('should redirect index.html to index.html#/phones', function() {
|
||||
browser.get('app/index.html');
|
||||
browser.getLocationAbsUrl().then(function(url) {
|
||||
expect(url).toEqual('/phones');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Phone list view', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
browser.get('app/index.html#/phones');
|
||||
});
|
||||
|
||||
|
||||
it('should filter the phone list as a user types into the search box', function() {
|
||||
|
||||
var phoneList = element.all(by.repeater('phone in phones'));
|
||||
var query = element(by.model('query'));
|
||||
|
||||
expect(phoneList.count()).toBe(20);
|
||||
|
||||
query.sendKeys('nexus');
|
||||
expect(phoneList.count()).toBe(1);
|
||||
|
||||
query.clear();
|
||||
query.sendKeys('motorola');
|
||||
expect(phoneList.count()).toBe(8);
|
||||
});
|
||||
|
||||
|
||||
it('should be possible to control phone order via the drop down select box', function() {
|
||||
|
||||
var phoneNameColumn = element.all(by.repeater('phone in phones').column('phone.name'));
|
||||
var query = element(by.model('query'));
|
||||
|
||||
function getNames() {
|
||||
return phoneNameColumn.map(function(elm) {
|
||||
return elm.getText();
|
||||
});
|
||||
}
|
||||
|
||||
query.sendKeys('tablet'); //let's narrow the dataset to make the test assertions shorter
|
||||
|
||||
expect(getNames()).toEqual([
|
||||
"Motorola XOOM\u2122 with Wi-Fi",
|
||||
"MOTOROLA XOOM\u2122"
|
||||
]);
|
||||
|
||||
element(by.model('orderProp')).element(by.css('option[value="name"]')).click();
|
||||
|
||||
expect(getNames()).toEqual([
|
||||
"MOTOROLA XOOM\u2122",
|
||||
"Motorola XOOM\u2122 with Wi-Fi"
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
it('should render phone specific links', function() {
|
||||
var query = element(by.model('query'));
|
||||
query.sendKeys('nexus');
|
||||
element.all(by.css('.phones li a')).first().click();
|
||||
browser.getLocationAbsUrl().then(function(url) {
|
||||
expect(url).toEqual('/phones/nexus-s');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Phone detail view', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
browser.get('app/index.html#/phones/nexus-s');
|
||||
});
|
||||
|
||||
|
||||
it('should display nexus-s page', function() {
|
||||
expect(element(by.binding('phone.name')).getText()).toBe('Nexus S');
|
||||
});
|
||||
|
||||
|
||||
it('should display the first phone image as the main phone image', function() {
|
||||
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
|
||||
});
|
||||
|
||||
|
||||
it('should swap main image if a thumbnail image is clicked on', function() {
|
||||
element(by.css('.phone-thumbs li:nth-child(3) img')).click();
|
||||
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);
|
||||
|
||||
element(by.css('.phone-thumbs li:nth-child(1) img')).click();
|
||||
expect(element(by.css('img.phone.active')).getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,101 @@
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
|
||||
basePath: '../',
|
||||
port: 9876,
|
||||
// urlRoot: "/",
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: true,
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
frameworks: ['jasmine'],
|
||||
|
||||
browsers: ['Chrome', 'Firefox'],
|
||||
|
||||
plugins: [
|
||||
'karma-chrome-launcher',
|
||||
'karma-firefox-launcher',
|
||||
'karma-jasmine'
|
||||
],
|
||||
|
||||
junitReporter: {
|
||||
outputFile: 'test_out/unit.xml',
|
||||
suite: 'unit'
|
||||
},
|
||||
|
||||
preprocessors: {
|
||||
"*.html": ["ng-html2js"]
|
||||
},
|
||||
|
||||
// ngHtml2JsPreprocessor: {
|
||||
// // If your build process changes the path to your templates,
|
||||
// // use stripPrefix and prependPrefix to adjust it.
|
||||
// // stripPrefix: "source/path/to/templates/.*/",
|
||||
// // prependPrefix: "web/path/to/templates/",
|
||||
//
|
||||
// // the name of the Angular module to create
|
||||
// moduleName: "scienceAlchemy.templates"
|
||||
// },
|
||||
|
||||
|
||||
// use this to fix server 404 errors. Karma server everything at /base
|
||||
proxies: {
|
||||
'/json/': '/base/json/'
|
||||
},
|
||||
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
|
||||
// dependencies
|
||||
'bower_components/jquery/dist/jquery.js',
|
||||
'bower_components/jquery-ui/jquery-ui.js',
|
||||
'bower_components/bootstrap/dist/js/bootstrap.js',
|
||||
'bower_components/angular/angular.js',
|
||||
'bower_components/angular-route/angular-route.js',
|
||||
'bower_components/angular-resource/angular-resource.js',
|
||||
'bower_components/angular-animate/angular-animate.js',
|
||||
'bower_components/angular-mocks/angular-mocks.js',
|
||||
'bower_components/angular-dragdrop/src/angular-dragdrop.js',
|
||||
'bower_components/angular-ui-grid/ui-grid.js',
|
||||
'bower_components/lodash/dist/lodash.js',
|
||||
'js/external/*.js',
|
||||
|
||||
// fixtures
|
||||
{
|
||||
pattern: 'index.html',
|
||||
watched: true,
|
||||
served: true,
|
||||
included: false
|
||||
}, {
|
||||
pattern: 'json/*.json',
|
||||
watched: true,
|
||||
served: true,
|
||||
included: false
|
||||
},
|
||||
{
|
||||
pattern: 'css/*.css',
|
||||
watched: true,
|
||||
served: true,
|
||||
included: false
|
||||
},
|
||||
|
||||
// files to test
|
||||
'js/storage.js',
|
||||
'js/helpers.js',
|
||||
'js/analytics.js',
|
||||
'js/gameobjects.js',
|
||||
'js/detector/flame.js',
|
||||
'js/detector/bubblr.js',
|
||||
'js/detector/event.js',
|
||||
'js/detector/detector.js',
|
||||
'js/ui.js',
|
||||
'js/game.js',
|
||||
'js/app.js',
|
||||
'test/unit/**/*.js'
|
||||
],
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
|
||||
specs: [
|
||||
'e2e/*.js'
|
||||
],
|
||||
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
|
||||
chromeOnly: true,
|
||||
|
||||
baseUrl: 'http://localhost:8000/',
|
||||
|
||||
framework: 'jasmine',
|
||||
|
||||
jasmineNodeOpts: {
|
||||
defaultTimeoutInterval: 30000
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for controllers go here */
|
||||
describe('scienceAlchemy controllers', function () {
|
||||
var $controller;
|
||||
|
||||
beforeEach(function () {
|
||||
jasmine.addMatchers({
|
||||
toEqualData: function(util, customEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var passed = angular.equals(actual, expected);
|
||||
return {
|
||||
pass: passed,
|
||||
message: 'Expected "' + actual + '"' + (passed ? '' : ' not') + ' to angular.equals "' + expected + '"'
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
beforeEach(module('scienceAlchemy'));
|
||||
beforeEach(inject(function (_$controller_) {
|
||||
// The injector unwraps the underscores (_) from around the parameter names when matching
|
||||
$controller = _$controller_;
|
||||
}));
|
||||
|
||||
describe('ElementController', function () {
|
||||
var $scope, controller;
|
||||
|
||||
beforeEach(function () {
|
||||
$scope = {};
|
||||
controller = $controller('ElementController',{$scope:$scope});
|
||||
});
|
||||
|
||||
it('should have elements', function () {
|
||||
expect(controller.elements).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be visible', function () {
|
||||
var item = controller.elements[0];
|
||||
expect(controller.isVisible(item)).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be isAvailable', function () {
|
||||
var item = controller.elements[0];
|
||||
expect(controller.isAvailable(item)).toBeDefined();
|
||||
});
|
||||
|
||||
// onDrop
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for directives go here */
|
||||
|
||||
describe('directives', function() {
|
||||
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for filters go here */
|
||||
|
||||
describe('filter', function () {
|
||||
|
||||
beforeEach(
|
||||
module('scienceAlchemy')
|
||||
);
|
||||
|
||||
describe('niceNumber', function () {
|
||||
it('should make numbers human readable',
|
||||
inject(function (niceNumberFilter) {
|
||||
expect(niceNumberFilter(100000000)).toBe("100.0M");
|
||||
expect(niceNumberFilter(10000)).toBe("10.0k");
|
||||
expect(niceNumberFilter(0.000000001)).toBe(1e-9);
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('niceTime', function () {
|
||||
it('should make time human readable',
|
||||
inject(function (niceTimeFilter) {
|
||||
expect(niceTimeFilter(100000000)).toBe("1 day, 3 h, 46 min, 40 s");
|
||||
expect(niceTimeFilter(10000)).toBe("10 s");
|
||||
expect(niceTimeFilter(0.000000001)).toBe("1 s");
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('currency', function () {
|
||||
it('should make currency human readable',
|
||||
inject(function (currencyFilter) {
|
||||
expect(currencyFilter(100000000)).toBe("JTN 100.0M");
|
||||
expect(currencyFilter(10000)).toBe("JTN 10.0k");
|
||||
expect(currencyFilter(0.000000001)).toBe('JTN 1e-9');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('reverse', function () {
|
||||
it('should reverse',
|
||||
inject(function (reverseFilter) {
|
||||
expect(reverseFilter([1,2,3])[0]).toBe(3);
|
||||
expect(reverseFilter([1,2,3])[1]).toBe(2);
|
||||
expect(reverseFilter([1,2,3])[2]).toBe(1);
|
||||
expect(reverseFilter([]).length).toBe(0);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[0].i).toBe(3);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[1].i).toBe(2);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[2].i).toBe(1);
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
describe('services', function () {
|
||||
|
||||
//load modules
|
||||
beforeEach(module('scienceAlchemy'));
|
||||
|
||||
// Test service availability
|
||||
describe('game', function () {
|
||||
it('should exist', inject(function (game) {
|
||||
expect(game).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('detector', function () {
|
||||
it('should exist', inject(function (detector) {
|
||||
expect(detector).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('lab', function () {
|
||||
it('should exist', inject(function (lab) {
|
||||
expect(lab).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user