-
Notifications
You must be signed in to change notification settings - Fork 11
/
project-create.e2e.ts
70 lines (60 loc) · 2.69 KB
/
project-create.e2e.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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { expect, test } from '@playwright/test'
import { expectVisible } from './utils'
test.describe('Project create', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/projects-new')
})
test('contains expected elements', async ({ page }) => {
await expectVisible(page, [
'role=heading[name*="Create project"]', // TODO: standardize capitalization
'role=textbox[name="Name"]',
'role=textbox[name="Description"]',
'role=button[name="Create project"]',
])
})
test('navigates back to project instances page on success', async ({ page }) => {
await page.fill('role=textbox[name="Name"]', 'mock-project-2')
await page.click('role=button[name="Create project"]')
await expect(page).toHaveURL('/projects/mock-project-2/instances')
})
test('shows field-level validation error and does not POST', async ({ page }) => {
const input = page.getByRole('textbox', { name: 'Name' })
await input.pressSequentially('no sPoNgEbOb_CaSe or spaces')
await expect(input).toHaveValue('no-spongebob-case-or-spaces')
await input.fill('no-ending-dash-')
// submit to trigger validation
await page.getByRole('button', { name: 'Create project' }).click()
await expect(
page.getByText('Must end with a letter or number', { exact: true }).nth(0)
).toBeVisible()
})
test('shows form-level error for known server error', async ({ page }) => {
await page.fill('role=textbox[name="Name"]', 'mock-project') // already exists
await page.click('role=button[name="Create project"]')
await expectVisible(page, ['text="Project name already exists"'])
})
// TODO: figure these out
// it('shows message for known error code in global code map', async () => {
// overrideOnce('post', projectsUrl, 403, { error_code: 'Forbidden' })
// renderAppAt(formUrl)
// await enterName('mock-project-2')
// clickByRole('button', 'Create project')
// await screen.findByText('Action not authorized')
// expect(window.location.pathname).toEqual(formUrl) // don't nav away
// })
// it('shows generic message for unknown server error', async () => {
// overrideOnce('post', projectsUrl, 400, { error_code: 'UnknownCode' })
// renderAppAt(formUrl)
// await enterName('mock-project-2')
// clickByRole('button', 'Create project')
// await screen.findByText('Unknown error from server')
// expect(window.location.pathname).toEqual(formUrl) // don't nav away
// })
})