From 8b62a00a29955f2767acf167393ff4c8b7b11219 Mon Sep 17 00:00:00 2001 From: Ludvig Hozman Date: Tue, 9 Feb 2021 11:36:04 +0100 Subject: [PATCH] Add some more admin tests --- app/views/partials/admin/editElection.pug | 9 +++++--- features/admin.feature | 25 ++++++++++++++++++++++- features/step_definitions/adminSteps.js | 2 +- features/step_definitions/webSteps.js | 13 ++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/app/views/partials/admin/editElection.pug b/app/views/partials/admin/editElection.pug index d8429f69..087bfb58 100644 --- a/app/views/partials/admin/editElection.pug +++ b/app/views/partials/admin/editElection.pug @@ -72,13 +72,16 @@ tbody tr th.th-left Stemmer - th.th-right = {{ election.voteCount }} + th.th-right = + span(ng-bind='election.voteCount') {{ election.voteCount }} tr th.th-left ∟ Hvorav blanke stemmer - th.th-right = {{ election.blankVoteCount }} + th.th-right = + span(ng-bind='election.blankVoteCount') {{ election.blankVoteCount }} tr th.th-left Plasser - th.th-right = {{ election.seats }} + th.th-right = + span(ng-bind='election.seats') {{ election.seats }} tr th.th-left Terskel th.th-right ⌊ diff --git a/features/admin.feature b/features/admin.feature index f2744adb..ce1d8b23 100644 --- a/features/admin.feature +++ b/features/admin.feature @@ -8,12 +8,32 @@ Feature: Admin When I am on page "/admin" Then I see a list of elections - Scenario: Create election + Scenario: Create basic election Given There is an inactive election And I am on page "/admin/create_election" When I create an election Then The election should exist + Scenario: Create invalid election + Given There is an inactive election + And I am on page "/admin/create_election" + When I fill in "title" with "test election" + And I fill in "seats" with "2" + And I fill in "alternative0" with "A" + Then Button "Submit" should be disabled + + Scenario: Create election with more seats + Given There is an inactive election + And I am on page "/admin/create_election" + When I fill in "title" with "test election" + And I fill in "seats" with "2" + And I fill in "alternative0" with "A" + And I click anchor "new-alternative" + And I fill in "alternative1" with "B" + Then Button "Submit" should not be disabled + When I click "Submit" + Then I see alert "Avstemning lagret" + Scenario: Count votes Given There is an active election And The election has votes @@ -21,6 +41,9 @@ Feature: Admin And I am on the edit election page When I click "Kalkuler resultat" Then I should see votes + And I should see 1 in "election.voteCount" + And I should see 0 in "election.blankVoteCount" + And I should see 1 in "election.seats" And There should be 1 winner And I should see "test alternative" as winner 1 diff --git a/features/step_definitions/adminSteps.js b/features/step_definitions/adminSteps.js index d8e2807f..87348382 100644 --- a/features/step_definitions/adminSteps.js +++ b/features/step_definitions/adminSteps.js @@ -129,7 +129,7 @@ module.exports = function () { }); this.Then(/^I should see ([\d]+) in "([^"]*)"$/, (count, binding) => { - const countElement = element(by.binding(binding)); + const countElement = element.all(by.binding(binding)).first(); return expect(countElement.getText()).to.eventually.equal(String(count)); }); }; diff --git a/features/step_definitions/webSteps.js b/features/step_definitions/webSteps.js index d1480373..b2e32479 100644 --- a/features/step_definitions/webSteps.js +++ b/features/step_definitions/webSteps.js @@ -59,6 +59,11 @@ module.exports = function () { button.click(); }); + this.When(/^I click anchor "([^"]*)"$/, (classname) => { + const anchor = element(by.className(classname)); + anchor.click(); + }); + this.Then(/^I should find "([^"]*)"$/, (selector) => expect(element(by.css(selector)).isPresent()).to.eventually.equal(true) ); @@ -88,4 +93,12 @@ module.exports = function () { const found = element.all(by.css(css)); expect(found.count()).to.eventually.equal(Number(count)); }); + + this.Then( + /^Button "([^"]*)" should( not)? be disabled$/, + (buttonText, not) => { + const button = element(by.buttonText(buttonText)); + expect(button.isEnabled()).to.eventually.equal(!!not); + } + ); };