-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathanti-affinity.e2e.ts
255 lines (205 loc) · 10.2 KB
/
anti-affinity.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* 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 { clickRowAction, closeToast, expectRowVisible } from './utils'
test('can nav to Affinity from /', async ({ page }) => {
await page.goto('/')
await page.getByRole('table').getByRole('link', { name: 'mock-project' }).click()
await page.getByRole('link', { name: 'Affinity' }).click()
await expectRowVisible(page.getByRole('table'), {
name: 'romulus-remus',
type: 'anti-affinity',
Policy: 'fail',
instances: '2',
})
// click the anti-affinity group name cell to go to the view page
await page.getByRole('link', { name: 'romulus-remus' }).click()
await expect(page.getByRole('heading', { name: 'romulus-remus' })).toBeVisible()
await expect(page).toHaveURL('/projects/mock-project/affinity/romulus-remus')
await expect(page).toHaveTitle(
'romulus-remus / Affinity Groups / mock-project / Projects / Oxide Console'
)
// click through to instance
await page.getByRole('link', { name: 'db1' }).click()
await expect(page).toHaveURL('/projects/mock-project/instances/db1/settings')
})
test('can add a new anti-affinity group', async ({ page }) => {
await page.goto('/projects/mock-project/affinity')
await page.getByRole('link', { name: 'New group' }).click()
await expect(page).toHaveURL('/projects/mock-project/affinity-new')
await expect(page.getByRole('heading', { name: 'Add anti-affinity group' })).toBeVisible()
// fill out the form
await page.getByLabel('Name').fill('new-anti-affinity-group')
await page
.getByRole('textbox', { name: 'Description' })
.fill('this is a new anti-affinity group')
await page.getByRole('radio', { name: 'Fail' }).click()
// submit the form
await page.getByRole('button', { name: 'Add group' }).click()
// check that we are on the view page for the new anti-affinity group
await expect(page).toHaveURL('/projects/mock-project/affinity/new-anti-affinity-group')
// add a member to the new anti-affinity group
const addInstanceButton = page.getByRole('button', { name: 'Add instance' })
const addInstanceModal = page.getByRole('dialog', { name: 'Add instance to group' })
const instanceCombobox = page.getByRole('combobox', { name: 'Instance' })
const modalAddButton = page.getByRole('button', { name: 'Add to group' })
// open modal and pick instance
await addInstanceButton.click()
await expect(addInstanceModal).toBeVisible()
await instanceCombobox.fill('db1')
await page.getByRole('option', { name: 'db1' }).click()
await expect(instanceCombobox).toHaveValue('db1')
// close and reopen the modal to make sure the field clears
await page.getByRole('button', { name: 'Cancel' }).click()
await expect(addInstanceModal).toBeHidden()
await addInstanceButton.click()
await expect(instanceCombobox).toHaveValue('')
await page.getByRole('option', { name: 'db1' }).click()
// the submit button should be disabled
await expect(modalAddButton).toBeDisabled()
// go disable db1
await page.getByRole('button', { name: 'Cancel' }).click()
await page.getByRole('link', { name: 'Instances' }).click()
clickRowAction(page, 'db1', 'Stop')
await page.getByRole('button', { name: 'Confirm' }).click()
await expectRowVisible(page.getByRole('table'), {
name: 'db1',
state: expect.stringContaining('stopped'),
})
// go back to the anti-affinity group and add the instance
await page.getByRole('link', { name: 'Affinity' }).click()
await page.getByRole('link', { name: 'new-anti-affinity-group' }).click()
await addInstanceButton.click()
await expect(addInstanceModal).toBeVisible()
await instanceCombobox.fill('db1')
await page.getByRole('option', { name: 'db1' }).click()
await expect(instanceCombobox).toHaveValue('db1')
// the submit button should be enabled
await modalAddButton.click()
const cell = page.getByRole('cell', { name: 'db1' })
await expect(cell).toBeVisible()
// remove the instance from the group
await clickRowAction(page, 'db1', 'Remove from group')
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(cell).toBeHidden()
// expect empty message
await expect(page.getByText('No group members')).toBeVisible()
})
// edit an anti-affinity group from the view page
test('can edit an anti-affinity group', async ({ page }) => {
await page.goto('/projects/mock-project/affinity/romulus-remus')
await page.getByRole('button', { name: 'Anti-affinity group actions' }).click()
await page.getByRole('menuitem', { name: 'Edit' }).click()
// can see Add anti-affinity group header
await expect(
page.getByRole('heading', { name: 'Edit anti-affinity group' })
).toBeVisible()
// change the name to romulus-remus-2
await page.getByLabel('Name').fill('romulus-remus-2')
await page.getByRole('button', { name: 'Edit group' }).click()
await expect(page).toHaveURL('/projects/mock-project/affinity/romulus-remus-2')
await expect(page.getByRole('heading', { name: 'romulus-remus-2' })).toBeVisible()
})
// delete an anti-affinity group
test('can delete an anti-affinity group', async ({ page }) => {
await page.goto('/projects/mock-project/affinity')
await clickRowAction(page, 'set-osiris', 'Delete')
await expect(
page.getByRole('heading', { name: 'Delete anti-affinity group' })
).toBeVisible()
// confirm the deletion
await page.getByRole('button', { name: 'Confirm' }).click()
// check that we are back on the affinity page
await expect(page).toHaveURL('/projects/mock-project/affinity')
// can't see set-osiris in the table
await expect(page.getByRole('table').getByText('set-osiris')).toBeHidden()
// can create a new anti-affinity group with the same name
await page.getByRole('link', { name: 'New group' }).click()
await expect(page).toHaveURL('/projects/mock-project/affinity-new')
await expect(page.getByRole('heading', { name: 'Add anti-affinity group' })).toBeVisible()
await page.getByLabel('Name').fill('set-osiris')
await page
.getByRole('textbox', { name: 'Description' })
.fill('this is a new anti-affinity group')
await page.getByRole('radio', { name: 'Fail' }).click()
await page.getByRole('button', { name: 'Add group' }).click()
await expect(page).toHaveURL('/projects/mock-project/affinity/set-osiris')
await expect(page.getByRole('heading', { name: 'set-osiris' })).toBeVisible()
// click on Affinity in crumbs
await page.getByRole('link', { name: 'Affinity' }).first().click()
await expect(page).toHaveURL('/projects/mock-project/affinity')
// check that we can see the new anti-affinity group in the table
await expect(page.getByRole('table').getByText('set-osiris')).toBeVisible()
})
test('can delete anti-affinity group from detail page', async ({ page }) => {
await page.goto('/projects/mock-project/affinity/romulus-remus')
const modal = page.getByRole('dialog', { name: 'Confirm delete' })
await expect(modal).toBeHidden()
await page.getByLabel('Anti-affinity group actions').click()
await page.getByRole('menuitem', { name: 'Delete' }).click()
await expect(modal).toBeVisible()
await page.getByRole('button', { name: 'Confirm' }).click()
// modal closes, row is gone
await expect(modal).toBeHidden()
await closeToast(page)
await expect(page).toHaveURL('/projects/mock-project/affinity')
await expectRowVisible(page.getByRole('table'), { name: 'set-osiris' })
await expect(page.getByRole('cell', { name: 'romulus-remus' })).toBeHidden()
})
test('add and remove instance from group on instance settings', async ({ page }) => {
const groupName = 'oil-water'
// Go to instance settings
await page.goto('/projects/mock-project/instances/db1/settings')
// Locate the Anti-affinity card and the table within it
const groupsTable = page.getByRole('table', { name: 'Anti-affinity groups' })
const groupCell = groupsTable.getByRole('cell', { name: groupName })
// Ensure the group is not initially present
await expect(groupCell).toBeHidden()
// Make sure Add to group button is disabled
const addToGroupButton = page.getByRole('button', { name: 'Add to group' })
await expect(addToGroupButton).toBeDisabled()
// Stop the instance
await page.getByRole('button', { name: 'Stop' }).click()
const confirmStopModal = page.getByRole('dialog', { name: 'Confirm stop' })
await expect(confirmStopModal).toBeVisible()
await confirmStopModal.getByRole('button', { name: 'Confirm' }).click()
await expect(confirmStopModal).toBeHidden()
// Add instance to group
await addToGroupButton.click()
const modal = page.getByRole('dialog', { name: 'Add to anti-affinity group' })
await expect(modal).toBeVisible()
await modal.getByRole('combobox', { name: 'Anti-affinity group' }).click()
await page.getByRole('option', { name: groupName }).click()
await modal.getByRole('button', { name: 'Add to group' }).click()
await expect(modal).toBeHidden()
await closeToast(page)
// Group appears in table
await expect(groupCell).toBeVisible()
// Go to the group page
await page.getByRole('link', { name: groupName }).click()
await expect(page.getByRole('heading', { name: groupName })).toBeVisible()
const groupTable = page.getByRole('table')
// Instance is listed in the group members table
await expectRowVisible(groupTable, { name: 'db1' })
// Go back to instance settings
await page.getByRole('link', { name: 'db1' }).click()
// Remove instance from group using row action
await clickRowAction(page, groupName, 'Remove instance from group')
const confirmModal = page.getByRole('dialog', { name: 'Remove instance from group' })
await expect(confirmModal).toBeVisible()
await confirmModal.getByRole('button', { name: 'Confirm' }).click()
await expect(confirmModal).toBeHidden()
await closeToast(page)
// Group is no longer in table
await expect(groupCell).toBeHidden()
// Instance is gone from group members table
await page.goto('/projects/mock-project/affinity/oil-water')
await expect(page.getByRole('heading', { name: groupName })).toBeVisible()
await expect(page.getByRole('cell', { name: 'db1' })).toBeHidden()
await expect(page.getByText('No group members')).toBeVisible()
})