Skip to content

Commit

Permalink
print display and add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
koudaiii committed Sep 18, 2024
1 parent 8020ee7 commit 584d437
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const timeAgoLabels = {
const languageLabel = languageLabels[currentLang] || 'last updated on';

// Display update info
updateInfo.innerHTML = informationIcon + `${languageLabel}: <a href="${englishUrl}" target="_blank" class="${textColorClass}">${englishDate.toLocaleDateString(currentLang)}</a>`;
updateInfo.innerHTML = informationIcon + `${languageLabel}: <a href="${englishUrl}" target="_blank" class="${textColorClass}">${englishDate.toLocaleDateString(currentLang)}${timeAgoStr}</a>`;
}
updateClass();
const observer = new MutationObserver(updateClass);
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/content.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ describe('learn.microsoft.com Update Checker E2E Test', () => {
return textElement !== null;
}, testCase.textElementSelector);
expect(hasTextColorClass).toBe(true);

// get text content. e.g. '2023/12/21 英語版の更新日: 2023/12/21 (271日前に更新)'
const textContentStr = await page.evaluate(() => {
const visibilityHiddenVisualDiffElement = document.querySelector('li.visibility-hidden-visual-diff');
return visibilityHiddenVisualDiffElement ? visibilityHiddenVisualDiffElement.innerText : null;
});
console.log("textContentStr:", textContentStr);

let defaultUpdatePattern = /(years|days|hours|minutes) ago|(just now)/;
if (testCase.url.includes('ja-jp')) {
defaultUpdatePattern = /(年|日|時間|分)前に更新|(今更新されたばかり)/;
}
let match = textContentStr.match(defaultUpdatePattern);
console.log("match:", match);
expect(!!match).toBe(true);
});

test(`should not run script on en-us pages with ${testCase.themeColor} theme in ${testCase.prefersColorScheme} mode`, async () => {
Expand Down

0 comments on commit 584d437

Please sign in to comment.