Skip to content

Commit

Permalink
Añadido token a add-friend
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 26, 2024
1 parent 3d67a8e commit ba78b08
Showing 1 changed file with 60 additions and 46 deletions.
106 changes: 60 additions & 46 deletions webapp/e2e/steps/add-friend.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let browser;
defineFeature(feature, (test) => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch({ headless: 'new', slowMo: 100 })
: await puppeteer.launch({ headless: 'new', slowMo: 100 });
? await puppeteer.launch({ headless: "new", slowMo: 100 })
: await puppeteer.launch({ headless: "new", slowMo: 100 });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });

Expand All @@ -21,55 +21,65 @@ defineFeature(feature, (test) => {
});

await page.setRequestInterception(true);
page.on('request', (req) => {
if (req.method() === 'OPTIONS'){
page.on("request", (req) => {
if (req.method() === "OPTIONS") {
req.respond({
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': '*'
}
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "*",
},
});
} else if (req.url().includes('/questions')) {
req.respond({
status: 200,
headers: {
'Access-Control-Allow-Origin': '*'
},
contentType: 'application/json',
body: JSON.stringify([{
pregunta: 'Test question',
respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'],
correcta: 'Test correct answer',

}, {
pregunta: 'Test question 2',
respuestas: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'],
correcta: 'Test correct answer'
}]
)
});
} else {
req.continue();
}
});

} else if (req.url().includes("/questions")) {
req.respond({
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
},
contentType: "application/json",
body: JSON.stringify([
{
pregunta: "Test question",
respuestas: [
"Test answer 1",
"Test answer 2",
"Test answer 3",
"Test correct answer",
],
correcta: "Test correct answer",
},
{
pregunta: "Test question 2",
respuestas: [
"Test answer 1",
"Test answer 2",
"Test answer 3",
"Test correct answer",
],
correcta: "Test correct answer",
},
]),
});
} else {
req.continue();
}
});
});
let username;
let password;
let userCountBefore;
test("The user can add a friend", ({ given, when, then }) => {
given("A logged-in user and another user", async () => {
await expect(page).toClick("a", { text: "Regístrate" });
username="Friend";
password="Friend123";
await page.waitForSelector('#register-username');
await page.type('#register-username', username);
await page.waitForSelector('#register-password');
await page.type('#register-password', password);
await page.waitForSelector('#register-pass2');
await page.type('#register-pass2', password);
username = "Friend";
password = "Friend123";
await page.waitForSelector("#register-username");
await page.type("#register-username", username);
await page.waitForSelector("#register-password");
await page.type("#register-password", password);
await page.waitForSelector("#register-pass2");
await page.type("#register-pass2", password);
await page.click("button", { text: "Registrarse" });

await page.waitForTimeout(1000);
Expand All @@ -91,6 +101,13 @@ defineFeature(feature, (test) => {
when("I add the user as a friend", async () => {
await page.waitForTimeout(1000);

localStorage.setItem("username", "testuser");
localStorage.setItem("token", "testtoken");

await page.goto("http://localhost:3000/social/usuarios", {
waitUntil: "networkidle0",
});

await page.click('button[aria-label="Abrir menú"]');
await page.click('[data-testid="home-usuarios-link"]');
//await page.waitForNavigation({ waitUntil: "networkidle0" });
Expand All @@ -101,23 +118,20 @@ defineFeature(feature, (test) => {

await page.waitForSelector('[data-testid^="add-friend-button-"]');
await page.click('[data-testid^="add-friend-button-"]');

});
});

then("The user should disappear from the Users page", async () => {

await page.waitForTimeout(1000);
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });

const userRowsAfter = await page.$$('[data-testid^="user-row-"]');
const userCountAfter = userRowsAfter.length;

expect(userCountAfter).toBe(userCountBefore - 1);

expect(userCountAfter).toBe(userCountBefore - 1);
});
});

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

0 comments on commit ba78b08

Please sign in to comment.