-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMachineUserFlow.test.ts
70 lines (60 loc) · 2.11 KB
/
MachineUserFlow.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { expect, test } from '@playwright/test'
import { createTestModel } from '@xstate/test'
import { setup } from 'xstate'
const MachineUserFlow = setup({
types: {} as {
events: |
{
type: 'User successfully fetched post'
} |
{
type: 'User unsuccessfully fetched post'
}
},
}).createMachine({
/** @xstate-layout N4IgpgJg5mDOIC5QFkCGBjAFgSwHZgFVYwAnAMQBsB7AdwDojSACAN21mwBdYmSqrOAYkYkmsAK7p0cWADNxFCgE8mssJyyQmAByqxOAbQAMAXUShdHTtiq5zIAB6IATAGZnAGhBLEADgBsdACsAL4hXmhYeITE5NT0IqzsXDx8AsKxTOK4ElIy8ooqahqYWpaGpvaWXDZ2SI4uzgCcwV4+CACMvs7BYeEguFQQcPaROPgilLRVejW29k4IRm2IALRGdE1bTQFuAOy+rh1uRh1hERjjMaRTCZlsVqn8nDNWtQuIACy+KwgBvf0xtFJvE6AAFPScJjsVTqTQQV5zOqgRb+ZxBX7-UKAy7A2K3cGQ2ElPBQJikPiiGGwTC0ZEgarWeb1VHOHpBJquPYY7yILrsvohIA */
id: 'MachineUserFlow',
states: {
'User visits root': {
on: {
'User successfully fetched post': 'Post is fetched',
'User unsuccessfully fetched post': 'Post fetching error is shown',
},
},
'Post is fetched': {
},
'Post fetching error is shown': {
},
},
initial: 'User visits root',
})
const modelUserFlow = createTestModel(MachineUserFlow)
const testPaths = modelUserFlow.getShortestPaths()
testPaths.forEach((path) => {
test(path.description, async ({ page }) => {
await path.test({
states: {
'User visits root': async () => {
await page.goto('/')
await expect(page.getByTestId('input')).toBeVisible()
},
'Post is fetched': async () => {
await expect(page.getByTestId('post')).toBeVisible()
},
'Post fetching error is shown': async () => {
await expect(page.getByTestId('error-message').first()).toBeVisible()
},
},
events: {
'User successfully fetched post': async () => {
await page.getByTestId('input').fill('1')
await page.getByTestId('submit').click()
},
'User unsuccessfully fetched post': async () => {
await page.getByTestId('input').fill('12345')
await page.getByTestId('submit').click()
},
},
})
})
})