Skip to content

Commit

Permalink
Fix for differences across different browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
mikikiv committed Dec 27, 2023
1 parent 67bfd47 commit 08c63ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"start": "next start",
"lint": "next lint",
"test": "playwright test",
"test-dev": "playwright test --ui",
"vercel-build": "next build",
"build:extension": "extensionReqs/build.sh"
},
Expand Down
45 changes: 24 additions & 21 deletions tests/aliasedEmail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ test.describe("aliased emails", () => {
expect(await page.textContent("#copyEmail")).toEqual(aliasedEmail)
await page.click("#copyEmail")
const savedLocalStorage = (await page.context().storageState()).origins[0]
expect(savedLocalStorage.localStorage.length).toBe(5)
const expectedStorage: TotalLocalStorage = [
{
name: "selectedAlias",
value: '"SugarFire"',
value: "SugarFire",
},
{
name: "email",
value: `"${email}"`,
value: email,
},
{
name: "copyHistory",
Expand All @@ -34,35 +35,37 @@ test.describe("aliased emails", () => {
},
{
name: "timestampEnabled",
value: "false",
value: false,
},
]

for (let index = 0; index < expectedStorage.length; index++) {
if (expectedStorage[index].name === "copyHistory") {
const expectedStorageMap = Object.fromEntries(
expectedStorage.map((item) => [item.name, item.value])
)
const savedLocalStorageMap = Object.fromEntries(
savedLocalStorage.localStorage.map((item) => [
item.name,
JSON.parse(item.value),
])
)

for (const key in expectedStorageMap) {
if (key === "copyHistory") {
//@ts-ignore
const expectedCopyHistory: CopyHistoryType =
expectedStorage[index].value
const storedCopyHistory: CopyHistoryType = JSON.parse(
savedLocalStorage.localStorage[index].value
)
expect(storedCopyHistory.type).toBe(expectedCopyHistory.type)
expect(storedCopyHistory.id).toBe(expectedCopyHistory.id)
expect(storedCopyHistory.timestamp).not.toBeNaN()
} else if (expectedStorage[index].name === "aliases") {
const expectedCopyHistory: CopyHistoryType = expectedStorageMap[key]
const storedCopyHistory: CopyHistoryType = savedLocalStorageMap[key]
expect(storedCopyHistory).toMatchObject(expectedCopyHistory)
} else if (key === "aliases") {
//@ts-ignore
const expectedAliases: AliasType[] = expectedStorage[index].value
const storedAliases: AliasType[] = JSON.parse(
savedLocalStorage.localStorage[index].value
)
const expectedAliases: AliasType[] = expectedStorageMap[key]
const storedAliases: AliasType[] = savedLocalStorageMap[key]
expect(storedAliases).toMatchObject(expectedAliases)
} else {
expect(JSON.stringify(savedLocalStorage.localStorage[index])).toMatch(
JSON.stringify(expectedStorage[index])
expect(JSON.stringify(savedLocalStorageMap[key])).toMatch(
JSON.stringify(expectedStorageMap[key])
)
}
}

await expect(page.getByTestId(aliasedEmail)).toBeVisible()
})
})

0 comments on commit 08c63ae

Please sign in to comment.