-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
751e53c
commit de2e195
Showing
22 changed files
with
884 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,80 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
import { escapeRegex, getRandomId } from '../utils'; | ||
import { expect } from '@playwright/test'; | ||
import { RulePage, RulesPage } from '../pages'; | ||
import { getRandomId } from '../utils'; | ||
import { test } from './_fixture'; | ||
|
||
// We have no easy way to identity rules. Therefore run them sequentially. | ||
test.describe.configure({ mode: 'serial' }); | ||
|
||
test.beforeEach(async ({ page, appName }) => { | ||
await page.goto(`/app/${appName}/rules`); | ||
test.beforeEach(async ({ appName, rulesPage }) => { | ||
await rulesPage.goto(appName); | ||
}); | ||
|
||
test('create rule', async ({ page }) => { | ||
const ruleName = await createRandomRule(page); | ||
const ruleCard = page.locator('div.card', { hasText: escapeRegex(ruleName) }); | ||
test('create rule', async ({ rulesPage, rulePage }) => { | ||
const ruleName = await createRandomRule(rulesPage, rulePage); | ||
const ruleCard = await rulesPage.getRule(ruleName); | ||
|
||
await expect(ruleCard).toBeVisible(); | ||
await expect(ruleCard.root).toBeVisible(); | ||
}); | ||
|
||
test('delete rule', async ({ dropdown, page }) => { | ||
const ruleName = await createRandomRule(page); | ||
const ruleCard = page.locator('div.card', { hasText: escapeRegex(ruleName) }); | ||
test('delete rule', async ({ rulesPage, rulePage }) => { | ||
const ruleName = await createRandomRule(rulesPage, rulePage); | ||
const ruleCard = await rulesPage.getRule(ruleName); | ||
|
||
await ruleCard.getByLabel('Options').click(); | ||
const dropdown = await ruleCard.openOptionsDropdown(); | ||
await dropdown.delete(); | ||
|
||
await expect(ruleCard).not.toBeVisible(); | ||
await expect(ruleCard.root).toBeVisible(); | ||
}); | ||
|
||
test('disable rule', async ({ dropdown, page }) => { | ||
const ruleName = await createRandomRule(page); | ||
const ruleCard = page.locator('div.card', { hasText: escapeRegex(ruleName) }); | ||
test('disable rule', async ({ rulePage, rulesPage }) => { | ||
const ruleName = await createRandomRule(rulesPage, rulePage); | ||
const ruleCard = await rulesPage.getRule(ruleName); | ||
|
||
await ruleCard.getByLabel('Options').click(); | ||
const dropdown = await ruleCard.openOptionsDropdown(); | ||
await dropdown.action('Disable'); | ||
|
||
await expect(ruleCard.locator('sqx-toggle .toggle-container')).toHaveAttribute('data-state', 'unchecked'); | ||
await expect(ruleCard.root.locator('sqx-toggle .toggle-container')).toHaveAttribute('data-state', 'unchecked'); | ||
}); | ||
|
||
test('enable rule', async ({ dropdown, page }) => { | ||
const ruleName = await createRandomRule(page); | ||
const ruleCard = page.locator('div.card', { hasText: escapeRegex(ruleName) }); | ||
test('enable rule', async ({ rulePage, rulesPage }) => { | ||
const ruleName = await createRandomRule(rulesPage, rulePage); | ||
const ruleCard = await rulesPage.getRule(ruleName); | ||
|
||
await ruleCard.getByLabel('Options').click(); | ||
await dropdown.action('Disable'); | ||
const dropdown1 = await ruleCard.openOptionsDropdown(); | ||
await dropdown1.action('Disable'); | ||
|
||
await expect(ruleCard.locator('sqx-toggle .toggle-container')).toHaveAttribute('data-state', 'unchecked'); | ||
await expect(ruleCard.root.locator('sqx-toggle .toggle-container')).toHaveAttribute('data-state', 'unchecked'); | ||
|
||
await ruleCard.getByLabel('Options').click(); | ||
await dropdown.action('Enable'); | ||
const dropdown2 = await ruleCard.openOptionsDropdown(); | ||
await dropdown2.action('Enable'); | ||
|
||
await expect(ruleCard.locator('sqx-toggle .toggle-container')).toHaveAttribute('data-state', 'checked'); | ||
await expect(ruleCard.root.locator('sqx-toggle .toggle-container')).toHaveAttribute('data-state', 'checked'); | ||
}); | ||
|
||
test('edit rule', async ({ dropdown, page }) => { | ||
const ruleName = await createRandomRule(page); | ||
const ruleCard = page.locator('div.card', { hasText: escapeRegex(ruleName) }); | ||
test('edit rule', async ({ page, rulePage, rulesPage }) => { | ||
const ruleName = await createRandomRule(rulesPage, rulePage); | ||
const ruleCard = await rulesPage.getRule(ruleName); | ||
|
||
await ruleCard.getByLabel('Options').click(); | ||
const dropdown = await ruleCard.openOptionsDropdown(); | ||
await dropdown.action('Edit'); | ||
|
||
await expect(page.getByText('Enabled')).toBeVisible(); | ||
}); | ||
|
||
async function createRandomRule(page: Page) { | ||
async function createRandomRule(rulesPage: RulesPage, rulePage: RulePage) { | ||
const ruleName = `rule-${getRandomId()}`; | ||
|
||
await page.getByRole('link', { name: /New Rule/ }).click(); | ||
|
||
// Define rule action | ||
await page.getByText('Content changed').click(); | ||
|
||
// Define rule trigger | ||
await page.getByText('Webhook').click(); | ||
// This is the only required field, so we have to enter some text. | ||
await page.locator('sqx-formattable-input').first().getByRole('textbox').fill('https:/squidex.io'); | ||
|
||
await page.getByRole('button', { name: 'Save' }).click(); | ||
|
||
await page.getByText('Enabled').waitFor({ state: 'visible' }); | ||
await rulesPage.addRule(); | ||
|
||
// Go back | ||
await page.getByLabel('Back').click(); | ||
await rulePage.selectContentChangedTrigger(); | ||
await rulePage.selectWebhookAction(); | ||
await rulePage.save(); | ||
await rulePage.back(); | ||
|
||
// Define rule name. | ||
await page.locator('div.card', { hasText: /Unnamed Rule/ }).getByRole('heading').first().dblclick(); | ||
await page.locator('form').getByRole('textbox').fill(ruleName); | ||
await page.locator('form').getByLabel('Save').click(); | ||
const rename = await rulesPage.renameRule(/Unnamed Rule/); | ||
await rename.enterName(ruleName); | ||
await rename.save(); | ||
|
||
return ruleName; | ||
} |
Oops, something went wrong.