Skip to content

Commit

Permalink
Merge pull request #411 from webkom/e2e-stv-admin
Browse files Browse the repository at this point in the history
Fix the rest of the E2E tests
  • Loading branch information
SmithPeder authored Feb 7, 2021
2 parents 31c1a5c + 0892406 commit f1a7094
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/views/partials/admin/editElection.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion features/admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions features/step_definitions/adminSteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
});
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit f1a7094

Please sign in to comment.