From 0892406378baa6f79540bccca23361672b7c8937 Mon Sep 17 00:00:00 2001 From: Ludvig Hozman Date: Sun, 7 Feb 2021 18:42:56 +0100 Subject: [PATCH] Fix E2E tests for admin view with STV --- app/views/partials/admin/editElection.pug | 4 +-- features/admin.feature | 4 ++- features/step_definitions/adminSteps.js | 42 +++++++++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/views/partials/admin/editElection.pug b/app/views/partials/admin/editElection.pug index 7eadccd9..d8429f69 100644 --- a/app/views/partials/admin/editElection.pug +++ b/app/views/partials/admin/editElection.pug @@ -86,11 +86,11 @@ span.cs-tooltiptext Antall stemmer span / span.cs-tooltip {{ election.seats + 1 }} - span.cs-tooltiptext Antall stemmer + 1 + span.cs-tooltiptext Antall plasser + 1 span ⌋ + 1 = {{ election.thr }} h2 Logg ul.list-unstyled.log.mono - li(ng-repeat='elem in election.log')(ng-switch='elem.action') + li(ng-repeat='elem in election.log', ng-switch='elem.action') div(ng-switch-when='ITERATION') h5 {{ elem.action }} {{ elem.iteration }} p(ng-repeat='(key, value) in elem.counts') {{ key }} with {{ value }} votes diff --git a/features/admin.feature b/features/admin.feature index 406db96f..f2744adb 100644 --- a/features/admin.feature +++ b/features/admin.feature @@ -19,8 +19,10 @@ Feature: Admin And The election has votes And The election is deactivated And I am on the edit election page - When I click "Vis resultat" + When I click "Kalkuler resultat" Then I should see votes + And There should be 1 winner + And I should see "test alternative" as winner 1 Scenario: Count votes for active elections Given There is an active election diff --git a/features/step_definitions/adminSteps.js b/features/step_definitions/adminSteps.js index 4541bde2..d8e2807f 100644 --- a/features/step_definitions/adminSteps.js +++ b/features/step_definitions/adminSteps.js @@ -26,7 +26,9 @@ module.exports = function () { const election = alternatives.first(); Bluebird.all([ - expect(election.getText()).to.eventually.equal(this.election.title), + expect(election.element(by.css('span')).getText()).to.eventually.equal( + this.election.title + ), expect(alternatives.count()).to.eventually.equal(1), ]); }); @@ -65,22 +67,48 @@ module.exports = function () { }) ); - this.Given(/^The election has votes$/, function () { - this.alternative.addVote(this.user); + this.Given(/^The election has votes$/, async function () { + await this.election.addVote(this.user, [this.alternatives[0]]); }); this.Given(/^I am on the edit election page$/, function () { browser.get(`/admin/election/${this.election.id}/edit`); }); - this.Then(/^I should see votes$/, () => { + this.Then(/^I should see votes$/, function () { const alternatives = element.all( - by.repeater('alternative in election.alternatives') + by.repeater('(key, value) in elem.counts') ); const alternative = alternatives.first(); - const span = alternative.element(by.tagName('span')); - return expect(span.getText()).to.eventually.equal('1 - 100 %'); + return Bluebird.all([ + expect(alternative.getText()).to.eventually.equal( + `${this.alternatives[0].description} with 1 votes` + ), + expect(alternatives.get(1).getText()).to.eventually.equal( + `${this.alternatives[1].description} with 0 votes` + ), + expect(alternatives.get(2).getText()).to.eventually.equal( + `${this.alternatives[2].description} with 0 votes` + ), + ]); + }); + + this.Then(/^There should be (\d+) winners?$/, (count) => { + const winners = element.all( + by.repeater('winner in election.result.winners') + ); + return expect(winners.count()).to.eventually.equal(Number(count)); + }); + + this.Then(/^I should see "([^"]*)" as winner (\d+)$/, (winner, number) => { + const winners = element.all( + by.repeater('winner in election.result.winners') + ); + + return expect( + winners.get(Number(number) - 1).getText() + ).to.eventually.equal(`Vinner ${number}: ${winner}`); }); this.When(/^I enter a new alternative "([^"]*)"$/, (alternative) => {