commit 907d3f151712fba78791955cb95cd397b5afc252 Author: Märt Kalmo Date: Thu Mar 9 11:45:33 2017 +0200 1st diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d234112 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +node_modules + +/.tmp + +/.settings +/.classpath +/.project + +/.idea +*.iml +*.log diff --git a/checkout.bat b/checkout.bat new file mode 100644 index 0000000..7639169 --- /dev/null +++ b/checkout.bat @@ -0,0 +1,12 @@ + +git clone https://bitbucket.org/%1/i399 .\.tmp + +cd .\.tmp + +git checkout %2 + +if %errorlevel% neq 0 exit /b %errorlevel% + +call npm install + +call npm start diff --git a/checkout.sh b/checkout.sh new file mode 100755 index 0000000..3055737 --- /dev/null +++ b/checkout.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +git clone https://bitbucket.org/$1/i399 ./.tmp + +(cd ./.tmp && git checkout $2 && npm install && npm start) diff --git a/conf.js b/conf.js new file mode 100644 index 0000000..fdda263 --- /dev/null +++ b/conf.js @@ -0,0 +1,31 @@ +exports.config = { + seleniumAddress: 'http://localhost:4444/wd/hub', + + capabilities: { + 'browserName': 'phantomjs', + 'phantomjs.cli.args': ['--ignore-ssl-errors=true'] + }, + + suites: { + hw2: 'hw2-spec.js', + hw3: 'hw3-spec.js', + hw4: 'hw4-spec.js' + }, + + jasmineNodeOpts: { + showColors: true + }, + + onPrepare: function() { + jasmine.getEnv().addReporter(getReporter()); + } + +}; + +function getReporter() { + return { + suiteDone: function(result) { + console.log('Suite ' + result.description + ' done'); + } + }; +} diff --git a/hw2-spec.js b/hw2-spec.js new file mode 100644 index 0000000..4387169 --- /dev/null +++ b/hw2-spec.js @@ -0,0 +1,204 @@ +'use strict'; + +var BASE_URL = 'http://localhost:3000/'; + +describe('Application part 2', function () { + + beforeEach(function() { + goTo(BASE_URL); + }); + + it('menu links should change url', function () { + expect(currentUrl()).toBe(getUrl('#/search')); + + link('menu-new').click(); + + expect(currentUrl()).toBe(getUrl('#/new')); + + link('menu-search').click(); + + expect(currentUrl()).toBe(getUrl('#/search')); + }); + + it('should insert contact with name and phone number', function () { + + link('menu-new').click(); + + var sampleData = getSampleData(); + + input('name-input').setValue(sampleData.name); + input('phone-input').setValue(sampleData.phone); + + link('save-link').click(); + + expect(currentUrl()).toBe(getUrl('#/search')); + + expect(element(by.tagName('table')).getText()).toContain(sampleData.name); + expect(element(by.tagName('table')).getText()).toContain(sampleData.phone); + }); + + it('selecting a contact should change its row\'s css class', function () { + var name = getSampleData().name; + insertContact(name); + + rowContainingText(name).checkBox().click(); + + var cssClassesList = rowContainingText(name).cssClasses(); + + expect(cssClassesList).toContain('selected'); + }); + + it('should be able to edit contacts', function () { + var sampleData = getSampleData(); + var changedName = sampleData.name + 1; + insertContact(sampleData.name); + + rowContainingText(sampleData.name).elementWithCssClass('edit-link').click(); + + input('name-input').setValue(changedName); + link('save-link').click(); + + expect(currentUrl()).toBe(getUrl('#/search')); + expect(element(by.tagName('table')).getText()).toContain(changedName); + expect(element(by.tagName('table')).getText()).not.toContain(sampleData.name); + }); + + it('should ask confirmation on deleting', function () { + var name = getSampleData().name; + insertContact(name); + + rowContainingText(name).elementWithCssClass('delete-link').click(); + + expect(element(by.id('simple-modal')).isPresent()).toBe(true, "can't find modal"); + }); + + it('should delete contacts', function () { + + var name = getSampleData().name; + insertContact(name); + + expect(element(by.tagName('table')).getText()).toContain(name); + + rowContainingText(name).elementWithCssClass('delete-link').click(); + + link('simple-modal-ok').click(); + + expect(currentUrl()).toBe(getUrl('#/search')); + + expect(element(by.tagName('table')).getText()).not.toContain(name); + }); + + it('should filter by name and phone', function () { + + insertContact('Jaana'); + insertContact('Jaak'); + insertContact('Tiit', 'aa'); + insertContact('Tiina'); + + input('search-string').setValue('aa'); + + expect(element(by.tagName('table')).getText()).toContain('Jaana'); + expect(element(by.tagName('table')).getText()).toContain('Jaak'); + expect(element(by.tagName('table')).getText()).toContain('Tiit'); + expect(element(by.tagName('table')).getText()).not.toContain('Tiina'); + }); + +}); + +function rowContainingText(searchString) { + var rows = element.all(by.tagName('tr')) + .filter(function (each) { + return each.getText().then(function (text) { + return text.indexOf(searchString) >= 0; + }) + }); + + expect(rows.count()).toBe(1, 'should find exactly one matching row'); + + return { + elementWithCssClass: elementWithCssClass, + checkBox: checkBox, + cssClasses: cssClasses + }; + + function elementWithCssClass(cssClass) { + var elements = rows.get(0).all(by.css('.' + cssClass)); + + expect(elements.count()).toBe(1, 'should find exactly one matching element'); + + return elements.get(0); + } + + function cssClasses() { + return rows.first().getAttribute('class').then(function (string) { + return string.split(' '); + }); + } + + function checkBox() { + var checkboxes = rows.get(0).all(by.tagName('input')); + + expect(checkboxes.count()).toBe(1, 'should find exactly one checkbox'); + + return checkboxes.get(0); + } +} + +function link(id) { + return element(by.id(id)); +} + +function goTo(addr) { + browser.get(addr).then(function () { + browser.manage().window().setSize(1920, 1080); + }); +} + +function getUrl(path) { + return BASE_URL.replace(/\/$/, '') + '/' + path; +} + +function currentUrl() { + return browser.getCurrentUrl(); +} + +function getSampleData() { + var time = new Date().getTime(); + return { + name : time, + phone : time + 1 + }; +} + +function input(id) { + var input = element(by.id(id)); + + return { + getValue: getValue, + setValue: setValue, + isPresent : isPresent + }; + + function isPresent() { + return input.isPresent(); + } + + function setValue(value) { + if (value == null || value == undefined) { + return; + } + + input.clear().sendKeys(value); + } + + function getValue() { + return input.getAttribute('value'); + } +} + +function insertContact(name, phone) { + link('menu-new').click(); + input('name-input').setValue(name); + input('phone-input').setValue(phone); + link('save-link').click(); +} diff --git a/hw3-spec.js b/hw3-spec.js new file mode 100644 index 0000000..4a6a7b4 --- /dev/null +++ b/hw3-spec.js @@ -0,0 +1,9 @@ +'use strict'; + +describe('Application part 3', function () { + + it('should ...', function () { + fail('part 3 tests not implemented yet'); + }); + +}); diff --git a/hw4-spec.js b/hw4-spec.js new file mode 100644 index 0000000..3b22e85 --- /dev/null +++ b/hw4-spec.js @@ -0,0 +1,9 @@ +'use strict'; + +describe('Application part 4', function () { + + it('should ...', function () { + fail('part 4 tests not implemented yet'); + }); + +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..b344606 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "i399tester", + "version": "1.0.0", + "scripts": { + "update": "webdriver-manager update", + "postinstall": "npm run update", + "start": "webdriver-manager start", + "hw2_tests": "protractor ./conf.js --suite=hw2", + "hw3_tests": "protractor ./conf.js --suite=hw3", + "hw4_tests": "protractor ./conf.js --suite=hw4" + }, + "devDependencies": { + "phantomjs": "^2.1.7", + "protractor": "^4.0.11", + "request": "^2.79.0" + } +}