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-17 00:10:31 +00:00
|
|
|
import { exit } from "node:process";
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-18 20:34:59 +00:00
|
|
|
describe("test create 1 new review", async () => {
|
|
|
|
it("create 1 new review", async () => {
|
2022-11-19 04:36:10 +00:00
|
|
|
// Click the button to show update form
|
|
|
|
let create_btn = await page.$("#create-btn");
|
|
|
|
await create_btn.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Set text fields
|
|
|
|
await page.$eval("#mealImg", el => el.value = "sample src");
|
|
|
|
await page.$eval("#imgAlt", el => el.value = "sample alt");
|
|
|
|
await page.$eval("#mealName", el => el.value = "sample name");
|
|
|
|
await page.$eval("#comments", el => el.value = "sample comment");
|
|
|
|
await page.$eval("#restaurant", el => el.value = "sample restaurant");
|
|
|
|
|
|
|
|
// Get the button needed to add new tags
|
|
|
|
let tag_btn = await page.$("#tag-add-btn");
|
|
|
|
for(let i = 0; i < 5; i++){
|
|
|
|
await page.$eval("#tag-form", (el, value) => el.value = `tag ${value}`, i);
|
|
|
|
await tag_btn.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select a new rating of 1 star
|
|
|
|
let rating_select = await page.$("#s1");
|
|
|
|
rating_select.click();
|
2022-11-17 20:32:38 +00:00
|
|
|
|
2022-11-19 04:36:10 +00:00
|
|
|
// Click the save button to save updates
|
2022-11-19 04:43:55 +00:00
|
|
|
let save_btn = await page.$("#save-btn");
|
|
|
|
save_btn.click();
|
2022-11-19 04:36:10 +00:00
|
|
|
await page.waitForNavigation();
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 20:32:38 +00:00
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
it("check details page", async () => {
|
2022-11-19 07:08:54 +00:00
|
|
|
// click review card
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
console.log(JSON.stringify(review_card));
|
|
|
|
await review_card.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Get the review image and check src and alt
|
|
|
|
let img = await page.$("#d-mealImg");
|
|
|
|
let imgSrc = await img.getProperty("src");
|
|
|
|
let imgAlt = await img.getProperty("alt");
|
|
|
|
// Check src and alt
|
|
|
|
assert.strictEqual(await imgSrc.jsonValue(), "sample src");
|
|
|
|
assert.strictEqual(await imgAlt.jsonValue(), "sample alt");
|
|
|
|
|
|
|
|
// Get the title, comment, and restaurant
|
|
|
|
let title = await page.$("#d-mealName");
|
|
|
|
let title_text = await title.getProperty("innerText");
|
|
|
|
let comment = await page.$("#d-comments");
|
|
|
|
let comment_text = await comment.getProperty("innerText");
|
|
|
|
let restaurant = await page.$("#d-restaurant");
|
|
|
|
let restaurant_text = await restaurant.getProperty("innerText");
|
|
|
|
|
|
|
|
// Check title, comment, and restaurant
|
|
|
|
assert.strictEqual(await title_text.jsonValue(), "sample name");
|
|
|
|
assert.strictEqual(await comment_text.jsonValue(), "sample comment");
|
|
|
|
assert.strictEqual(await restaurant_text.jsonValue(), "sample restaurant");
|
|
|
|
|
|
|
|
// Check tags
|
|
|
|
let tags = page.$(".tag");
|
|
|
|
for(let i = 0; i < tags.length; i++){
|
|
|
|
let tag_text = await tags[i].getProperty("innerText");
|
|
|
|
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check stars
|
|
|
|
let stars = await page.$("#d-rating");
|
|
|
|
let stars_src = await stars.getProperty("src");
|
|
|
|
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/5-star.svg");
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("check home page", async () => {
|
2022-11-19 04:36:10 +00:00
|
|
|
// Click the button to return to the home page
|
|
|
|
let home_btn = await page.$("#home-btn");
|
|
|
|
home_btn.click();
|
|
|
|
await page.waitForNavigation();
|
2022-11-19 07:08:54 +00:00
|
|
|
|
|
|
|
// Get the review card again and get its shadowRoot
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
let shadowRoot = await review_card.getProperty("shadowRoot");
|
|
|
|
|
|
|
|
// Get the review image and check src and alt
|
|
|
|
let img = await shadowRoot.$("#a-mealImg");
|
|
|
|
let imgSrc = await img.getProperty("src");
|
|
|
|
let imgAlt = await img.getProperty("alt");
|
|
|
|
// Check src and alt
|
|
|
|
assert.strictEqual(await imgSrc.jsonValue(), "sample src");
|
|
|
|
assert.strictEqual(await imgAlt.jsonValue(), "sample alt");
|
|
|
|
|
|
|
|
// Get the title, comment, and restaurant
|
|
|
|
let title = await shadowRoot.$("#a-mealName");
|
|
|
|
let title_text = await title.getProperty("innerText");
|
|
|
|
let comment = await shadowRoot.$("#a-comments");
|
|
|
|
let comment_text = await comment.getProperty("innerText");
|
|
|
|
let restaurant = await shadowRoot.$("#a-restaurant");
|
|
|
|
let restaurant_text = await restaurant.getProperty("innerText");
|
|
|
|
// Check title, comment, and restaurant
|
|
|
|
assert.strictEqual(await title_text.jsonValue(), "sample name");
|
|
|
|
assert.strictEqual(await comment_text.jsonValue(), "sample comment");
|
|
|
|
assert.strictEqual(await restaurant_text.jsonValue(), "sample restaurant");
|
|
|
|
|
|
|
|
// Check tags
|
|
|
|
let tags = shadowRoot.$(".tag");
|
|
|
|
for(let i = 0; i < tags.length; i++){
|
|
|
|
let tag_text = await tags[i].getProperty("innerText");
|
|
|
|
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check stars
|
|
|
|
let stars = await shadowRoot.$("#a-rating");
|
|
|
|
let stars_src = await stars.getProperty("src");
|
|
|
|
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/5-star.svg");
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 23:32:37 +00:00
|
|
|
});
|
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
describe("test read 1 review after refresh", async () => {
|
|
|
|
it("refresh page", async () => {
|
2022-11-19 07:08:54 +00:00
|
|
|
// Reload the page
|
|
|
|
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
it("check details page", async () => {
|
2022-11-19 07:08:54 +00:00
|
|
|
// click review card
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
console.log(JSON.stringify(review_card));
|
|
|
|
await review_card.click();
|
|
|
|
await page.waitForNavigation();
|
|
|
|
|
|
|
|
// Get the review image and check src and alt
|
|
|
|
let img = await page.$("#d-mealImg");
|
|
|
|
let imgSrc = await img.getProperty("src");
|
|
|
|
let imgAlt = await img.getProperty("alt");
|
|
|
|
// Check src and alt
|
|
|
|
assert.strictEqual(await imgSrc.jsonValue(), "sample src");
|
|
|
|
assert.strictEqual(await imgAlt.jsonValue(), "sample alt");
|
|
|
|
|
|
|
|
// Get the title, comment, and restaurant
|
|
|
|
let title = await page.$("#d-mealName");
|
|
|
|
let title_text = await title.getProperty("innerText");
|
|
|
|
let comment = await page.$("#d-comments");
|
|
|
|
let comment_text = await comment.getProperty("innerText");
|
|
|
|
let restaurant = await page.$("#d-restaurant");
|
|
|
|
let restaurant_text = await restaurant.getProperty("innerText");
|
|
|
|
|
|
|
|
// Check title, comment, and restaurant
|
|
|
|
assert.strictEqual(await title_text.jsonValue(), "sample name");
|
|
|
|
assert.strictEqual(await comment_text.jsonValue(), "sample comment");
|
|
|
|
assert.strictEqual(await restaurant_text.jsonValue(), "sample restaurant");
|
|
|
|
|
|
|
|
// Check tags
|
|
|
|
let tags = page.$(".tag");
|
|
|
|
for(let i = 0; i < tags.length; i++){
|
|
|
|
let tag_text = await tags[i].getProperty("innerText");
|
|
|
|
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check stars
|
|
|
|
let stars = await page.$("#d-rating");
|
|
|
|
let stars_src = await stars.getProperty("src");
|
|
|
|
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/5-star.svg");
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 23:32:37 +00:00
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
it("check home page", async () => {
|
2022-11-19 07:08:54 +00:00
|
|
|
// 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");
|
|
|
|
|
|
|
|
// Get the review image and check src and alt
|
|
|
|
let img = await shadowRoot.$("#a-mealImg");
|
|
|
|
let imgSrc = await img.getProperty("src");
|
|
|
|
let imgAlt = await img.getProperty("alt");
|
|
|
|
// Check src and alt
|
|
|
|
assert.strictEqual(await imgSrc.jsonValue(), "sample src");
|
|
|
|
assert.strictEqual(await imgAlt.jsonValue(), "sample alt");
|
|
|
|
|
|
|
|
// Get the title, comment, and restaurant
|
|
|
|
let title = await shadowRoot.$("#a-mealName");
|
|
|
|
let title_text = await title.getProperty("innerText");
|
|
|
|
let comment = await shadowRoot.$("#a-comments");
|
|
|
|
let comment_text = await comment.getProperty("innerText");
|
|
|
|
let restaurant = await shadowRoot.$("#a-restaurant");
|
|
|
|
let restaurant_text = await restaurant.getProperty("innerText");
|
|
|
|
// Check title, comment, and restaurant
|
|
|
|
assert.strictEqual(await title_text.jsonValue(), "sample name");
|
|
|
|
assert.strictEqual(await comment_text.jsonValue(), "sample comment");
|
|
|
|
assert.strictEqual(await restaurant_text.jsonValue(), "sample restaurant");
|
2022-11-18 20:34:59 +00:00
|
|
|
|
2022-11-19 07:08:54 +00:00
|
|
|
// Check tags
|
|
|
|
let tags = shadowRoot.$(".tag");
|
|
|
|
for(let i = 0; i < tags.length; i++){
|
|
|
|
let tag_text = await tags[i].getProperty("innerText");
|
|
|
|
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check stars
|
|
|
|
let stars = await shadowRoot.$("#a-rating");
|
|
|
|
let stars_src = await stars.getProperty("src");
|
|
|
|
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/5-star.svg");
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
2022-11-17 23:32:37 +00:00
|
|
|
});
|
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
describe("test update 1 review", async () => {
|
|
|
|
|
|
|
|
it("update 1 review", async () => {
|
2022-11-19 04:36:10 +00:00
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
// Get the only review card and click it
|
|
|
|
let review_card = await page.$("review-card");
|
2022-11-19 04:36:10 +00:00
|
|
|
console.log(JSON.stringify(review_card));
|
2022-11-18 20:34:59 +00:00
|
|
|
await review_card.click();
|
2022-11-19 03:21:53 +00:00
|
|
|
await page.waitForNavigation();
|
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
// Click the button to show update form
|
2022-11-19 04:36:10 +00:00
|
|
|
let update_btn = await page.$("#update-btn");
|
2022-11-18 20:34:59 +00:00
|
|
|
await update_btn.click();
|
|
|
|
|
|
|
|
// Set text fields
|
|
|
|
await page.$eval("#mealImg", el => el.value = "updated src");
|
|
|
|
await page.$eval("#imgAlt", el => el.value = "updated alt");
|
|
|
|
await page.$eval("#mealName", el => el.value = "updated name");
|
|
|
|
await page.$eval("#comments", el => el.value = "updated comment");
|
|
|
|
await page.$eval("#restaurant", el => el.value = "updated restaurant");
|
|
|
|
|
|
|
|
// Get all tag elements and click them to delete them
|
|
|
|
let tag_items = await page.$$(".tag");
|
|
|
|
for(let i = 0; i < tag_items.length; i++){
|
|
|
|
await tag_items.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the button needed to add new tags
|
|
|
|
let tag_btn = await page.$("#tag-add-btn");
|
|
|
|
for(let i = 0; i < 5; i++){
|
2022-11-19 04:36:10 +00:00
|
|
|
await page.$eval("#tag-form", (el, value) => el.value = `updated tag -${value}`, i);
|
|
|
|
await tag_btn.click();
|
2022-11-18 20:34:59 +00:00
|
|
|
}
|
2022-11-19 04:36:10 +00:00
|
|
|
|
2022-11-19 04:37:33 +00:00
|
|
|
// Select a new rating of 5 stars
|
|
|
|
let rating_select = await page.$("#s5");
|
2022-11-18 20:34:59 +00:00
|
|
|
rating_select.click();
|
|
|
|
|
|
|
|
// Click the save button to save updates
|
2022-11-19 04:43:55 +00:00
|
|
|
let save_btn = await page.$("#save-btn");
|
|
|
|
save_btn.click();
|
2022-11-19 04:36:10 +00:00
|
|
|
await page.waitForNavigation();
|
2022-11-18 20:34:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("check details page", async () => {
|
|
|
|
// Get the review image and check src and alt
|
|
|
|
let img = await page.$("#d-mealImg");
|
|
|
|
let imgSrc = await img.getProperty("src");
|
|
|
|
let imgAlt = await img.getProperty("alt");
|
|
|
|
// Check src and alt
|
|
|
|
assert.strictEqual(await imgSrc.jsonValue(), "updated src");
|
|
|
|
assert.strictEqual(await imgAlt.jsonValue(), "updated alt");
|
|
|
|
|
|
|
|
// Get the title, comment, and restaurant
|
|
|
|
let title = await page.$("#d-mealName");
|
|
|
|
let title_text = await title.getProperty("innerText");
|
|
|
|
let comment = await page.$("#d-comments");
|
|
|
|
let comment_text = await comment.getProperty("innerText");
|
|
|
|
let restaurant = await page.$("#d-restaurant");
|
|
|
|
let restaurant_text = await restaurant.getProperty("innerText");
|
|
|
|
// Check title, comment, and restaurant
|
|
|
|
assert.strictEqual(await title_text.jsonValue(), "updated name");
|
|
|
|
assert.strictEqual(await comment_text.jsonValue(), "updated comment");
|
|
|
|
assert.strictEqual(await restaurant_text.jsonValue(), "updated restaurant");
|
|
|
|
|
|
|
|
// Check tags
|
|
|
|
let tags = page.$(".tag");
|
|
|
|
for(let i = 0; i < tags.length; i++){
|
|
|
|
let tag_text = await tags[i].getProperty("innerText");
|
2022-11-19 04:36:10 +00:00
|
|
|
assert.strictEqual(await tag_text.jsonValue(), `updated tag -${i}`);
|
2022-11-18 20:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check stars
|
|
|
|
let stars = await page.$("#d-rating");
|
|
|
|
let stars_src = await stars.getProperty("src");
|
|
|
|
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/1-star.svg");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("check home page", async () => {
|
|
|
|
// Click the button to return to the home page
|
|
|
|
let home_btn = await page.$("#home-btn");
|
|
|
|
home_btn.click();
|
2022-11-19 03:21:53 +00:00
|
|
|
await page.waitForNavigation();
|
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
// Get the review card again and get its shadowRoot
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
let shadowRoot = await review_card.getProperty("shadowRoot");
|
|
|
|
|
|
|
|
// Get the review image and check src and alt
|
|
|
|
let img = await shadowRoot.$("#a-mealImg");
|
|
|
|
let imgSrc = await img.getProperty("src");
|
|
|
|
let imgAlt = await img.getProperty("alt");
|
|
|
|
// Check src and alt
|
|
|
|
assert.strictEqual(await imgSrc.jsonValue(), "updated src");
|
|
|
|
assert.strictEqual(await imgAlt.jsonValue(), "updated alt");
|
|
|
|
|
|
|
|
// Get the title, comment, and restaurant
|
|
|
|
let title = await shadowRoot.$("#a-mealName");
|
|
|
|
let title_text = await title.getProperty("innerText");
|
|
|
|
let comment = await shadowRoot.$("#a-comments");
|
|
|
|
let comment_text = await comment.getProperty("innerText");
|
|
|
|
let restaurant = await shadowRoot.$("#a-restaurant");
|
|
|
|
let restaurant_text = await restaurant.getProperty("innerText");
|
|
|
|
// Check title, comment, and restaurant
|
|
|
|
assert.strictEqual(await title_text.jsonValue(), "updated name");
|
|
|
|
assert.strictEqual(await comment_text.jsonValue(), "updated comment");
|
|
|
|
assert.strictEqual(await restaurant_text.jsonValue(), "updated restaurant");
|
|
|
|
|
|
|
|
// Check tags
|
|
|
|
let tags = shadowRoot.$(".tag");
|
|
|
|
for(let i = 0; i < tags.length; i++){
|
|
|
|
let tag_text = await tags[i].getProperty("innerText");
|
|
|
|
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check stars
|
|
|
|
let stars = await shadowRoot.$("#a-rating");
|
|
|
|
let stars_src = await stars.getProperty("src");
|
|
|
|
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/1-star.svg");
|
|
|
|
});
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-17 20:32:38 +00:00
|
|
|
});
|
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
describe("test delete 1 review", () => {
|
|
|
|
it("delete 1 review", async () => {
|
|
|
|
// Get the only review card and click it
|
|
|
|
let review_card = await page.$("review-card");
|
|
|
|
await review_card.click();
|
2022-11-19 04:43:55 +00:00
|
|
|
await page.waitForNavigation();
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
// Get the delete button and click it
|
|
|
|
let delete_btn = await page.$("#delete-btn");
|
|
|
|
await delete_btn.click();
|
2022-11-19 04:43:55 +00:00
|
|
|
await page.waitForNavigation();
|
2022-11-17 21:54:58 +00:00
|
|
|
|
2022-11-18 20:34:59 +00:00
|
|
|
// 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-17 20:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
2022-11-17 00:10:31 +00:00
|
|
|
await page.close();
|
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
});
|