This commit is contained in:
Märt Kalmo
2017-03-09 11:45:33 +02:00
commit 907d3f1517
8 changed files with 300 additions and 0 deletions

11
.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
node_modules
/.tmp
/.settings
/.classpath
/.project
/.idea
*.iml
*.log

12
checkout.bat Normal file
View File

@@ -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

7
checkout.sh Executable file
View File

@@ -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)

31
conf.js Normal file
View File

@@ -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');
}
};
}

204
hw2-spec.js Normal file
View File

@@ -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();
}

9
hw3-spec.js Normal file
View File

@@ -0,0 +1,9 @@
'use strict';
describe('Application part 3', function () {
it('should ...', function () {
fail('part 3 tests not implemented yet');
});
});

9
hw4-spec.js Normal file
View File

@@ -0,0 +1,9 @@
'use strict';
describe('Application part 4', function () {
it('should ...', function () {
fail('part 4 tests not implemented yet');
});
});

17
package.json Normal file
View File

@@ -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"
}
}