Skip to content

Commit

Permalink
Added more tests to cover all features
Browse files Browse the repository at this point in the history
  • Loading branch information
print-Sathvik committed Feb 14, 2024
1 parent 8d5e1e2 commit 79658c2
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
cypress/screenshots
135 changes: 102 additions & 33 deletions cypress/e2e/e2e.cy.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
/* eslint-disable no-undef */
describe('Testing Election Site', () => {
describe("Authentication Tests", () => {
it('Sign up', () => {
cy.visit('/signup');
cy.get("input[name='firstName']").type('First');
cy.get("input[name='lastName']").type('last');
cy.get("input[name='email']").type('[email protected]');
cy.get("input[name='password']").type('testpassword');
cy.get("button[type='submit']").click();
cy.location().should((loc) => {
expect(loc.pathname).to.eq("/elections");
});
});

it('Login', () => {
cy.visit('/signout');
cy.visit('/login');
cy.get("input[name='email']").type('[email protected]');
cy.get("input[name='password']").type('testpassword');
cy.get("button[type='submit']").click();
cy.location().should((loc) => {
expect(loc.pathname).to.eq("/elections");
});
});
})

describe('Election Organizer Test Suite', () => {
beforeEach(() => {
cy.session("Signup Session", () => {
cy.visit("/signup")
// cy.visit('/login');
// cy.get("input[name='email']").type('[email protected]');
// cy.get("input[name='password']").type('testpassword');
// cy.get("button[type='submit']").click();
cy.get("input[name='firstName']").type('First');
cy.get("input[name='lastName']").type('last');
cy.session("Login Session", () => {
cy.visit('/login');
cy.get("input[name='email']").type('[email protected]');
cy.get("input[name='password']").type('testpassword');
cy.get("button[type='submit']").click();
Expand All @@ -18,29 +37,6 @@ describe('Testing Election Site', () => {
})
})

// it('Sign up', () => {
// cy.visit('/signup');
// cy.get("input[name='firstName']").type('First');
// cy.get("input[name='lastName']").type('last');
// cy.get("input[name='email']").type('[email protected]');
// cy.get("input[name='password']").type('testpassword');
// cy.get("button[type='submit']").click();
// cy.location().should((loc) => {
// expect(loc.pathname).to.eq("/elections");
// });
// });

// it('Login', () => {
// cy.visit('/signout');
// cy.visit('/login');
// cy.get("input[name='email']").type('[email protected]');
// cy.get("input[name='password']").type('testpassword');
// cy.get("button[type='submit']").click();
// cy.location().should((loc) => {
// expect(loc.pathname).to.eq("/elections");
// });
// });

it('Create Election', () => {
cy.visit('/elections');
cy.get("input[name='title']").type('WD Election');
Expand Down Expand Up @@ -75,6 +71,13 @@ describe('Testing Election Site', () => {
cy.contains("voter2")
})

it('Start Election without Question', () => {
cy.visit("/elections")
cy.get("a").eq(5).click()
cy.url().should('contain', "preview")
cy.contains("Cannot start an election without any question")
})

it('Manage Questions', () => {
cy.visit('/elections')
cy.get("a").eq(4).click()
Expand All @@ -92,6 +95,72 @@ describe('Testing Election Site', () => {
cy.contains("Question added Successfully")
})

it('Start Election after adding question', () => {
cy.visit("/elections")
cy.get("a").eq(5).click()
cy.url().should('contain', "preview")
cy.get("button[type='submit']").click()
})


it('Signout', () => {
cy.visit("/elections")
cy.get("a").contains('Signout').click()
cy.location().should((loc) => {
expect(loc.pathname).to.eq("/");
});
})
});


describe('Voting Suite', () => {
beforeEach(() => {
cy.session("Voter Login Session", () => {
cy.visit("/vote/election/wdpoll")
cy.get("input[name='voterid']").type('voter1');
cy.get("input[name='password']").type('p1');
cy.get("button[type='submit']").click();
})
})

it('Vote', () => {
cy.visit("/vote/election/wdpoll")
cy.contains("How is the WD401 Course?")
cy.get("input[type='radio']").check("3")
cy.get("button[type='submit']").click();
cy.contains("You have already voted. Please wait for the result")
})

it('Same voter voting again', () => {
cy.visit("/vote/election/wdpoll")
cy.contains("You have already voted. Please wait for the result")
})
})

describe("After Election", () => {
beforeEach(() => {
cy.session("Admin Signin after election", () => {
cy.visit('/login');
cy.get("input[name='email']").type('[email protected]');
cy.get("input[name='password']").type('testpassword');
cy.get("button[type='submit']").click();
cy.location().should((loc) => {
expect(loc.pathname).to.eq("/elections");
});
})
})

it('Check Results', () => {
cy.visit("/elections")
cy.get("a").eq(5).click()
cy.url().should('contain', "status/bar")
cy.contains("Total Voters: 2")
cy.contains("No of voters polled: 1")
cy.contains("Voters remaining: 1")
})

it('End Election', () => {
cy.visit('/elections')
cy.get("button").eq(1).click()
cy.contains("Ended")
})
})

0 comments on commit 79658c2

Please sign in to comment.