Skip to content

Commit d049bc2

Browse files
committed
Add responsive design benchmark back
1 parent 06a0513 commit d049bc2

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

resources/default-tests.mjs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,4 +1077,109 @@ export const defaultSuites = [
10771077
}),
10781078
],
10791079
},
1080+
{
1081+
name: "Responsive-Design",
1082+
url: "experimental/responsive-design/dist/index.html",
1083+
tags: ["responsive-design", "webcomponents", "experimental"],
1084+
disabled: true,
1085+
type: "async",
1086+
async prepare(page) {
1087+
await page.waitForElement("cooking-app");
1088+
},
1089+
tests: [
1090+
new BenchmarkTestStep("LoadChatAndExpandRecipes", async (page) => {
1091+
const resumePreviousChatBtn = page.querySelector("#resume-previous-chat-btn", ["cooking-app", "chat-window"]);
1092+
resumePreviousChatBtn.click();
1093+
page.layout();
1094+
1095+
const nextRestaurantBtn = page.querySelector("#next-restaurant-btn", ["cooking-app", "information-window"]);
1096+
const restaurantCards = page.querySelectorAll("restaurant-card", ["cooking-app", "information-window"]);
1097+
const numOfRestaurantCards = restaurantCards.length - 1;
1098+
for (let i = 0; i < numOfRestaurantCards; i++) {
1099+
nextRestaurantBtn.click();
1100+
page.layout();
1101+
}
1102+
1103+
const showMoreBtn = page.querySelectorAll(".show-more-btn", ["cooking-app", "main-content", "recipe-grid"]);
1104+
for (const btn of showMoreBtn) {
1105+
btn.click();
1106+
page.layout();
1107+
}
1108+
}),
1109+
new BenchmarkTestStep("ReduceWidthIn5Steps", async (page) => {
1110+
const widths = [768, 704, 640, 560, 480];
1111+
const MATCH_MEDIA_QUERY_BREAKPOINT = 640;
1112+
1113+
// The matchMedia query is "(max-width: 640px)"
1114+
// Starting from a width > 640px, we'll only get 1 event when crossing to <= 640px
1115+
// This happens when the width changes from 704px to 640px
1116+
const resizeWorkPromise = new Promise((resolve) => {
1117+
page.addEventListener("resize-work-complete", resolve, { once: true });
1118+
});
1119+
1120+
for (const width of widths) {
1121+
page.setWidth(width);
1122+
page.layout();
1123+
if (width === MATCH_MEDIA_QUERY_BREAKPOINT)
1124+
await resizeWorkPromise;
1125+
}
1126+
1127+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
1128+
}),
1129+
new BenchmarkTestStep("ScrollToChatAndSendMessages", async (page) => {
1130+
const cvWorkComplete = new Promise((resolve) => {
1131+
page.addEventListener("video-grid-content-visibility-complete", resolve, { once: true });
1132+
});
1133+
1134+
const nextItemBtn = page.querySelector("#next-item-carousel-btn", ["cooking-app", "main-content", "recipe-carousel"]);
1135+
const recipeCarouselItems = page.querySelectorAll(".carousel-item", ["cooking-app", "main-content", "recipe-carousel"]);
1136+
const numOfCarouselItems = recipeCarouselItems.length - 3;
1137+
for (let i = 0; i < numOfCarouselItems; i++) {
1138+
nextItemBtn.click();
1139+
page.layout();
1140+
}
1141+
1142+
// Collapse recipes
1143+
const showMoreBtnCollapse = page.querySelectorAll(".show-more-btn", ["cooking-app", "main-content", "recipe-grid"]);
1144+
for (const btn of showMoreBtnCollapse) {
1145+
btn.click();
1146+
page.layout();
1147+
}
1148+
1149+
const chatWindow = page.querySelector("#chat-window", ["cooking-app", "chat-window"]);
1150+
chatWindow.scrollIntoView({ behavior: "instant" });
1151+
page.layout();
1152+
1153+
const messagesToBeSent = ["Please generate an image of Tomato Soup.", "Try again, but make the soup look thicker.", "Try again, but make the soup served in a rustic bowl and include a sprinkle of fresh herbs on top."];
1154+
const chatInput = page.querySelector("#chat-input", ["cooking-app", "chat-window"]);
1155+
for (const message of messagesToBeSent) {
1156+
chatInput.setValue(message);
1157+
chatInput.dispatchEvent("input");
1158+
chatInput.enter("keydown");
1159+
page.layout();
1160+
}
1161+
await cvWorkComplete;
1162+
}),
1163+
new BenchmarkTestStep("IncreaseWidthIn5Steps", async (page) => {
1164+
const widths = [560, 640, 704, 768, 800];
1165+
const MATCH_MEDIA_QUERY_BREAKPOINT = 704;
1166+
1167+
// The matchMedia query is "(max-width: 640px)"
1168+
// Starting from a width <= 640px, we'll get 1 event when crossing back to > 640px.
1169+
// This happens when the width changes from 640px to 704px.
1170+
const resizeWorkPromise = new Promise((resolve) => {
1171+
page.addEventListener("resize-work-complete", resolve, { once: true });
1172+
});
1173+
1174+
for (const width of widths) {
1175+
page.setWidth(width);
1176+
page.layout();
1177+
if (width === MATCH_MEDIA_QUERY_BREAKPOINT)
1178+
await resizeWorkPromise;
1179+
}
1180+
1181+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
1182+
}),
1183+
],
1184+
},
10801185
];

0 commit comments

Comments
 (0)