Skip to content

Commit

Permalink
Merge pull request #17049 from calixteman/fix_stamp_tests
Browse files Browse the repository at this point in the history
Remove the timeouts from the stampEditor integration tests
  • Loading branch information
calixteman authored Sep 29, 2023
2 parents 12ca22b + b8c118d commit 7d7a7a4
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions test/integration/stamp_editor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,33 @@
const {
closePages,
getEditorDimensions,
getEditorSelector,
loadAndWait,
serializeBitmapDimensions,
waitForAnnotationEditorLayer,
waitForStorageEntries,
waitForSelectedEditor,
} = require("./test_utils.js");
const path = require("path");
const fs = require("fs");

const selectAll = async page => {
await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForFunction(
() => !document.querySelector(".stampEditor:not(.selectedEditor)")
);
};

const clearAll = async page => {
await selectAll(page);
await page.keyboard.down("Control");
await page.keyboard.press("Backspace");
await page.keyboard.up("Control");
await waitForStorageEntries(page, 0);
};

describe("Stamp Editor", () => {
describe("Basic operations", () => {
let pages;
Expand Down Expand Up @@ -50,8 +70,7 @@ describe("Stamp Editor", () => {
await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.png")}`
);

await page.waitForTimeout(300);
await page.waitForSelector(`${getEditorSelector(0)} .altText`);

const { width } = await getEditorDimensions(page, 0);

Expand All @@ -63,12 +82,7 @@ describe("Stamp Editor", () => {
expect(bitmap.width).toEqual(512);
expect(bitmap.height).toEqual(543);

await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(10);

await page.keyboard.press("Backspace");
await clearAll(page);
})
);
});
Expand All @@ -86,8 +100,7 @@ describe("Stamp Editor", () => {
await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.svg")}`
);

await page.waitForTimeout(300);
await page.waitForSelector(`${getEditorSelector(1)} .altText`);

const { width } = await getEditorDimensions(page, 1);

Expand All @@ -102,12 +115,7 @@ describe("Stamp Editor", () => {
expect(bitmap.width).toEqual(Math.round(242 * ratio));
expect(bitmap.height).toEqual(Math.round(80 * ratio));

await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(10);

await page.keyboard.press("Backspace");
await clearAll(page);
})
);
});
Expand Down Expand Up @@ -137,40 +145,34 @@ describe("Stamp Editor", () => {

for (let i = 0; i < 4; i++) {
if (i !== 0) {
await page.keyboard.down("Control");
await page.keyboard.press("a");
await page.keyboard.up("Control");
await page.waitForTimeout(10);
await page.keyboard.press("Backspace");
await page.waitForTimeout(10);
await clearAll(page);
}

await page.click("#editorStampAddImage");
await page.waitForTimeout(10);
const input = await page.$("#stampEditorFileInput");
await input.uploadFile(
`${path.join(__dirname, "../images/firefox_logo.png")}`
);

await page.waitForTimeout(300);
await page.waitForSelector(`${getEditorSelector(i)} .altText`);

for (let j = 0; j < 4; j++) {
await page.keyboard.press("Escape");
await page.waitForFunction(
`getComputedStyle(document.querySelector(".resizers")).display === "none"`
await page.waitForSelector(
`${getEditorSelector(i)} .resizers.hidden`
);

const promise = waitForAnnotationEditorLayer(page);
await page.evaluate(() => {
window.PDFViewerApplication.rotatePages(90);
});
await promise;

await page.focus(".stampEditor");
await waitForSelectedEditor(page, getEditorSelector(i));

await page.waitForFunction(
`getComputedStyle(document.querySelector(".resizers")).display === "block"`
await page.waitForSelector(
`${getEditorSelector(i)} .resizers:not(.hidden)`
);
await page.waitForTimeout(10);

const [name, cursor] = await page.evaluate(() => {
const { x, y } = document
Expand Down

0 comments on commit 7d7a7a4

Please sign in to comment.