2022-11-17 00:10:31 +00:00
|
|
|
import {strict as assert} from "node:assert";
|
2022-11-17 21:54:58 +00:00
|
|
|
import {describe, it, before, after} from "mocha";
|
2022-11-17 00:46:02 +00:00
|
|
|
import puppeteer from "puppeteer-core";
|
2022-11-20 21:39:21 +00:00
|
|
|
import {exit} from "node:process";
|
2022-11-20 22:07:01 +00:00
|
|
|
import {setReviewForm, checkCorrectness} from "./appTestHelpers.js";
|
2022-11-17 00:10:31 +00:00
|
|
|
|
|
|
|
describe("test App end to end", async () => {
|
|
|
|
|
|
|
|
let browser;
|
|
|
|
let page;
|
|
|
|
|
2022-11-17 20:32:38 +00:00
|
|
|
before(async () => {
|
2022-11-19 07:26:51 +00:00
|
|
|
let root;
|
|
|
|
try {
|
|
|
|
root = process.getuid() == 0;
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
root = false;
|
|
|
|
}
|
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
//browser = await puppeteer.launch({headless: false, slowMo: 250, args: root ? ['--no-sandbox'] : undefined});
|
2022-11-20 22:07:01 +00:00
|
|
|
browser = await puppeteer.launch({args: root ? ["--no-sandbox"] : undefined});
|
2022-11-17 00:10:31 +00:00
|
|
|
page = await browser.newPage();
|
|
|
|
try{
|
2022-11-19 07:26:51 +00:00
|
|
|
await page.goto("http://localhost:8080", {timeout: 1000});
|
|
|
|
await console.log(`✔ connected to localhost webserver as ${root ? "root" : "user"}`);
|
2022-11-17 00:10:31 +00:00
|
|
|
}
|
|
|
|
catch (error) {
|
2022-11-19 07:26:51 +00:00
|
|
|
await console.log("❌ failed to connect to localhost webserver on port 8080");
|
|
|
|
await exit(1);
|
2022-11-17 00:10:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
describe("test simple properties", async () => {
|
|
|
|
it("page should have correct title", async () => {
|
|
|
|
assert.strictEqual(await page.title(), "Food Journal");
|
|
|
|
});
|
2022-11-17 00:10:31 +00:00
|
|
|
});
|
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
describe("test CRUD on simple inputs and default image", () => {
|
|
|
|
|
|
|
|
describe("test create 1 new review", async () => {
|
|
|
|
it("create 1 new review", async () => {
|
|
|
|
// Click the button to create a new review
|
|
|
|
let create_btn = await page.$("#create-btn");
|
|
|
|
await create_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// create a new review
|
|
|
|
let review = {
|
|
|
|
imgAlt: "sample alt",
|
|
|
|
mealName: "sample name",
|
|
|
|
comments: "sample comment",
|
|
|
|
restaurant: "sample restaurant",
|
|
|
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
|
|
|
rating: 1
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await setReviewForm(page, review);
|
|
|
|
|
|
|
|
// Click the save button to save updates
|
|
|
|
let save_btn = await page.$("#save-btn");
|
|
|
|
await save_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
});
|
2022-11-17 23:32:37 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
it("check details page", async () => {
|
|
|
|
// check the details page for correctness
|
|
|
|
let expected = {
|
|
|
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
|
|
|
imgAlt: "sample alt",
|
|
|
|
mealName: "sample name",
|
|
|
|
comments: "sample comment",
|
|
|
|
restaurant: "sample restaurant",
|
|
|
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
|
|
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await checkCorrectness(page, "d", expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("check home page", async () => {
|
|
|
|
// Click the button to return to the home page
|
|
|
|
let home_btn = await page.$("#home-btn");
|
|
|
|
home_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Get the review card again and get its shadowRoot
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
let shadowRoot = await review_card.getProperty("shadowRoot");
|
|
|
|
|
|
|
|
let expected = {
|
|
|
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
|
|
|
imgAlt: "sample alt",
|
|
|
|
mealName: "sample name",
|
|
|
|
comments: "sample comment",
|
|
|
|
restaurant: "sample restaurant",
|
|
|
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
|
|
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await checkCorrectness(shadowRoot, "a", expected);
|
|
|
|
});
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 23:32:37 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
describe("test read 1 review after refresh", async () => {
|
|
|
|
it("refresh page", async () => {
|
|
|
|
// Reload the page
|
|
|
|
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });
|
|
|
|
});
|
2022-11-18 20:34:59 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
it("check details page", async () => {
|
|
|
|
// click review card
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
await review_card.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// check the details page for correctness
|
|
|
|
let expected = {
|
|
|
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
|
|
|
imgAlt: "sample alt",
|
|
|
|
mealName: "sample name",
|
|
|
|
comments: "sample comment",
|
|
|
|
restaurant: "sample restaurant",
|
|
|
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
|
|
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await checkCorrectness(page, "d", expected);
|
|
|
|
});
|
2022-11-18 20:34:59 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
it("check home page", async () => {
|
|
|
|
// Click the button to return to the home page
|
|
|
|
let home_btn = await page.$("#home-btn");
|
|
|
|
home_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Get the review card again and get its shadowRoot
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
let shadowRoot = await review_card.getProperty("shadowRoot");
|
|
|
|
|
|
|
|
// check the details page for correctness
|
|
|
|
let expected = {
|
|
|
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
|
|
|
imgAlt: "sample alt",
|
|
|
|
mealName: "sample name",
|
|
|
|
comments: "sample comment",
|
|
|
|
restaurant: "sample restaurant",
|
|
|
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
|
|
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await checkCorrectness(shadowRoot, "a", expected);
|
|
|
|
});
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
describe("test update 1 review", async () => {
|
|
|
|
|
|
|
|
it("update 1 review", async () => {
|
|
|
|
|
|
|
|
// Get the only review card and click it
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
await review_card.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Click the button to show update form
|
|
|
|
let update_btn = await page.$("#update-btn");
|
|
|
|
await update_btn.click();
|
|
|
|
|
|
|
|
// create a new review
|
|
|
|
let review = {
|
|
|
|
imgAlt: "updated alt",
|
|
|
|
mealName: "updated name",
|
|
|
|
comments: "updated comment",
|
|
|
|
restaurant: "updated restaurant",
|
|
|
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
|
|
|
rating: 5
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await setReviewForm(page, review);
|
|
|
|
|
|
|
|
// Click the save button to save updates
|
|
|
|
let save_btn = await page.$("#save-btn");
|
|
|
|
await save_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
});
|
2022-11-17 20:32:38 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
it("check details page", async () => {
|
|
|
|
// check the details page for correctness
|
|
|
|
let expected = {
|
|
|
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
|
|
|
imgAlt: "updated alt",
|
|
|
|
mealName: "updated name",
|
|
|
|
comments: "updated comment",
|
|
|
|
restaurant: "updated restaurant",
|
|
|
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
|
|
|
rating: "http://localhost:8080/assets/images/icons/5-star.svg"
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await checkCorrectness(page, "d", expected);
|
|
|
|
});
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
it("check home page", async () => {
|
|
|
|
// Click the button to return to the home page
|
|
|
|
let home_btn = await page.$("#home-btn");
|
|
|
|
home_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Get the review card again and get its shadowRoot
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
let shadowRoot = await review_card.getProperty("shadowRoot");
|
|
|
|
|
|
|
|
// check the details page for correctness
|
|
|
|
let expected = {
|
|
|
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
|
|
|
imgAlt: "updated alt",
|
|
|
|
mealName: "updated name",
|
|
|
|
comments: "updated comment",
|
|
|
|
restaurant: "updated restaurant",
|
|
|
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
|
|
|
rating: "http://localhost:8080/assets/images/icons/5-star.svg"
|
2022-11-20 22:07:01 +00:00
|
|
|
};
|
2022-11-20 21:39:21 +00:00
|
|
|
await checkCorrectness(shadowRoot, "a", expected);
|
2022-11-19 20:16:03 +00:00
|
|
|
});
|
|
|
|
|
2022-11-20 21:39:21 +00:00
|
|
|
});
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-20 21:39:52 +00:00
|
|
|
describe("test delete 1 review", async () => {
|
2022-11-20 21:39:21 +00:00
|
|
|
it("delete 1 review", async () => {
|
|
|
|
// Get the only review card and click it
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
await review_card.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
2022-11-20 22:07:01 +00:00
|
|
|
page.on("dialog", async dialog => {
|
2022-11-20 21:39:21 +00:00
|
|
|
console.log(dialog.message());
|
|
|
|
await dialog.accept();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get the delete button and click it
|
|
|
|
let delete_btn = await page.$("#delete-btn");
|
|
|
|
await delete_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Check that the card was correctly removed (there should be no remaining cards)
|
|
|
|
review_card = await page.$("#review-card");
|
|
|
|
assert.strictEqual(review_card, null);
|
|
|
|
});
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-20 21:39:21 +00:00
|
|
|
|
2022-11-17 20:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
2022-11-17 00:10:31 +00:00
|
|
|
await page.close();
|
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
});
|