forked from angular-architects/ngrx-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(devtools): do not throw if devtools are unavailable
- Loading branch information
1 parent
174eb09
commit 8c471a1
Showing
3 changed files
with
106 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,112 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { Action } from '@ngrx/store'; | ||
|
||
test('has title', async ({ page }) => { | ||
await page.goto(''); | ||
test.describe('DevTools', () => { | ||
test('DevTools do not throw an error when not available', async ({ | ||
page, | ||
}) => { | ||
await page.goto(''); | ||
const errors = []; | ||
page.on('pageerror', (error) => errors.push(error)); | ||
await page.getByRole('link', { name: 'DevTools' }).click(); | ||
await expect( | ||
page.getByRole('row', { name: 'Go for a walk' }) | ||
).toBeVisible(); | ||
}); | ||
|
||
await page.evaluate(() => { | ||
window['devtoolsSpy'] = []; | ||
test('DevTools are syncing state changes', async ({ page }) => { | ||
await page.goto(''); | ||
|
||
window['__REDUX_DEVTOOLS_EXTENSION__'] = { | ||
connect: () => { | ||
return { | ||
send: (data: Action) => { | ||
window['devtoolsSpy'].push(data); | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
await page.getByRole('link', { name: 'DevTools' }).click(); | ||
await page | ||
.getByRole('row', { name: 'Go for a walk' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
await page | ||
.getByRole('row', { name: 'Exercise' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
await page.evaluate(() => { | ||
window['devtoolsSpy'] = []; | ||
|
||
await expect( | ||
page.getByRole('region', { name: 'Go for a walk' }) | ||
).toBeVisible(); | ||
await expect(page.getByRole('region', { name: 'Exercise' })).toBeVisible(); | ||
window['__REDUX_DEVTOOLS_EXTENSION__'] = { | ||
connect: () => { | ||
return { | ||
send: (data: Action) => { | ||
window['devtoolsSpy'].push(data); | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
await page.getByRole('link', { name: 'DevTools' }).click(); | ||
await page | ||
.getByRole('row', { name: 'Go for a walk' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
await page | ||
.getByRole('row', { name: 'Exercise' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
|
||
await page | ||
.getByRole('row', { name: 'Go for a walk' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
await page | ||
.getByRole('row', { name: 'Exercise' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
await expect( | ||
page.getByRole('region', { name: 'Go for a walk' }) | ||
).toBeVisible(); | ||
await expect(page.getByRole('region', { name: 'Exercise' })).toBeVisible(); | ||
|
||
await expect( | ||
page.getByRole('region', { name: 'Go for a walk' }) | ||
).toBeHidden(); | ||
await expect(page.getByRole('region', { name: 'Exercise' })).toBeHidden(); | ||
await page | ||
.getByRole('row', { name: 'Go for a walk' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
await page | ||
.getByRole('row', { name: 'Exercise' }) | ||
.getByRole('checkbox') | ||
.click(); | ||
|
||
const devtoolsActions = await page.evaluate(() => window['devtoolsSpy']); | ||
await expect( | ||
page.getByRole('region', { name: 'Go for a walk' }) | ||
).toBeHidden(); | ||
await expect(page.getByRole('region', { name: 'Exercise' })).toBeHidden(); | ||
|
||
expect(devtoolsActions).toEqual([ | ||
{ | ||
type: 'add todo', | ||
}, | ||
{ | ||
type: 'select todo 1', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'select todo 4', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'select todo 1', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'select todo 4', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
]); | ||
const devtoolsActions = await page.evaluate(() => window['devtoolsSpy']); | ||
|
||
expect(devtoolsActions).toEqual([ | ||
{ | ||
type: 'add todo', | ||
}, | ||
{ | ||
type: 'select todo 1', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'select todo 4', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'select todo 1', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'select todo 4', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
{ | ||
type: 'Store Update', | ||
}, | ||
]); | ||
}); | ||
}); |
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