mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-11-10 05:34:44 +00:00
fix js linting
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
72e2f0fa03
commit
e73a544ab2
@ -1,76 +1,76 @@
|
|||||||
import {strict as assert} from "node:assert";
|
import {strict as assert} from "node:assert";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills out a create or update review form
|
* Fills out a create or update review form
|
||||||
* @param {Object} page the page object which contains the create or update form
|
* @param {Object} page the page object which contains the create or update form
|
||||||
* @param {Object} review review data to input into the form
|
* @param {Object} review review data to input into the form
|
||||||
*/
|
*/
|
||||||
export async function setReviewForm(page, review) {
|
export async function setReviewForm(page, review) {
|
||||||
|
|
||||||
// Set text fields
|
// Set text fields
|
||||||
await page.$eval("#imgAlt", (el, value) => el.value = value, review.imgAlt);
|
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("#mealName", (el, value) => el.value = value, review.mealName);
|
||||||
await page.$eval("#comments", (el, value) => el.value = value, review.comments);
|
await page.$eval("#comments", (el, value) => el.value = value, review.comments);
|
||||||
await page.$eval("#restaurant", (el, value) => el.value = value, review.restaurant);
|
await page.$eval("#restaurant", (el, value) => el.value = value, review.restaurant);
|
||||||
|
|
||||||
// Get all tag elements and click them to delete them
|
// Get all tag elements and click them to delete them
|
||||||
let tag_items = await page.$$(".tag");
|
let tag_items = await page.$$(".tag");
|
||||||
if(tag_items !== null){
|
if(tag_items !== null){
|
||||||
for(let i = 0; i < tag_items.length; i++){
|
for(let i = 0; i < tag_items.length; i++){
|
||||||
await tag_items[i].click();
|
await tag_items[i].click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the button needed to add new tags
|
// Get the button needed to add new tags
|
||||||
let tag_btn = await page.$("#tag-add-btn");
|
let tag_btn = await page.$("#tag-add-btn");
|
||||||
for(let i = 0; i < review.tags.length; i++){
|
for(let i = 0; i < review.tags.length; i++){
|
||||||
await page.$eval("#tag-form", (el, value) => el.value = value, review.tags[i]);
|
await page.$eval("#tag-form", (el, value) => el.value = value, review.tags[i]);
|
||||||
await tag_btn.click();
|
await tag_btn.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select a new rating
|
// Select a new rating
|
||||||
let rating_select = await page.$(`#s${review.rating}-select`);
|
let rating_select = await page.$(`#s${review.rating}-select`);
|
||||||
await rating_select.click({delay: 100});
|
await rating_select.click({delay: 100});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests a page or shadowDOM for correct element text, src, or alt values
|
* Tests a page or shadowDOM for correct element text, src, or alt values
|
||||||
* @param {Object} root page or shodowDOM to test
|
* @param {Object} root page or shodowDOM to test
|
||||||
* @param {string} prefix prefix character for element IDs
|
* @param {string} prefix prefix character for element IDs
|
||||||
* @param {Object} expected values for eahc element
|
* @param {Object} expected values for eahc element
|
||||||
*/
|
*/
|
||||||
export async function checkCorrectness(root, prefix, expected){
|
export async function checkCorrectness(root, prefix, expected){
|
||||||
// Get the review image and check src and alt
|
// Get the review image and check src and alt
|
||||||
let img = await root.$(`#${prefix}-mealImg`);
|
let img = await root.$(`#${prefix}-mealImg`);
|
||||||
let imgSrc = await img.getProperty("src");
|
let imgSrc = await img.getProperty("src");
|
||||||
let imgAlt = await img.getProperty("alt");
|
let imgAlt = await img.getProperty("alt");
|
||||||
// Check src and alt
|
// Check src and alt
|
||||||
assert.strictEqual(await imgSrc.jsonValue(), expected.imgSrc);
|
assert.strictEqual(await imgSrc.jsonValue(), expected.imgSrc);
|
||||||
assert.strictEqual(await imgAlt.jsonValue(), expected.imgAlt);
|
assert.strictEqual(await imgAlt.jsonValue(), expected.imgAlt);
|
||||||
|
|
||||||
// Get the title, comment, and restaurant
|
// Get the title, comment, and restaurant
|
||||||
let title = await root.$(`#${prefix}-mealName`);
|
let title = await root.$(`#${prefix}-mealName`);
|
||||||
let title_text = await title.getProperty("innerText");
|
let title_text = await title.getProperty("innerText");
|
||||||
let comment = await root.$(`#${prefix}-comments`);
|
let comment = await root.$(`#${prefix}-comments`);
|
||||||
let comment_text = await comment.getProperty("innerText");
|
let comment_text = await comment.getProperty("innerText");
|
||||||
let restaurant = await root.$(`#${prefix}-restaurant`);
|
let restaurant = await root.$(`#${prefix}-restaurant`);
|
||||||
let restaurant_text = await restaurant.getProperty("innerText");
|
let restaurant_text = await restaurant.getProperty("innerText");
|
||||||
|
|
||||||
// Check title, comment, and restaurant
|
// Check title, comment, and restaurant
|
||||||
assert.strictEqual(await title_text.jsonValue(), expected.mealName);
|
assert.strictEqual(await title_text.jsonValue(), expected.mealName);
|
||||||
assert.strictEqual(await comment_text.jsonValue(), expected.comments);
|
assert.strictEqual(await comment_text.jsonValue(), expected.comments);
|
||||||
assert.strictEqual(await restaurant_text.jsonValue(), expected.restaurant);
|
assert.strictEqual(await restaurant_text.jsonValue(), expected.restaurant);
|
||||||
|
|
||||||
// Check tags
|
// Check tags
|
||||||
let tags = await root.$$(".tag");
|
let tags = await root.$$(".tag");
|
||||||
assert.strictEqual(await tags.length, expected.tags.length);
|
assert.strictEqual(await tags.length, expected.tags.length);
|
||||||
for(let i = 0; i < expected.tags.length; i++){
|
for(let i = 0; i < expected.tags.length; i++){
|
||||||
let tag_text = await tags[i].getProperty("innerText");
|
let tag_text = await tags[i].getProperty("innerText");
|
||||||
assert.strictEqual(await tag_text.jsonValue(), expected.tags[i]);
|
assert.strictEqual(await tag_text.jsonValue(), expected.tags[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check stars
|
// Check stars
|
||||||
let stars = await root.$(`#${prefix}-rating`);
|
let stars = await root.$(`#${prefix}-rating`);
|
||||||
let stars_src = await stars.getProperty("src");
|
let stars_src = await stars.getProperty("src");
|
||||||
assert.strictEqual(await stars_src.jsonValue(), expected.rating);
|
assert.strictEqual(await stars_src.jsonValue(), expected.rating);
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ 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"
|
import {setReviewForm, checkCorrectness} from "./appTestHelpers.js";
|
||||||
|
|
||||||
describe("test App end to end", async () => {
|
describe("test App end to end", async () => {
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ describe("test App end to end", async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//browser = await puppeteer.launch({headless: false, slowMo: 250, args: root ? ['--no-sandbox'] : undefined});
|
//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{
|
||||||
await page.goto("http://localhost:8080", {timeout: 1000});
|
await page.goto("http://localhost:8080", {timeout: 1000});
|
||||||
@ -54,7 +54,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "sample restaurant",
|
restaurant: "sample restaurant",
|
||||||
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
rating: 1
|
rating: 1
|
||||||
}
|
};
|
||||||
await setReviewForm(page, review);
|
await setReviewForm(page, review);
|
||||||
|
|
||||||
// Click the save button to save updates
|
// Click the save button to save updates
|
||||||
@ -73,7 +73,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "sample restaurant",
|
restaurant: "sample restaurant",
|
||||||
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
||||||
}
|
};
|
||||||
await checkCorrectness(page, "d", expected);
|
await checkCorrectness(page, "d", expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "sample restaurant",
|
restaurant: "sample restaurant",
|
||||||
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
||||||
}
|
};
|
||||||
await checkCorrectness(shadowRoot, "a", expected);
|
await checkCorrectness(shadowRoot, "a", expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -121,7 +121,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "sample restaurant",
|
restaurant: "sample restaurant",
|
||||||
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
||||||
}
|
};
|
||||||
await checkCorrectness(page, "d", expected);
|
await checkCorrectness(page, "d", expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "sample restaurant",
|
restaurant: "sample restaurant",
|
||||||
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
tags: ["tag 0", "tag 1", "tag 2", "tag 3", "tag 4"],
|
||||||
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
rating: "http://localhost:8080/assets/images/icons/1-star.svg"
|
||||||
}
|
};
|
||||||
await checkCorrectness(shadowRoot, "a", expected);
|
await checkCorrectness(shadowRoot, "a", expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -170,7 +170,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "updated restaurant",
|
restaurant: "updated restaurant",
|
||||||
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
||||||
rating: 5
|
rating: 5
|
||||||
}
|
};
|
||||||
await setReviewForm(page, review);
|
await setReviewForm(page, review);
|
||||||
|
|
||||||
// Click the save button to save updates
|
// Click the save button to save updates
|
||||||
@ -189,7 +189,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "updated restaurant",
|
restaurant: "updated restaurant",
|
||||||
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
||||||
rating: "http://localhost:8080/assets/images/icons/5-star.svg"
|
rating: "http://localhost:8080/assets/images/icons/5-star.svg"
|
||||||
}
|
};
|
||||||
await checkCorrectness(page, "d", expected);
|
await checkCorrectness(page, "d", expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ describe("test App end to end", async () => {
|
|||||||
restaurant: "updated restaurant",
|
restaurant: "updated restaurant",
|
||||||
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
tags: ["tag -0", "tag -1", "tag -2", "tag -3", "tag -4", "tag -5"],
|
||||||
rating: "http://localhost:8080/assets/images/icons/5-star.svg"
|
rating: "http://localhost:8080/assets/images/icons/5-star.svg"
|
||||||
}
|
};
|
||||||
await checkCorrectness(shadowRoot, "a", expected);
|
await checkCorrectness(shadowRoot, "a", expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ describe("test App end to end", async () => {
|
|||||||
await review_card.click();
|
await review_card.click();
|
||||||
await page.waitForNavigation();
|
await page.waitForNavigation();
|
||||||
|
|
||||||
page.on('dialog', async dialog => {
|
page.on("dialog", async dialog => {
|
||||||
console.log(dialog.message());
|
console.log(dialog.message());
|
||||||
await dialog.accept();
|
await dialog.accept();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user