Skip to content

Commit

Permalink
Structured tests some more and some commented out code for checking i…
Browse files Browse the repository at this point in the history
…f the right buildings are shown.
  • Loading branch information
rehmsen committed Dec 14, 2014
1 parent 29efe2e commit 6650af1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 16 deletions.
54 changes: 53 additions & 1 deletion src/e2e-tests/main-page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/// <reference path="../../typings/angular-protractor/angular-protractor.d.ts" />
/// <reference path="../../typings/selenium-webdriver/selenium-webdriver.d.ts" />

function hasClass(element: protractor.ElementFinder, cls: string) {
return element.getAttribute('class').then(function (classes) {
return classes.split(' ').indexOf(cls) !== -1;
});
};

class MainPage {
foodIndicator = element(by.className('icon-food'));
Expand All @@ -18,10 +25,55 @@ class MainPage {
}

taskDistribution = element(by.className('task-distribution'));
idleTaskAssignment = this.taskDistribution.element(by.className('icon-idle'));
getTaskAssignment(taskObject: string) {
return this.taskDistribution.element(by.className('icon-' + taskObject));
}
expectAssigned(taskObject: string, count: number) {
expect(this.getTaskAssignment(taskObject).isPresent()).toBe(true);
expect(this.taskDistribution.element(by.className('counter')).getText()).toBe('' + count);
}

buildPane = element(by.tagName('build-pane'));

unitButtons = element.all(by.repeater('unit in ctrl.rulesService.units'));
techButtons = element.all(by.repeater('tech in ctrl.rulesService.technologies'));

// expectEnabledButtons(buttons: protractor.ElementArrayFinder, icons: string[]) {
// buttons.filter((button) => {
// return button.isDisplayed() && button.isEnabled();
// }).then((displayedEnabledButtons) => {
// var displayedEnabledIconPromises = displayedEnabledButtons.map((button: protractor.ElementFinder) => {
// return button.getAttribute('class').then((classesString: string) => {
// var classes = classesString.split(' ');
// var iconClasses = classes.filter((cls) => {
// return cls.indexOf('icon-') == 0;
// });
// expect(iconClasses.length).toBe(1);
// return iconClasses[0].substring('icon-'.length);
// });
// });
// webdriver.promise.fullyResolved(displayedEnabledIconPromises).then((displayedEnabledIcons) => {
// expect(displayedEnabledIcons).toEqual(icons);
// })
// });


// // icons.forEach((icon: string) => {
// // buttons.filter(function(button) {
// // return hasClass(button, 'icon-' + icon);
// // }).then(function(buttons) {
// // expect(buttons.length).toBe(1);
// // expect(buttons[0].isEnabled()).toBe(true);
// // })
// // });
// }

// expectDisabledButtons(buttons: protractor.ElementArrayFinder, icons: string[]) {
// icons.forEach((icon: string) => {
// expect(buttons.element(by.class('icon-' + icon))).not.isEnabled();
// });
// }

constructButton = element(by.className('icon-construct'));
constructHouseButton = this.buildPane.element(by.className('icon-house'));

Expand Down
42 changes: 27 additions & 15 deletions src/e2e-tests/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,37 @@ describe('Main page', function() {
expect(browser.getTitle()).toEqual('AoC Planner');
});

it('should have the correct start resources', function() {
expect(mainPage.foodIndicator.getText()).toBe('200');
expect(mainPage.lumberIndicator.getText()).toBe('200');
expect(mainPage.goldIndicator.getText()).toBe('100');
expect(mainPage.stoneIndicator.getText()).toBe('200');

expect(mainPage.timeIndicator.getText()).toBe('0:00:00');
});
describe('initial state', function() {
it('should have the correct resources', function() {
expect(mainPage.foodIndicator.getText()).toBe('200');
expect(mainPage.lumberIndicator.getText()).toBe('200');
expect(mainPage.goldIndicator.getText()).toBe('100');
expect(mainPage.stoneIndicator.getText()).toBe('200');

it('should start in dark age', function() {
expect(mainPage.ageName.getText()).toBe('Dark Age');
});
expect(mainPage.timeIndicator.getText()).toBe('0:00:00');
});

it('should start at time 0', function() {
expect(mainPage.timeIndicator.getText()).toBe('0:00:00');
it('should be in dark age', function() {
expect(mainPage.ageName.getText()).toBe('Dark Age');
});

// it('should show dark age units', function() {
// mainPage.expectEnabledButtons(mainPage.unitButtons, ['villager']);
// // mainPage.expectDisabledButtons(mainPage.unitButtons, ['militia']);
// });

it('should be at time 0', function() {
expect(mainPage.timeIndicator.getText()).toBe('0:00:00');
});

it('should have 3 idle villagers', function() {
mainPage.expectAssigned('idle', 3);
});
});

it('should allow selecting one idle villager', function() {
mainPage.idleTaskAssignment.click();
mainPage.getTaskAssignment('idle').click();
mainPage.expectSelected('idle', 1);
});

Expand All @@ -56,8 +68,8 @@ describe('Main page', function() {
});

it('should allow assigning multiple idle villagers to construct house', function() {
mainPage.idleTaskAssignment.click();
mainPage.idleTaskAssignment.click();
mainPage.getTaskAssignment('idle').click();
mainPage.getTaskAssignment('idle').click();
mainPage.constructButton.click();
mainPage.constructHouseButton.click();

Expand Down

0 comments on commit 6650af1

Please sign in to comment.