Skip to content

Commit 350a70c

Browse files
committed
Add responsive design benchmark back
1 parent 477964e commit 350a70c

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

resources/default-tests.mjs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,4 +940,109 @@ export const DefaultSuites = freezeSuites([
940940
}),
941941
],
942942
},
943+
{
944+
name: "Responsive-Design",
945+
url: "experimental/responsive-design/dist/index.html",
946+
tags: ["responsive-design", "webcomponents", "experimental"],
947+
disabled: true,
948+
type: "async",
949+
async prepare(page) {
950+
await page.waitForElement("cooking-app");
951+
},
952+
tests: [
953+
new BenchmarkTestStep("LoadChatAndExpandRecipes", async (page) => {
954+
const resumePreviousChatBtn = page.querySelector("#resume-previous-chat-btn", ["cooking-app", "chat-window"]);
955+
resumePreviousChatBtn.click();
956+
page.layout();
957+
958+
const nextRestaurantBtn = page.querySelector("#next-restaurant-btn", ["cooking-app", "information-window"]);
959+
const restaurantCards = page.querySelectorAll("restaurant-card", ["cooking-app", "information-window"]);
960+
const numOfRestaurantCards = restaurantCards.length - 1;
961+
for (let i = 0; i < numOfRestaurantCards; i++) {
962+
nextRestaurantBtn.click();
963+
page.layout();
964+
}
965+
966+
const showMoreBtn = page.querySelectorAll(".show-more-btn", ["cooking-app", "main-content", "recipe-grid"]);
967+
for (const btn of showMoreBtn) {
968+
btn.click();
969+
page.layout();
970+
}
971+
}),
972+
new BenchmarkTestStep("ReduceWidthIn5Steps", async (page) => {
973+
const widths = [768, 704, 640, 560, 480];
974+
const MATCH_MEDIA_QUERY_BREAKPOINT = 640;
975+
976+
// The matchMedia query is "(max-width: 640px)"
977+
// Starting from a width > 640px, we'll only get 1 event when crossing to <= 640px
978+
// This happens when the width changes from 704px to 640px
979+
const resizeWorkPromise = new Promise((resolve) => {
980+
page.addEventListener("resize-work-complete", resolve, { once: true });
981+
});
982+
983+
for (const width of widths) {
984+
page.setWidth(width);
985+
page.layout();
986+
if (width === MATCH_MEDIA_QUERY_BREAKPOINT)
987+
await resizeWorkPromise;
988+
}
989+
990+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
991+
}),
992+
new BenchmarkTestStep("ScrollToChatAndSendMessages", async (page) => {
993+
const cvWorkComplete = new Promise((resolve) => {
994+
page.addEventListener("video-grid-content-visibility-complete", resolve, { once: true });
995+
});
996+
997+
const nextItemBtn = page.querySelector("#next-item-carousel-btn", ["cooking-app", "main-content", "recipe-carousel"]);
998+
const recipeCarouselItems = page.querySelectorAll(".carousel-item", ["cooking-app", "main-content", "recipe-carousel"]);
999+
const numOfCarouselItems = recipeCarouselItems.length - 3;
1000+
for (let i = 0; i < numOfCarouselItems; i++) {
1001+
nextItemBtn.click();
1002+
page.layout();
1003+
}
1004+
1005+
// Collapse recipes
1006+
const showMoreBtnCollapse = page.querySelectorAll(".show-more-btn", ["cooking-app", "main-content", "recipe-grid"]);
1007+
for (const btn of showMoreBtnCollapse) {
1008+
btn.click();
1009+
page.layout();
1010+
}
1011+
1012+
const chatWindow = page.querySelector("#chat-window", ["cooking-app", "chat-window"]);
1013+
chatWindow.scrollIntoView({ behavior: "instant" });
1014+
page.layout();
1015+
1016+
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."];
1017+
const chatInput = page.querySelector("#chat-input", ["cooking-app", "chat-window"]);
1018+
for (const message of messagesToBeSent) {
1019+
chatInput.setValue(message);
1020+
chatInput.dispatchEvent("input");
1021+
chatInput.enter("keydown");
1022+
page.layout();
1023+
}
1024+
await cvWorkComplete;
1025+
}),
1026+
new BenchmarkTestStep("IncreaseWidthIn5Steps", async (page) => {
1027+
const widths = [560, 640, 704, 768, 800];
1028+
const MATCH_MEDIA_QUERY_BREAKPOINT = 704;
1029+
1030+
// The matchMedia query is "(max-width: 640px)"
1031+
// Starting from a width <= 640px, we'll get 1 event when crossing back to > 640px.
1032+
// This happens when the width changes from 640px to 704px.
1033+
const resizeWorkPromise = new Promise((resolve) => {
1034+
page.addEventListener("resize-work-complete", resolve, { once: true });
1035+
});
1036+
1037+
for (const width of widths) {
1038+
page.setWidth(width);
1039+
page.layout();
1040+
if (width === MATCH_MEDIA_QUERY_BREAKPOINT)
1041+
await resizeWorkPromise;
1042+
}
1043+
1044+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
1045+
}),
1046+
],
1047+
},
9431048
]);

0 commit comments

Comments
 (0)