mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-12-26 17:09:09 +00:00
Merge branch 'sprint-2' into sprint-2-homepage-integration
This commit is contained in:
commit
db3e8dba8d
@ -50,7 +50,6 @@
|
|||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
||||||
<legend> Meal: </legend>
|
<legend> Meal: </legend>
|
||||||
<label for="Meal: ">Meal:
|
<label for="Meal: ">Meal:
|
||||||
<input type="text" id="mealName" name="mealName" required>
|
<input type="text" id="mealName" name="mealName" required>
|
||||||
@ -60,15 +59,14 @@
|
|||||||
<textarea name="comments" id="comments"></textarea>
|
<textarea name="comments" id="comments"></textarea>
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset class="rating">
|
||||||
<fieldset class="rating">
|
<legend> Rating: </legend>
|
||||||
<legend> Rating: </legend>
|
<input type="radio" id="s5" name="rating" value="5"/> <label for="s5" id="s5-select"> 5 stars </label>
|
||||||
<input type="radio" id="s5" name="rating" value="5"/> <label for="s5"> 5 stars </label>
|
<input type="radio" id="s4" name="rating" value="4"/> <label for="s4" id="s4-select"> 4 stars </label>
|
||||||
<input type="radio" id="s4" name="rating" value="4"/> <label for="s4"> 4 stars </label>
|
<input type="radio" id="s3" name="rating" value="3"/> <label for="s3" id="s3-select"> 3 stars </label>
|
||||||
<input type="radio" id="s3" name="rating" value="3"/> <label for="s3"> 3 stars </label>
|
<input type="radio" id="s2" name="rating" value="2"/> <label for="s2" id="s2-select"> 2 stars </label>
|
||||||
<input type="radio" id="s2" name="rating" value="2"/> <label for="s2"> 2 stars </label>
|
<input type="radio" id="s1" name="rating" value="1"/> <label for="s1" id="s1-select"> 1 star </label>
|
||||||
<input type="radio" id="s1" name="rating" value="1"/> <label for="s1"> 1 star </label>
|
</fieldset>
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Other Info:</legend>
|
<legend>Other Info:</legend>
|
||||||
@ -80,10 +78,10 @@
|
|||||||
Tags:
|
Tags:
|
||||||
<input type="text" id="tag-form" name="tag-form">
|
<input type="text" id="tag-form" name="tag-form">
|
||||||
<div class='tag-container' id="tag-container-form">
|
<div class='tag-container' id="tag-container-form">
|
||||||
|
</div>
|
||||||
|
<button type="button" id="tag-add-btn">Add Tag</button>
|
||||||
|
</label>
|
||||||
|
|
||||||
</div>
|
|
||||||
<button type="button" id="tagAdd">Add Tag</button>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<button type="submit" id="save-btn" value="Submit">Save Review</button>
|
<button type="submit" id="save-btn" value="Submit">Save Review</button>
|
||||||
|
@ -49,11 +49,11 @@
|
|||||||
|
|
||||||
<fieldset class="rating">
|
<fieldset class="rating">
|
||||||
<legend> Rating: </legend>
|
<legend> Rating: </legend>
|
||||||
<input type="radio" id="s5" name="rating" value="5"/> <label for="s5"> 5 stars </label>
|
<input type="radio" id="s5" name="rating" value="5"/> <label for="s5" id="s5-select"> 5 stars </label>
|
||||||
<input type="radio" id="s4" name="rating" value="4"/> <label for="s4"> 4 stars </label>
|
<input type="radio" id="s4" name="rating" value="4"/> <label for="s4" id="s4-select"> 4 stars </label>
|
||||||
<input type="radio" id="s3" name="rating" value="3"/> <label for="s3"> 3 stars </label>
|
<input type="radio" id="s3" name="rating" value="3"/> <label for="s3" id="s3-select"> 3 stars </label>
|
||||||
<input type="radio" id="s2" name="rating" value="2"/> <label for="s2"> 2 stars </label>
|
<input type="radio" id="s2" name="rating" value="2"/> <label for="s2" id="s2-select"> 2 stars </label>
|
||||||
<input type="radio" id="s1" name="rating" value="1"/> <label for="s1"> 1 star </label>
|
<input type="radio" id="s1" name="rating" value="1"/> <label for="s1" id="s1-select"> 1 star </label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@ -72,7 +72,7 @@
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<button type="submit" value="Submit">Add Review</button>
|
<button type="submit" id="save-btn" value="Submit">Add Review</button>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -46,7 +46,7 @@ function initFormHandler() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let tagAddBtn = document.getElementById("tagAdd");
|
let tagAddBtn = document.getElementById("tag-add-btn");
|
||||||
tagAddBtn.addEventListener("click", ()=> {
|
tagAddBtn.addEventListener("click", ()=> {
|
||||||
let tagField = document.getElementById("tag-form");
|
let tagField = document.getElementById("tag-form");
|
||||||
if (tagField.value.length > 0) {
|
if (tagField.value.length > 0) {
|
||||||
|
76
source/assets/scripts/appTestHelpers.js
Normal file
76
source/assets/scripts/appTestHelpers.js
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import {strict as assert} from "node:assert";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills out a create or update review form
|
||||||
|
* @param {Object} page the page object which contains the create or update form
|
||||||
|
* @param {Object} review review data to input into the form
|
||||||
|
*/
|
||||||
|
export async function setReviewForm(page, review) {
|
||||||
|
|
||||||
|
// Set text fields
|
||||||
|
await page.$eval("#imgAlt", (el, value) => el.value = value, review.imgAlt);
|
||||||
|
await page.$eval("#mealName", (el, value) => el.value = value, review.mealName);
|
||||||
|
await page.$eval("#comments", (el, value) => el.value = value, review.comments);
|
||||||
|
await page.$eval("#restaurant", (el, value) => el.value = value, review.restaurant);
|
||||||
|
|
||||||
|
// Get all tag elements and click them to delete them
|
||||||
|
let tag_items = await page.$$(".tag");
|
||||||
|
if(tag_items !== null){
|
||||||
|
for(let i = 0; i < tag_items.length; i++){
|
||||||
|
await tag_items[i].click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the button needed to add new tags
|
||||||
|
let tag_btn = await page.$("#tag-add-btn");
|
||||||
|
for(let i = 0; i < review.tags.length; i++){
|
||||||
|
await page.$eval("#tag-form", (el, value) => el.value = value, review.tags[i]);
|
||||||
|
await tag_btn.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select a new rating
|
||||||
|
let rating_select = await page.$(`#s${review.rating}-select`);
|
||||||
|
await rating_select.click({delay: 100});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests a page or shadowDOM for correct element text, src, or alt values
|
||||||
|
* @param {Object} root page or shodowDOM to test
|
||||||
|
* @param {string} prefix prefix character for element IDs
|
||||||
|
* @param {Object} expected values for eahc element
|
||||||
|
*/
|
||||||
|
export async function checkCorrectness(root, prefix, expected){
|
||||||
|
// Get the review image and check src and alt
|
||||||
|
let img = await root.$(`#${prefix}-mealImg`);
|
||||||
|
let imgSrc = await img.getProperty("src");
|
||||||
|
let imgAlt = await img.getProperty("alt");
|
||||||
|
// Check src and alt
|
||||||
|
assert.strictEqual(await imgSrc.jsonValue(), expected.imgSrc);
|
||||||
|
assert.strictEqual(await imgAlt.jsonValue(), expected.imgAlt);
|
||||||
|
|
||||||
|
// Get the title, comment, and restaurant
|
||||||
|
let title = await root.$(`#${prefix}-mealName`);
|
||||||
|
let title_text = await title.getProperty("innerText");
|
||||||
|
let comment = await root.$(`#${prefix}-comments`);
|
||||||
|
let comment_text = await comment.getProperty("innerText");
|
||||||
|
let restaurant = await root.$(`#${prefix}-restaurant`);
|
||||||
|
let restaurant_text = await restaurant.getProperty("innerText");
|
||||||
|
|
||||||
|
// Check title, comment, and restaurant
|
||||||
|
assert.strictEqual(await title_text.jsonValue(), expected.mealName);
|
||||||
|
assert.strictEqual(await comment_text.jsonValue(), expected.comments);
|
||||||
|
assert.strictEqual(await restaurant_text.jsonValue(), expected.restaurant);
|
||||||
|
|
||||||
|
// Check tags
|
||||||
|
let tags = await root.$$(".tag");
|
||||||
|
assert.strictEqual(await tags.length, expected.tags.length);
|
||||||
|
for(let i = 0; i < expected.tags.length; i++){
|
||||||
|
let tag_text = await tags[i].getProperty("innerText");
|
||||||
|
assert.strictEqual(await tag_text.jsonValue(), expected.tags[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check stars
|
||||||
|
let stars = await root.$(`#${prefix}-rating`);
|
||||||
|
let stars_src = await stars.getProperty("src");
|
||||||
|
assert.strictEqual(await stars_src.jsonValue(), expected.rating);
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import {strict as assert} from "node:assert";
|
import {strict as assert} from "node:assert";
|
||||||
import {describe, it, before, after} from "mocha";
|
import {describe, it, before, after} from "mocha";
|
||||||
import puppeteer from "puppeteer-core";
|
import puppeteer from "puppeteer-core";
|
||||||
import { exit } from "node:process";
|
import {exit} from "node:process";
|
||||||
|
import {setReviewForm, checkCorrectness} from "./appTestHelpers.js"
|
||||||
|
|
||||||
describe("test App end to end", async () => {
|
describe("test App end to end", async () => {
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ describe("test App end to end", async () => {
|
|||||||
root = false;
|
root = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//browser = await puppeteer.launch({headless: false, slowMo: 250, args: root ? ['--no-sandbox'] : undefined});
|
||||||
browser = await puppeteer.launch({args: root ? ['--no-sandbox'] : undefined});
|
browser = await puppeteer.launch({args: root ? ['--no-sandbox'] : undefined});
|
||||||
page = await browser.newPage();
|
page = await browser.newPage();
|
||||||
try{
|
try{
|
||||||
@ -35,346 +37,210 @@ describe("test App end to end", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("test create 1 new review", async () => {
|
describe("test CRUD on simple inputs and default image", () => {
|
||||||
it("create 1 new review", async () => {
|
|
||||||
// Click the button to show update form
|
|
||||||
let create_btn = await page.$("#create-btn");
|
|
||||||
await create_btn.click();
|
|
||||||
await page.waitForNavigation();
|
|
||||||
|
|
||||||
// Set text fields
|
describe("test create 1 new review", async () => {
|
||||||
await page.$eval("#mealImg", el => el.value = "sample src");
|
it("create 1 new review", async () => {
|
||||||
await page.$eval("#imgAlt", el => el.value = "sample alt");
|
// Click the button to create a new review
|
||||||
await page.$eval("#mealName", el => el.value = "sample name");
|
let create_btn = await page.$("#create-btn");
|
||||||
await page.$eval("#comments", el => el.value = "sample comment");
|
await create_btn.click();
|
||||||
await page.$eval("#restaurant", el => el.value = "sample restaurant");
|
await page.waitForNavigation();
|
||||||
|
|
||||||
// Get the button needed to add new tags
|
// create a new review
|
||||||
let tag_btn = await page.$("#tag-add-btn");
|
let review = {
|
||||||
for(let i = 0; i < 5; i++){
|
imgAlt: "sample alt",
|
||||||
await page.$eval("#tag-form", (el, value) => el.value = `tag ${value}`, i);
|
mealName: "sample name",
|
||||||
await tag_btn.click();
|
comments: "sample comment",
|
||||||
}
|
restaurant: "sample restaurant",
|
||||||
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
// Select a new rating of 1 star
|
rating: 1
|
||||||
let rating_select = await page.$("#s1");
|
}
|
||||||
rating_select.click();
|
await setReviewForm(page, review);
|
||||||
|
|
||||||
// Click the save button to save updates
|
// Click the save button to save updates
|
||||||
let save_btn = await page.$("#save-btn");
|
let save_btn = await page.$("#save-btn");
|
||||||
save_btn.click();
|
await save_btn.click();
|
||||||
await page.waitForNavigation();
|
await page.waitForNavigation();
|
||||||
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
await checkCorrectness(shadowRoot, "a", expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("check details page", async () => {
|
describe("test read 1 review after refresh", async () => {
|
||||||
// Get the review image and check src and alt
|
it("refresh page", async () => {
|
||||||
let img = await page.$("#d-mealImg");
|
// Reload the page
|
||||||
let imgSrc = await img.getProperty("src");
|
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });
|
||||||
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
|
it("check details page", async () => {
|
||||||
let title = await page.$("#d-mealName");
|
// click review card
|
||||||
let title_text = await title.getProperty("innerText");
|
let review_card = await page.$("review-card");
|
||||||
let comment = await page.$("#d-comments");
|
await review_card.click();
|
||||||
let comment_text = await comment.getProperty("innerText");
|
await page.waitForNavigation();
|
||||||
let restaurant = await page.$("#d-restaurant");
|
|
||||||
let restaurant_text = await restaurant.getProperty("innerText");
|
|
||||||
|
|
||||||
// Check title, comment, and restaurant
|
// check the details page for correctness
|
||||||
assert.strictEqual(await title_text.jsonValue(), "sample name");
|
let expected = {
|
||||||
assert.strictEqual(await comment_text.jsonValue(), "sample comment");
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
||||||
assert.strictEqual(await restaurant_text.jsonValue(), "sample restaurant");
|
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"
|
||||||
|
}
|
||||||
|
await checkCorrectness(page, "d", expected);
|
||||||
|
});
|
||||||
|
|
||||||
// Check tags
|
it("check home page", async () => {
|
||||||
let tags = page.$(".tag");
|
// Click the button to return to the home page
|
||||||
for(let i = 0; i < tags.length; i++){
|
let home_btn = await page.$("#home-btn");
|
||||||
let tag_text = await tags[i].getProperty("innerText");
|
home_btn.click();
|
||||||
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
await page.waitForNavigation();
|
||||||
}
|
|
||||||
|
|
||||||
// Check stars
|
// Get the review card again and get its shadowRoot
|
||||||
let stars = await page.$("#d-rating");
|
let review_card = await page.$("review-card");
|
||||||
let stars_src = await stars.getProperty("src");
|
let shadowRoot = await review_card.getProperty("shadowRoot");
|
||||||
assert.strictEqual(await stars_src.jsonValue(), "./assets/images/icons/5-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();
|
|
||||||
await page.waitForNavigation();
|
|
||||||
|
|
||||||
// Get the review card again and get its shadowRoot
|
// check the details page for correctness
|
||||||
let review_card = await page.$("review-card");
|
let expected = {
|
||||||
let shadowRoot = await review_card.getProperty("shadowRoot");
|
imgSrc: "http://localhost:8080/assets/images/icons/plate_with_cutlery.png",
|
||||||
|
imgAlt: "sample alt",
|
||||||
// Get the review image and check src and alt
|
mealName: "sample name",
|
||||||
let img = await shadowRoot.$("#a-mealImg");
|
comments: "sample comment",
|
||||||
let imgSrc = await img.getProperty("src");
|
restaurant: "sample restaurant",
|
||||||
let imgAlt = await img.getProperty("alt");
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
// Check src and alt
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
||||||
assert.strictEqual(await imgSrc.jsonValue(), "sample src");
|
}
|
||||||
assert.strictEqual(await imgAlt.jsonValue(), "sample alt");
|
await checkCorrectness(shadowRoot, "a", expected);
|
||||||
|
});
|
||||||
// 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");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("test read 1 review after refresh", async () => {
|
|
||||||
it("refresh page", async () => {
|
|
||||||
// Reload the page
|
|
||||||
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("check details page", async () => {
|
describe("test update 1 review", async () => {
|
||||||
// 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
|
it("update 1 review", async () => {
|
||||||
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
|
// Get the only review card and click it
|
||||||
let title = await page.$("#d-mealName");
|
let review_card = await page.$("review-card");
|
||||||
let title_text = await title.getProperty("innerText");
|
await review_card.click();
|
||||||
let comment = await page.$("#d-comments");
|
await page.waitForNavigation();
|
||||||
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
|
// Click the button to show update form
|
||||||
assert.strictEqual(await title_text.jsonValue(), "sample name");
|
let update_btn = await page.$("#update-btn");
|
||||||
assert.strictEqual(await comment_text.jsonValue(), "sample comment");
|
await update_btn.click();
|
||||||
assert.strictEqual(await restaurant_text.jsonValue(), "sample restaurant");
|
|
||||||
|
|
||||||
// Check tags
|
// create a new review
|
||||||
let tags = page.$(".tag");
|
let review = {
|
||||||
for(let i = 0; i < tags.length; i++){
|
imgAlt: "updated alt",
|
||||||
let tag_text = await tags[i].getProperty("innerText");
|
mealName: "updated name",
|
||||||
assert.strictEqual(await tag_text.jsonValue(), `tag -${i}`);
|
comments: "updated comment",
|
||||||
}
|
restaurant: "updated restaurant",
|
||||||
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
||||||
|
rating: 5
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
|
||||||
|
// 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"
|
||||||
|
}
|
||||||
|
await checkCorrectness(shadowRoot, "a", expected);
|
||||||
|
});
|
||||||
|
|
||||||
// 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");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("check home page", async () => {
|
describe("test delete 1 review", async () => {
|
||||||
// Click the button to return to the home page
|
it("delete 1 review", async () => {
|
||||||
let home_btn = await page.$("#home-btn");
|
// Get the only review card and click it
|
||||||
home_btn.click();
|
let review_card = await page.$("review-card");
|
||||||
await page.waitForNavigation();
|
await review_card.click();
|
||||||
|
await page.waitForNavigation();
|
||||||
|
|
||||||
// Get the review card again and get its shadowRoot
|
page.on('dialog', async dialog => {
|
||||||
let review_card = await page.$("review-card");
|
console.log(dialog.message());
|
||||||
let shadowRoot = await review_card.getProperty("shadowRoot");
|
await dialog.accept();
|
||||||
|
});
|
||||||
|
|
||||||
// Get the review image and check src and alt
|
// Get the delete button and click it
|
||||||
let img = await shadowRoot.$("#a-mealImg");
|
let delete_btn = await page.$("#delete-btn");
|
||||||
let imgSrc = await img.getProperty("src");
|
await delete_btn.click();
|
||||||
let imgAlt = await img.getProperty("alt");
|
await page.waitForNavigation();
|
||||||
// Check src and alt
|
|
||||||
assert.strictEqual(await imgSrc.jsonValue(), "sample src");
|
|
||||||
assert.strictEqual(await imgAlt.jsonValue(), "sample alt");
|
|
||||||
|
|
||||||
// Get the title, comment, and restaurant
|
// Check that the card was correctly removed (there should be no remaining cards)
|
||||||
let title = await shadowRoot.$("#a-mealName");
|
review_card = await page.$("#review-card");
|
||||||
let title_text = await title.getProperty("innerText");
|
assert.strictEqual(review_card, null);
|
||||||
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");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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");
|
|
||||||
console.log(JSON.stringify(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();
|
|
||||||
|
|
||||||
// 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++){
|
|
||||||
await page.$eval("#tag-form", (el, value) => el.value = `updated tag -${value}`, i);
|
|
||||||
await tag_btn.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select a new rating of 5 stars
|
|
||||||
let rating_select = await page.$("#s5");
|
|
||||||
rating_select.click();
|
|
||||||
|
|
||||||
// Click the save button to save updates
|
|
||||||
let save_btn = await page.$("#save-btn");
|
|
||||||
save_btn.click();
|
|
||||||
await page.waitForNavigation();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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");
|
|
||||||
assert.strictEqual(await tag_text.jsonValue(), `updated 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/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();
|
|
||||||
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(), "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");
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
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();
|
|
||||||
await page.waitForNavigation();
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user