File size: 4,603 Bytes
1e92f2d |
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 |
import { test, expect } from '@playwright/test'
import { dropdownSelect, pageAction, userSessionFile } from './lib'
import Chance from 'chance'
const c = new Chance()
test.describe.configure({ mode: 'parallel' })
test.use({ storageState: userSessionFile })
// test create, edit, verify, and delete of an EMAIL contact method
test('EMAIL contact method', async ({ page, browser, request }) => {
const name = 'pw-email ' + c.name()
const email = 'pw-email-' + c.email()
await page.goto('./profile')
await pageAction(page, 'Create Contact Method', 'Create Method')
await page.fill('input[name=name]', name)
// ensure disclaimer is shown for voice call
await dropdownSelect(page, 'Destination Type', 'Voice Call')
await expect(
page.locator('span', { hasText: 'test-disclaimer-text' }),
).toBeVisible()
await dropdownSelect(page, 'Destination Type', 'Email')
await page.fill('input[name=email_address]', email)
await page.click('[role=dialog] button[type=submit]')
const mail = await browser.newPage({
baseURL: 'http://localhost:6125',
viewport: { width: 800, height: 600 },
})
await mail.goto('./')
await mail.locator(`a:has-text("To: ${email}")`).click()
const code = await mail
.frameLocator('#preview-html')
.locator('.invite-code')
.textContent()
if (!code) {
throw new Error('No code found')
}
// validate links, grab message ID from url
const url = mail.url()
const id = url.match(/view\/(.+)/)?.[1]
// make GET request to validate link
const res = await request.get(
`http://localhost:6125/api/v1/message/${id}/link-check`,
)
await expect(res.ok()).toBeTruthy()
const body = await res.json()
body.Links.forEach(
(l: { URL: string; StatusCode: number; Status: string }) => {
expect(l, 'Link-Check: ' + l.URL).toHaveProperty('StatusCode', 200)
},
)
expect(body).toHaveProperty('Errors', 0)
await mail.getByTitle('Delete message').click()
await mail.close()
await page.fill('input[name=code]', code)
await page.click('[role=dialog] button[type=submit]')
await expect(page.locator('[role=dialog]')).toBeHidden()
// edit name and enable status updates
const updatedName = 'updated name ' + c.name()
await page.click(`li:has-text("${email}") [aria-label="Other Actions"]`)
await page.getByRole('menuitem', { name: 'Edit' }).click()
await page.fill('input[name=name]', updatedName)
await page.click('input[name=enableStatusUpdates]')
await page.click('[role=dialog] button[type=submit]')
// We need to move the mouse, otherwise it will keep it's position over the submit button and activate the speed dial...
await page.mouse.move(0, 0)
await expect(page.locator('[role=dialog]')).toBeHidden()
// open edit dialog to verify name change and status updates are enabled
await page.click(`li:has-text("${email}") [aria-label="Other Actions"]`)
await page.getByRole('menuitem', { name: 'Edit' }).click()
await expect(page.locator('input[name=name]')).toHaveValue(updatedName)
await expect(page.locator('input[name=enableStatusUpdates]')).toBeChecked()
await page.click('[role=dialog] button[type=submit]')
await page.mouse.move(0, 0)
await expect(page.locator('[role=dialog]')).toBeHidden()
// verify deleting a notification rule (immediate by default)
await page.click(
`li:has-text("Immediately notify me via Email at ${email}") button`,
)
// click confirm
await page.getByRole('button', { name: 'Confirm' }).click()
await expect(
page.locator('li', {
hasText: `Immediately notify me via Email at ${email}`,
}),
).toBeHidden()
// verify adding a notification rule (delayed)
await pageAction(page, 'Add Notification Rule', 'Add Rule')
await dropdownSelect(page, 'Contact Method', updatedName)
await page.fill('input[name=delayMinutes]', '5')
await page.click('[role=dialog] button[type=submit]')
await page.mouse.move(0, 0)
await expect(page.locator('[role=dialog]')).toBeHidden()
await expect(
page.locator('li', {
hasText: `After 5 minutes notify me via Email at ${email}`,
}),
).toBeVisible()
await page.click(`li:has-text("${email}") [aria-label="Other Actions"]`)
await page.getByRole('menuitem', { name: 'Delete' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
await page.mouse.move(0, 0)
await expect(page.locator('[role=dialog]')).toBeHidden()
await page
.locator('.MuiCard-root', {
has: page.locator('div > div > h2', { hasText: 'Contact Methods' }),
})
.locator('li', { hasText: email })
.isHidden()
})
|