Skip to content

Commit

Permalink
Merge pull request #2929 from target/services-playwright-3
Browse files Browse the repository at this point in the history
Converting remaining service tests from Cypress to Playwright
  • Loading branch information
mastercactapus authored Apr 17, 2023
2 parents 4211f71 + c10c68c commit dac6da1
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 260 deletions.
219 changes: 213 additions & 6 deletions test/integration/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,142 @@ test('Service', async ({ page, isMobile }) => {

await expect(page.getByRole('heading', { name, level: 1 })).toBeVisible()

// Create a label and value for the service
const key = `${c.word({ length: 4 })}/${c.word({ length: 3 })}`
const value = c.word({ length: 8 })
// Navigate to the heartbeat monitors
await page.getByRole('link', { name: 'Heartbeat Monitors' }).click()

// Cancel out of create
if (isMobile) {
await page.getByRole('button', { name: 'Create Heartbeat Monitor' }).click()
} else {
await page.getByTestId('create-monitor').click()
}
await page.getByRole('button', { name: 'Cancel' }).click()

// Create a heartbeat monitor using invalid name
let timeoutMinutes = (Math.trunc(Math.random() * 10) + 5).toString()
const invalidHMName = 'a'
if (isMobile) {
await page.getByRole('button', { name: 'Create Heartbeat Monitor' }).click()
} else {
await page.getByTestId('create-monitor').click()
}
await page.getByLabel('Name').fill(invalidHMName)
await page.getByLabel('Timeout (minutes)').fill(timeoutMinutes)
await page.getByRole('button', { name: 'Submit' }).click()

// Should see error message
await expect(page.getByText('Must be at least 2 characters')).toBeVisible()

// Use valid name instead
let hmName = c.word({ length: 5 }) + ' Monitor'
await page.getByLabel('Name').fill(hmName)
await page.getByRole('button', { name: 'Retry' }).click()

// Should see the heartbeat monitor created
await expect(page.getByText(hmName)).toBeVisible()
await expect(page.getByText(timeoutMinutes)).toBeVisible()

// Cancel out of edit
await page.getByRole('button', { name: 'Other Actions' }).click()
await page.getByRole('menuitem', { name: 'Edit' }).click()
await page.getByRole('button', { name: 'Cancel' }).click()

// Edit the heartbeat monitor
hmName = c.word({ length: 5 })
timeoutMinutes = (Math.trunc(Math.random() * 10) + 5).toString()
await page.getByRole('button', { name: 'Other Actions' }).click()
await page.getByRole('menuitem', { name: 'Edit' }).click()
await page.getByLabel('Name').fill(hmName)
await page.getByLabel('Timeout (minutes)').fill(timeoutMinutes)
await page.getByRole('button', { name: 'Submit' }).click()

// Should see the edited heartbeat monitor
await expect(page.getByText(hmName)).toBeVisible()
await expect(page.getByText(timeoutMinutes)).toBeVisible()

// Cancel out of delete
await page.getByRole('button', { name: 'Other Actions' }).click()
await page.getByRole('menuitem', { name: 'Delete' }).click()
await page.getByRole('button', { name: 'Cancel' }).click()

// Delete the heartbeat monitor
await page.getByRole('button', { name: 'Other Actions' }).click()
await page.getByRole('menuitem', { name: 'Delete' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
await page.getByText('No heartbeat monitors exist for this service.').click()

// Return to the service
if (isMobile) {
await page.getByRole('button', { name: 'Back' }).click()
} else {
await page.getByRole('link', { name, exact: true }).click()
}

// Go to the alerts page
await page
.getByRole('link', {
name: 'Alerts Manage alerts specific to this service',
})
.click()

// Create an alert
const summary = c.sentence({ words: 3 })
const details = c.word({ length: 10 })
await page.getByRole('button', { name: 'Create Alert' }).click()
await page.getByLabel('Alert Summary').fill(summary)
await page.getByLabel('Details (optional)').fill(details)
await page.getByRole('button', { name: 'Next' }).click()
if (isMobile) {
await expect(page.getByText('Selected Services (1)' + name)).toBeVisible()
} else {
await expect(
page.getByRole('dialog', { name: 'Create New Alert' }).getByText(name),
).toBeVisible()
}
await page.getByRole('button', { name: 'Submit' }).click()
await page.getByRole('button', { name: 'Done' }).click()

// Alert should be unacknowledged
await expect(
page.getByRole('link', { name: ' UNACKNOWLEDGED ' + summary }),
).toBeVisible()

// Acknowledge the alert
await page.getByRole('button', { name: 'Acknowledge All' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(
page.getByRole('link', { name: ' ACKNOWLEDGED ' + summary }),
).toBeVisible()
await expect(
page.getByRole('link', { name: ' UNACKNOWLEDGED ' + summary }),
).toBeHidden()

// Close the alert
await page.getByRole('button', { name: 'Close All' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(page.getByText('No results')).toBeVisible()

// Return to the service
if (isMobile) {
await page.getByRole('button', { name: 'Back' }).click()
} else {
await page.getByRole('link', { name, exact: true }).click()
}

// Navigate to the metrics
await page.getByRole('link', { name: 'Metrics' }).click()

// Return to the service
if (isMobile) {
await page.getByRole('button', { name: 'Back' }).click()
} else {
await page.getByRole('link', { name, exact: true }).click()
}

// Create a label for the service
await page.getByRole('link', { name: 'Labels' }).click()
const key = `${c.word({ length: 4 })}/${c.word({ length: 3 })}`
let value = c.word({ length: 8 })
if (isMobile) {
await page.getByRole('button', { name: 'Add' }).click()
} else {
Expand All @@ -60,6 +192,37 @@ test('Service', async ({ page, isMobile }) => {
await expect(page.getByText(key)).toBeVisible()
await expect(page.getByText(value)).toBeVisible()

// Edit the label, change the value, confirm new value is visible
value = c.word({ length: 8 })
await page.getByRole('button', { name: 'Other Actions' }).click()
await page.getByRole('menuitem', { name: 'Edit' }).click()
await page.getByLabel('Value', { exact: true }).fill(value)
await page.click('[role=dialog] button[type=submit]')

await expect(page.getByText(key)).toBeVisible()
await expect(page.getByText(value)).toBeVisible()

// Delete the label, confirm it's no longer visible
await page.getByRole('button', { name: 'Other Actions' }).click()
await page.getByRole('menuitem', { name: 'Delete' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(
page.getByText('No labels exist for this service.'),
).toBeVisible()

// Create a second the label and value for the service
if (isMobile) {
await page.getByRole('button', { name: 'Add' }).click()
} else {
await page.getByTestId('create-label').click()
}

await page.getByLabel('Key', { exact: true }).fill(key)
await page.getByText('Create "' + key + '"').click()
await page.getByLabel('Value', { exact: true }).fill(value)
await page.click('[role=dialog] button[type=submit]')

// Return to the service
if (isMobile) {
await page.getByRole('button', { name: 'Back' }).click()
Expand All @@ -78,6 +241,35 @@ test('Service', async ({ page, isMobile }) => {
await page.getByLabel('Name').fill(intKey)
await page.getByRole('button', { name: 'Submit' }).click()

await expect(page.getByText(intKey)).toBeVisible()
await expect(page.getByText('Generic API')).toBeVisible()

// Create a second integration key with a different type
const grafanaKey = c.word({ length: 5 }) + ' Key'
if (isMobile) {
await page.getByRole('button', { name: 'Create Integration Key' }).click()
} else {
await page.getByTestId('create-key').click()
}
await page.getByLabel('Name').fill(grafanaKey)
await page.getByRole('button', { name: 'Type Generic API' }).click()
await page.getByRole('option', { name: 'Grafana' }).click()
await page.getByRole('button', { name: 'Submit' }).click()

await expect(page.getByText(grafanaKey)).toBeVisible()
await expect(page.getByText('Grafana')).toBeVisible()

// Delete the second integration key, confirm it is no longer visible
await page
.getByRole('listitem')
.filter({ hasText: grafanaKey })
.getByRole('button')
.click()
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(page.getByText(intKey, { exact: true })).toBeVisible()
await expect(page.getByText(grafanaKey, { exact: true })).toBeHidden()

// Make another service
const diffName = 'pw-service ' + c.name()
const diffDescription = c.sentence()
Expand Down Expand Up @@ -124,8 +316,10 @@ test('Service', async ({ page, isMobile }) => {
await expect(page.getByLabel('Select Label Value')).toBeDisabled()

// Filter by label key
await page.getByLabel('Select Label Key').click()
await page.getByRole('option', { name: key }).getByRole('listitem').click()
// await page.getByLabel('Select Label Key').click()
await page.getByRole('combobox', { name: 'Select Label Key' }).fill(key)
await page.getByText(key).click()
// await page.getByRole('option', { name: key }).getByRole('listitem').click()
await page.getByRole('button', { name: 'Done' }).click()

// Check if filtered, should have found both services
Expand Down Expand Up @@ -168,7 +362,20 @@ test('Service', async ({ page, isMobile }) => {
page.getByRole('link', { name: name + ' ' + description }),
).toBeVisible()

// We should be on the services list page, so let's try searching for the service we just created. We add a space to the beginning of the name to ensure we are searching for the full name and not a substring.
// We should be on the services list page, so let's search for service by label
await page.fill('input[name=search]', key + '=' + value)
await page.getByPlaceholder('Search').press('Enter')

// We should see the service on the page
await expect(page.getByText(name, { exact: true })).toBeVisible()

// Search for service without a label
await page.fill('input[name=search]', key + '!=' + value)

// We should not see the service on the page
await expect(page.getByText(name, { exact: true })).toBeHidden()

// Try searching for the service by its name. We add a space to the beginning of the name to ensure we are searching for the full name and not a substring.
await page.fill('input[name=search]', ' ' + name + ' ')

// We should find the service in the list, lets go to it
Expand Down
Loading

0 comments on commit dac6da1

Please sign in to comment.