-
Notifications
You must be signed in to change notification settings - Fork 1
fix(sonar): clear complexity findings and add locale screenshot drift checks #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ const DEFAULT_SCREENSHOT_DIR = path.join('dist', 'qa', 'screenshots'); | |
| const SCREENSHOT_DIR = resolveOutputDirectory(process.env.UI_SCREENSHOT_DIR); | ||
| const PORT = Number(process.env.UI_SCREENSHOT_PORT || 4173); | ||
| const DEFAULT_SCREENSHOT_NAME = `ui-${process.platform}-${process.arch}.png`; | ||
| const DEFAULT_LOCALE = 'en'; | ||
| const SUPPORTED_LOCALES = ['en', 'es', 'fr', 'de']; | ||
| const FIXED_MTIME = 1700000000000; | ||
|
|
||
| function loadSecretScannerHelpers() { | ||
|
|
@@ -332,6 +334,12 @@ const MOCK_VISIBLE_FILE_COUNT_WITH_SECRET_FILTER = countMockFiles(MOCK_FILTERED_ | |
| const SCREENSHOT_NAME = sanitizeScreenshotName(process.env.UI_SCREENSHOT_NAME); | ||
| const SCREENSHOT_BASE_NAME = path.parse(SCREENSHOT_NAME).name; | ||
| const SCREENSHOT_PATH = resolveOutputPath(SCREENSHOT_NAME); | ||
| const LOCALE_SCREENSHOT_PATHS = Object.fromEntries( | ||
| SUPPORTED_LOCALES.map((locale) => [ | ||
| locale, | ||
| resolveOutputPath(`${SCREENSHOT_BASE_NAME}-locale-${locale}.png`), | ||
| ]) | ||
| ); | ||
|
|
||
| const SCREENSHOTS = { | ||
| configDefault: SCREENSHOT_PATH, | ||
|
|
@@ -343,6 +351,7 @@ const SCREENSHOTS = { | |
|
|
||
| const UI_SELECTORS = { | ||
| appRoot: '#app', | ||
| languageSelector: '#language-selector', | ||
| configTab: '[data-tab="config"]', | ||
| sourceTab: '[data-tab="source"]', | ||
| processedTabActive: '[data-tab="processed"][aria-selected="true"]', | ||
|
|
@@ -368,6 +377,7 @@ async function setupMockElectronApi(page) { | |
| sessionStorage.clear(); | ||
| localStorage.setItem('rootPath', mockRootPath); | ||
| localStorage.setItem('configContent', mockConfig); | ||
| localStorage.setItem('app.locale', 'en'); | ||
|
|
||
| const cloneTree = (treeItems) => JSON.parse(JSON.stringify(treeItems)); | ||
| const delay = (durationMs) => | ||
|
|
@@ -488,6 +498,44 @@ async function setupMockElectronApi(page) { | |
| ); | ||
| } | ||
|
|
||
| async function setLocaleAndWait(page, locale) { | ||
| await page.selectOption(UI_SELECTORS.languageSelector, locale); | ||
| await page.waitForFunction( | ||
| ({ languageSelector, expectedLocale }) => { | ||
| const localeSelector = document.querySelector(languageSelector); | ||
| if (!(localeSelector instanceof HTMLSelectElement)) { | ||
| return false; | ||
| } | ||
|
|
||
| return ( | ||
| localeSelector.value === expectedLocale && | ||
| localStorage.getItem('app.locale') === expectedLocale | ||
| ); | ||
| }, | ||
| { languageSelector: UI_SELECTORS.languageSelector, expectedLocale: locale } | ||
| ); | ||
| } | ||
|
|
||
| async function captureLocaleScreenshots(page) { | ||
| await runStep('Wait for language selector', async () => { | ||
| await page.waitForSelector(UI_SELECTORS.languageSelector, { timeout: 10000 }); | ||
| }); | ||
|
|
||
| for (const locale of SUPPORTED_LOCALES) { | ||
| await runStep(`Switch locale to ${locale}`, async () => { | ||
| await setLocaleAndWait(page, locale); | ||
| }); | ||
|
|
||
| await runStep(`Capture locale screenshot (${locale})`, async () => { | ||
| await page.screenshot({ path: LOCALE_SCREENSHOT_PATHS[locale], fullPage: true }); | ||
| }); | ||
| } | ||
|
|
||
| await runStep(`Reset locale to ${DEFAULT_LOCALE}`, async () => { | ||
| await setLocaleAndWait(page, DEFAULT_LOCALE); | ||
| }); | ||
| } | ||
|
|
||
| async function captureAppStateScreenshots(page) { | ||
| await runStep('Disable animations for stable screenshots', async () => { | ||
| await page.addStyleTag({ | ||
|
|
@@ -514,6 +562,8 @@ async function captureAppStateScreenshots(page) { | |
| await page.screenshot({ path: SCREENSHOTS.configDefault, fullPage: true }); | ||
| }); | ||
|
|
||
| await captureLocaleScreenshots(page); | ||
|
|
||
| await runStep('Switch to source tab', async () => { | ||
| await page.click(UI_SELECTORS.sourceTab); | ||
| }); | ||
|
|
@@ -703,7 +753,16 @@ async function captureScreenshot() { | |
| await page.goto(`http://127.0.0.1:${PORT}/index.html`, { waitUntil: 'networkidle' }); | ||
| }); | ||
| await captureAppStateScreenshots(page); | ||
| Object.values(SCREENSHOTS).forEach((screenshotPath) => { | ||
| const screenshotPaths = [ | ||
| SCREENSHOTS.configDefault, | ||
| ...SUPPORTED_LOCALES.map((locale) => LOCALE_SCREENSHOT_PATHS[locale]), | ||
| SCREENSHOTS.sourceTab, | ||
| SCREENSHOTS.sourceSelected, | ||
| SCREENSHOTS.sourceSelectedResized, | ||
| SCREENSHOTS.processedTab, | ||
| ]; | ||
|
Comment on lines
+756
to
+763
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of manually listing all screenshot paths, you can use const screenshotPaths = Object.values(SCREENSHOTS); |
||
|
|
||
| screenshotPaths.forEach((screenshotPath) => { | ||
| console.log(`UI screenshot captured: ${screenshotPath}`); | ||
| }); | ||
| } finally { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.