diff --git a/checkout.bat b/checkout.bat index 2e36e94..05569b3 100644 --- a/checkout.bat +++ b/checkout.bat @@ -10,11 +10,6 @@ if "%1" == "" ( exit /b 1 ) -if "%TAG%" == "hw4" ( - echo hw4 not implemented yet - exit /b 1 -) - if "%TAG%" == "hw2" ( set SUB_DIR=ng1 ) @@ -23,6 +18,10 @@ if "%TAG%" == "hw3" ( set SUB_DIR=ng1 ) +if "%TAG%" == "hw4" ( + set SUB_DIR=ng2 +) + if "%SUB_DIR%" == "" ( echo unknown tag exit /b 1 @@ -42,4 +41,6 @@ cd %SUB_DIR% call npm install +call npm run build + call npm start diff --git a/checkout.sh b/checkout.sh index c8e703c..a368d27 100755 --- a/checkout.sh +++ b/checkout.sh @@ -12,20 +12,24 @@ if [ $# -eq 0 ];then exit 1 fi -if [ $TAG == "hw4" ]; then - echo 'not implemented yet' - exit 1 -fi - -if [ $TAG == "hw2" ] || [ $TAG == "hw3" ]; then +if [ ${TAG} == "hw2" ] || [ ${TAG} == "hw3" ]; then SUB_DIR="ng1" fi -if [ -z $SUB_DIR ]; then +if [ ${TAG} == "hw4" ]; then + SUB_DIR="ng2" +fi + +if [ -z "${SUB_DIR}" ]; then echo 'unknown tag' exit 1 fi -git clone https://bitbucket.org/$USER/i399 $TMP +git clone https://bitbucket.org/${USER}/i399 $TMP -(cd "$TMP" && git checkout $TAG && cd "$SUB_DIR" && npm install && npm start) +(cd "${TMP}" && \ + git checkout ${TAG} && \ + cd "${SUB_DIR}" && \ + npm install && \ + npm run build && \ + npm start) diff --git a/conf-ng2.js b/conf-ng2.js new file mode 100644 index 0000000..dd1c1f4 --- /dev/null +++ b/conf-ng2.js @@ -0,0 +1,6 @@ +var conf = require('./conf.js'); + +conf.config.useAllAngular2AppRoots = true; +conf.config.allScriptsTimeout = 15000; + +exports.config = conf.config; diff --git a/package.json b/package.json index 80dbc11..08477cc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "webdriver-manager start", "hw2tests": "protractor ./conf.js --specs spec/hw2-spec.js", "hw3tests": "jasmine", - "hw4tests": "protractor ./conf.js --specs spec/hw4-spec.js" + "hw4tests": "protractor ./conf-ng2.js --specs spec/hw4-spec.js" }, "devDependencies": { "jasmine": "^2.6.0", diff --git a/spec/hw4-spec.js b/spec/hw4-spec.js index c826981..160c84c 100644 --- a/spec/hw4-spec.js +++ b/spec/hw4-spec.js @@ -1,17 +1,234 @@ 'use strict'; +var BASE_URL = 'http://localhost:3000/'; + describe('Application part 4', function () { it = extendIt(it); fit = extendIt(fit); xit = extendIt(xit); - it('should ...', function () { + beforeEach(function() { + goTo(BASE_URL); + }); - fail('not implemented yet'); + 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')); }).deductedOnFailure(10); + + 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); + + }).deductedOnFailure(10); + + + 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); + + }).deductedOnFailure(5); + + + 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'); + + }).deductedOnFailure(2); + + + 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(); + + expect(currentUrl()).toBe(getUrl('#/search')); + + expect(element(by.tagName('table')).getText()).not.toContain(name); + + }).deductedOnFailure(2); + + + it('should delete multiple contacts', function () { + + var name1 = getSampleData().name; + var name2 = name1 + 1; + insertContact(name1); + insertContact(name2); + + expect(element(by.tagName('table')).getText()).toContain(name1); + expect(element(by.tagName('table')).getText()).toContain(name2); + + rowContainingText(name1).checkBox().click(); + rowContainingText(name2).checkBox().click(); + + link('delete-all-link').click(); + + expect(currentUrl()).toBe(getUrl('#/search')); + + expect(element(by.tagName('table')).getText()).not.toContain(name1); + expect(element(by.tagName('table')).getText()).not.toContain(name2); + + }).deductedOnFailure(1); + + 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'); + + }).deductedOnFailure(1); + + }); +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(); + expect(currentUrl()).toBe(getUrl('#/search')); +} + function extendIt(it) { return require('./helpers/points-reporter').extendIt(it); }