Skip to content

Commit 28fb4f0

Browse files
authored
Merge pull request #20310 from calixteman/bug1990762
[Editor] Show the comments in the sidebar in the chronological order,newest to oldest (bug 1990762)
2 parents 101fa62 + f854770 commit 28fb4f0

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

test/integration/comment_spec.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ const switchToHighlight = switchToEditor.bind(null, "Highlight");
3333
const switchToStamp = switchToEditor.bind(null, "Stamp");
3434
const switchToComment = switchToEditor.bind(null, "Comment");
3535

36+
const highlightSpan = async (page, pageIndex, text) => {
37+
const rect = await getSpanRectFromText(page, pageIndex, text);
38+
const x = rect.x + rect.width / 2;
39+
const y = rect.y + rect.height / 2;
40+
await page.mouse.click(x, y, { count: 2, delay: 100 });
41+
await page.waitForSelector(getEditorSelector(0));
42+
};
43+
3644
describe("Comment", () => {
3745
describe("Comment edit dialog must be visible in ltr", () => {
3846
let pages;
@@ -417,5 +425,48 @@ describe("Comment", () => {
417425
})
418426
);
419427
});
428+
429+
it("must check that comments are in chronological order", async () => {
430+
await Promise.all(
431+
pages.map(async ([browserName, page]) => {
432+
await switchToComment(page);
433+
434+
const checkDates = async () => {
435+
const dates = await page.evaluate(() =>
436+
Array.from(
437+
document.querySelectorAll(
438+
`#editorCommentParamsToolbar ul > li > time`
439+
)
440+
).map(time => new Date(time.getAttribute("datetime")))
441+
);
442+
for (let i = 0; i < dates.length - 1; i++) {
443+
expect(dates[i])
444+
.withContext(`In ${browserName}`)
445+
.toBeGreaterThanOrEqual(dates[i + 1]);
446+
}
447+
};
448+
await checkDates();
449+
450+
// Add an highlight with a comment and check the order again.
451+
await switchToHighlight(page);
452+
await highlightSpan(page, 1, "Languages");
453+
const editorSelector = getEditorSelector(9);
454+
await page.waitForSelector(editorSelector);
455+
const commentButtonSelector = `${editorSelector} button.comment`;
456+
await waitAndClick(page, commentButtonSelector);
457+
458+
const textInputSelector = "#commentManagerTextInput";
459+
await page.waitForSelector(textInputSelector, {
460+
visible: true,
461+
});
462+
await page.type(textInputSelector, "Hello world!");
463+
await page.click("#commentManagerSaveButton");
464+
await waitForSerialized(page, 1);
465+
466+
await switchToComment(page);
467+
await checkDates();
468+
})
469+
);
470+
});
420471
});
421472
});

web/comment_manager.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,18 @@ class CommentSidebar {
612612
}
613613

614614
#sortComments(a, b) {
615+
const dateA = PDFDateString.toDateObject(
616+
a.modificationDate || a.creationDate
617+
);
618+
const dateB = PDFDateString.toDateObject(
619+
b.modificationDate || b.creationDate
620+
);
621+
if (dateA !== dateB) {
622+
if (dateA !== null && dateB !== null) {
623+
return dateB - dateA;
624+
}
625+
return dateA !== null ? -1 : 1;
626+
}
615627
if (a.pageIndex !== b.pageIndex) {
616628
return a.pageIndex - b.pageIndex;
617629
}

0 commit comments

Comments
 (0)