diff --git a/webapp/e2e/features/login-form.feature b/webapp/e2e/features/login-form.feature index a086ff7..d8bdf51 100644 --- a/webapp/e2e/features/login-form.feature +++ b/webapp/e2e/features/login-form.feature @@ -3,4 +3,14 @@ Feature: Login a registered user Scenario: The user is registered in the site Given An registered user When I fill the data in the form to log in - Then is taken to the home page \ No newline at end of file + Then is taken to the home page + +Scenario: User logs in with invalid credentials + Given a registered user with username "testUser" and password "testpass" + When I fill the login form with username "testUser" and incorrect password "wrongpass" + And I remain on the login page + +Scenario: User attempts to login without entering credentials + Given a registered user with username "testUser" and password "testpass" + When I attempt to log in without entering any credentials + And I remain on the login page \ No newline at end of file diff --git a/webapp/e2e/features/userprofile-form.feature b/webapp/e2e/features/userprofile-form.feature new file mode 100644 index 0000000..467d758 --- /dev/null +++ b/webapp/e2e/features/userprofile-form.feature @@ -0,0 +1,17 @@ +Feature: View and Change User Quiz Rankings + +Scenario: Viewing Global Rankings + Given the user navigates to their profile + When they select the "Global" category + Then they see their performance statistics for global quizzes + +Scenario: Switching Category to Flags + Given the user is on their profile page + When they click on the "Flags" category + Then they view their performance metrics for flag-related quizzes + +Scenario: Switching Category to Food + Given the user is on their profile page + When they click on the "Food" category + Then they view their performance metrics for food-related quizzes + diff --git a/webapp/e2e/steps/login-form.steps.js b/webapp/e2e/steps/login-form.steps.js index e949b11..239389b 100644 --- a/webapp/e2e/steps/login-form.steps.js +++ b/webapp/e2e/steps/login-form.steps.js @@ -45,10 +45,45 @@ defineFeature(feature, test => { then('is taken to the home page', async () => { await page.waitForNavigation({ waitUntil: "networkidle0" }); await expect(page).toMatchElement("h1", { text: "Welcome back, " + username + "!" }); + await expect(page).toClick("button", { text: "Log out" }); }); }); + test('User logs in with invalid credentials', ({ given, when, then }) => { + given('a registered user with username "testUser" and password "testpass"', async () => { + // No specific action needed since the user is already registered + }); + + when('I fill the login form with username "testUser" and incorrect password "wrongpass"', async () => { + await expect(page).toFill('input[name="username"]', 'testUser'); + await expect(page).toFill('input[name="password"]', 'wrongpass'); + await expect(page).toClick("button", { text: "Log In" }); + }); + + + then('I remain on the login page', async () => { + await expect(page).toMatchElement("h1", { text: "Access WIQ" }); + }); + }); + + test('User attempts to login without entering credentials', ({ given, when, then }) => { + given('a registered user with username "testUser" and password "testpass"', async () => { + // No specific action needed since the user is already registered + }); + + when('I attempt to log in without entering any credentials', async () => { + await expect(page).toFill('input[name="username"]', ''); + await expect(page).toFill('input[name="password"]', ''); + await expect(page).toClick("button", { text: "Log In" }); + }); + + + then('I remain on the login page', async () => { + await expect(page).toMatchElement("h1", { text: "Access WIQ" }); + }); + }); + afterAll(async ()=>{ browser.close() }) diff --git a/webapp/e2e/steps/userprofile-form.steps.js b/webapp/e2e/steps/userprofile-form.steps.js new file mode 100644 index 0000000..6232c9c --- /dev/null +++ b/webapp/e2e/steps/userprofile-form.steps.js @@ -0,0 +1,107 @@ +const puppeteer = require('puppeteer'); +const { defineFeature, loadFeature }=require('jest-cucumber'); +const setDefaultOptions = require('expect-puppeteer').setDefaultOptions +const feature = loadFeature('./features/userprofile-form.feature'); + + +let page; +let browser; + +defineFeature(feature, test => { + + beforeAll(async () => { + + browser = process.env.GITHUB_ACTIONS + ? await puppeteer.launch() + : await puppeteer.launch({ headless: false, slowMo: 20 }); + page = await browser.newPage(); + //Way of setting up the timeout + setDefaultOptions({ timeout: 10000 }) + + await page + .goto("http://localhost:3000/login", { + waitUntil: "networkidle0", + }) + .catch(() => {}); + }); + + test('Viewing Global Rankings', ({given,when,then}) => { + + let username; + let password; + + given('the user navigates to their profile', async () => { + username = "testUser" + password = "testpass"; + await expect(page).toClick("a", { text: "Log In" }); + await expect(page).toFill('input[name="username"]', username); + await expect(page).toFill('input[name="password"]', password); + await expect(page).toClick("button", { text: "Log In" }); + await expect(page).toClick("button", { text: "My stats" }); + }); + + when('they select the "Global" category', async () => { + + await expect(page).toMatchElement("h2", { text: "Username: " + username }); + await expect(page).toClick("button", { text: "Flags" }); + await expect(page).toClick("button", { text: "Global" }); + }); + + then('they see their performance statistics for global quizzes', async () => { + await expect(page).toMatchElement('.ranking h3', { text: "global Ranking" }); + await expect(page).toMatchElement(".ranking p:nth-child(1)", { text: "Total Answered Questions: " + 1 }); + }); + + }); + + test('Switching Category to Flags', ({given,when,then}) => { + + let username; + let password; + + given('the user is on their profile page', async () => { + username = "testUser" + password = "testpass"; + await expect(page).toMatchElement("h2", { text: "Username: " + username }); + }); + + when('they click on the "Flags" category', async () => { + + await expect(page).toClick("button", { text: "Flags" }); + }); + + then('they view their performance metrics for flag-related quizzes', async () => { + await expect(page).toMatchElement('.ranking h3', { text: "flags Ranking" }); + await expect(page).toMatchElement(".ranking p:nth-child(1)", { text: "Total Answered Questions: " + 1 }); + }); + + }); + + test('Switching Category to Food', ({given,when,then}) => { + + let username; + let password; + + given('the user is on their profile page', async () => { + username = "testUser" + password = "testpass"; + await expect(page).toMatchElement("h2", { text: "Username: " + username }); + }); + + when('they click on the "Food" category', async () => { + + await expect(page).toClick("button", { text: "Food" }); + }); + + then('they view their performance metrics for food-related quizzes', async () => { + await expect(page).toMatchElement('.ranking h3', { text: "foods Ranking" }); + await expect(page).toMatchElement(".ranking p:nth-child(1)", { text: "Total Answered Questions: " + 0 }); + }); + + }); + + afterAll(async ()=>{ + browser.close() + }) + +}); \ No newline at end of file diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 9c14242..8a43a0f 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -30,6 +30,13 @@ async function startServer() { email: email, password: password }); + + const pints = await axios.post('http://localhost:8001/addpoints', { + username: username, + category: "flags", + correct: "true" + }); + } catch (error) { console.error('Error adding user:', error.response.data); }