-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix playwright tests with better mock separation
- Loading branch information
1 parent
ab46df1
commit 11894a1
Showing
17 changed files
with
139 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createDataStates } from '../../shared/js/ui/views/tests/generate-data.mjs'; | ||
import { readFileSync } from 'node:fs'; | ||
|
||
const google = JSON.parse(readFileSync('./schema/__fixtures__/request-data-google.json', 'utf8')); | ||
const cnn = JSON.parse(readFileSync('./schema/__fixtures__/request-data-cnn.json', 'utf8')); | ||
|
||
export const testDataStates = createDataStates(google, cnn); |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import toggleReportScreen from '../../../../schema/__fixtures__/toggle-report-screen.json'; | ||
import { createDataStates } from '../../ui/views/tests/generate-data.mjs'; | ||
import google from '../../../../schema/__fixtures__/request-data-google.json'; | ||
import cnn from '../../../../schema/__fixtures__/request-data-cnn.json'; | ||
import { mockAndroidApis, mockBrowserApis, sharedMockDataProvider, webkitMockApis, windowsMockApis } from './communication-mocks.mjs'; | ||
|
||
/** | ||
* @param {import('../../ui/platform-features.mjs').Platform} platform | ||
*/ | ||
export function installBrowserMocks(platform) { | ||
console.log('installing...'); | ||
if (window.__playwright) { | ||
console.log('installing... NOE'); | ||
return () => console.log('❌ mocked already there'); | ||
} | ||
if (platform.name === 'windows') { | ||
windowsMockApis(); | ||
} else if (platform.name === 'ios' || platform.name === 'macos') { | ||
webkitMockApis({ | ||
messages: { | ||
privacyDashboardGetToggleReportOptions: toggleReportScreen, | ||
}, | ||
}); | ||
} else if (platform.name === 'android') { | ||
mockAndroidApis({ | ||
messages: { | ||
getToggleReportOptions: toggleReportScreen, | ||
}, | ||
}); | ||
} else if (platform.name === 'browser') { | ||
mockBrowserApis(); | ||
} | ||
|
||
const testDataStates = createDataStates(/** @type {any} */ (google), /** @type {any} */ (cnn)); | ||
const stateFromUrl = new URLSearchParams(window.location.search).get('state'); | ||
|
||
let mock; | ||
if (stateFromUrl && stateFromUrl in testDataStates) { | ||
mock = testDataStates[stateFromUrl]; | ||
} else { | ||
mock = testDataStates.protectionsOn_blocked; | ||
console.warn('state not found, falling back to default. state: ', 'protectionsOn_blocked', stateFromUrl); | ||
} | ||
|
||
console.groupCollapsed(`${platform.name} open for more Dashboard States`); | ||
const urls = Object.keys(testDataStates).map((key) => { | ||
const clone = new URL(location.href); | ||
clone.searchParams.set('state', key); | ||
return clone.href; | ||
}); | ||
for (const url of urls) { | ||
console.log(url); | ||
} | ||
console.groupEnd(); | ||
|
||
const messages = {}; | ||
|
||
if (platform.name === 'browser') { | ||
messages.getBurnOptions = mock.toBurnOptions(); | ||
messages.getPrivacyDashboardData = mock.toExtensionDashboardData(); | ||
messages.getToggleReportOptions = toggleReportScreen; | ||
messages.getBreakageFormOptions = toggleReportScreen; | ||
} | ||
if (platform.name === 'windows') { | ||
messages.windowsViewModel = mock.toWindowsViewModel(); | ||
messages.GetToggleReportOptions = mock.toWindowsToggleReportOptions(toggleReportScreen); | ||
} | ||
|
||
return () => | ||
sharedMockDataProvider({ | ||
state: mock, | ||
platform, | ||
messages, | ||
}); | ||
} |
Oops, something went wrong.