|
| 1 | +/* Copyright 2025 Mozilla Foundation |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import { |
| 17 | + closePages, |
| 18 | + getEditorSelector, |
| 19 | + getRect, |
| 20 | + getSpanRectFromText, |
| 21 | + loadAndWait, |
| 22 | + scrollIntoView, |
| 23 | + switchToEditor, |
| 24 | + waitAndClick, |
| 25 | +} from "./test_utils.mjs"; |
| 26 | + |
| 27 | +const switchToHighlight = switchToEditor.bind(null, "Highlight"); |
| 28 | + |
| 29 | +describe("Comment", () => { |
| 30 | + describe("Comment edit dialog must be visible in ltr", () => { |
| 31 | + let pages; |
| 32 | + |
| 33 | + beforeEach(async () => { |
| 34 | + pages = await loadAndWait( |
| 35 | + "bug1989304.pdf", |
| 36 | + ".annotationEditorLayer", |
| 37 | + "page-width", |
| 38 | + null, |
| 39 | + { enableComment: true } |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + afterEach(async () => { |
| 44 | + await closePages(pages); |
| 45 | + }); |
| 46 | + |
| 47 | + it("must set the comment dialog in the viewport (LTR)", async () => { |
| 48 | + await Promise.all( |
| 49 | + pages.map(async ([browserName, page]) => { |
| 50 | + await switchToHighlight(page); |
| 51 | + |
| 52 | + await scrollIntoView(page, ".textLayer span:last-of-type"); |
| 53 | + const rect = await getSpanRectFromText(page, 1, "..."); |
| 54 | + const x = rect.x + rect.width / 2; |
| 55 | + const y = rect.y + rect.height / 2; |
| 56 | + // Here and elsewhere, we add a small delay between press and release |
| 57 | + // to make sure that a pointerup event is triggered after |
| 58 | + // selectionchange. |
| 59 | + // It works with a value of 1ms, but we use 100ms to be sure. |
| 60 | + await page.mouse.click(x, y, { count: 2, delay: 100 }); |
| 61 | + await page.waitForSelector(getEditorSelector(0)); |
| 62 | + |
| 63 | + const commentButtonSelector = `${getEditorSelector(0)} button.comment`; |
| 64 | + await waitAndClick(page, commentButtonSelector); |
| 65 | + |
| 66 | + await page.waitForSelector("#commentManagerDialog", { |
| 67 | + visible: true, |
| 68 | + }); |
| 69 | + const dialogRect = await getRect(page, "#commentManagerDialog"); |
| 70 | + const viewport = await page.evaluate(() => ({ |
| 71 | + width: document.documentElement.clientWidth, |
| 72 | + height: document.documentElement.clientHeight, |
| 73 | + })); |
| 74 | + expect(dialogRect.x + dialogRect.width) |
| 75 | + .withContext(`In ${browserName}`) |
| 76 | + .toBeLessThanOrEqual(viewport.width); |
| 77 | + expect(dialogRect.y + dialogRect.height) |
| 78 | + .withContext(`In ${browserName}`) |
| 79 | + .toBeLessThanOrEqual(viewport.height); |
| 80 | + }) |
| 81 | + ); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + describe("Comment edit dialog must be visible in rtl", () => { |
| 86 | + let pages; |
| 87 | + |
| 88 | + beforeEach(async () => { |
| 89 | + pages = await loadAndWait( |
| 90 | + "bug1989304.pdf", |
| 91 | + ".annotationEditorLayer", |
| 92 | + "page-width", |
| 93 | + null, |
| 94 | + { enableComment: true, localeProperties: "ar" } |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + afterEach(async () => { |
| 99 | + await closePages(pages); |
| 100 | + }); |
| 101 | + |
| 102 | + it("must set the comment dialog in the viewport (RTL)", async () => { |
| 103 | + await Promise.all( |
| 104 | + pages.map(async ([browserName, page]) => { |
| 105 | + await switchToHighlight(page); |
| 106 | + |
| 107 | + await scrollIntoView(page, ".textLayer span:nth-of-type(4)"); |
| 108 | + const rect = await getSpanRectFromText(page, 1, "World"); |
| 109 | + const x = rect.x + rect.width / 2; |
| 110 | + const y = rect.y + rect.height / 2; |
| 111 | + await page.mouse.click(x, y, { count: 2, delay: 100 }); |
| 112 | + await page.waitForSelector(getEditorSelector(0)); |
| 113 | + |
| 114 | + const commentButtonSelector = `${getEditorSelector(0)} button.comment`; |
| 115 | + await waitAndClick(page, commentButtonSelector); |
| 116 | + |
| 117 | + await page.waitForSelector("#commentManagerDialog", { |
| 118 | + visible: true, |
| 119 | + }); |
| 120 | + const dialogRect = await getRect(page, "#commentManagerDialog"); |
| 121 | + const viewport = await page.evaluate(() => ({ |
| 122 | + height: document.documentElement.clientHeight, |
| 123 | + })); |
| 124 | + expect(dialogRect.x + dialogRect.width) |
| 125 | + .withContext(`In ${browserName}`) |
| 126 | + .toBeGreaterThanOrEqual(0); |
| 127 | + expect(dialogRect.y + dialogRect.height) |
| 128 | + .withContext(`In ${browserName}`) |
| 129 | + .toBeLessThanOrEqual(viewport.height); |
| 130 | + }) |
| 131 | + ); |
| 132 | + }); |
| 133 | + }); |
| 134 | +}); |
0 commit comments