Skip to content

Commit

Permalink
Test for the record button
Browse files Browse the repository at this point in the history
  • Loading branch information
lauracc97 committed Apr 27, 2024
1 parent 0785802 commit 3fdcb73
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webapp/e2e/features/record-button.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Seeing the records table of a user

Scenario: The authenticated user can see their records
Given An authenticated user
When I navigate to the records page
Then I can see my records
60 changes: 60 additions & 0 deletions webapp/e2e/steps/record-button.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/record-button.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", {
waitUntil: "networkidle0",
})
.catch(() => {});
});

test('The authenticated user can see their records', ({given, when, then}) => {
let username;
let password;

given('An authenticated user', async () => {
username = "record1";
password = "record1";
await expect(page).toClick('button', { text: 'SignUp' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Add User' });
await expect(page).toClick('a', { text: 'Already have an account? Login here.' });
await expect(page).toClick('button', { text: 'Login' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Login' });
});

when('I navigate to the records page', async () => {
await expect(page).toClick('button', { text: 'Ver historial' });
});

then('I can see my records', async () => {
await expect(page).toMatchElement("th", { text: "Preguntas acertadas" });
await expect(page).toMatchElement("th", { text: "Nº preguntas" });
await expect(page).toMatchElement("th", { text: "Tiempo total" });
await expect(page).toMatchElement("th", { text: "Fecha" });
});
});

afterAll(async ()=>{
browser.close()
})

});
2 changes: 2 additions & 0 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let mongoserver;
let userservice;
let authservice;
let gatewayservice;
let recordservice;

async function startServer() {
console.log('Starting MongoDB memory server...');
Expand All @@ -13,6 +14,7 @@ async function startServer() {
process.env.MONGODB_URI = mongoUri;
userservice = await require("../../users/userservice/user-service");
authservice = await require("../../users/authservice/auth-service");
recordservice = await require("../../recordhistory/record-service");
gatewayservice = await require("../../gatewayservice/gateway-service");
}

Expand Down

0 comments on commit 3fdcb73

Please sign in to comment.