-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* e2e tests - api helpers - trigger, webhook * [WIP] E2E tests - triggers, webhooks * tests - webhooks - WIP * E2E test for webhooks - complete * CreateTriggerPage * Complete trigger test * Selectors updated, Cleanup * selectors updated after data-test, Fixes after eslint
- Loading branch information
1 parent
905361d
commit 3894a79
Showing
13 changed files
with
424 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import config from '../config'; | ||
|
||
export default { | ||
'trigger-deployment-creation-name-test-name': { | ||
name: 'temp-trigger-depl-cr-name-test-name', | ||
namespace: config.namespace, | ||
resource: 'deployment', | ||
event: 'created', | ||
action: 'run', | ||
execution: 'test', | ||
concurrencyPolicy: '', | ||
testSelector: { | ||
name: 'postman-executor-smoke', | ||
namespace: 'testkube', | ||
}, | ||
resourceSelector: { | ||
name: 'non-existant-resource', | ||
namespace: 'namespace-name', | ||
}, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import config from '../config'; | ||
|
||
export default { | ||
'temp-wh-on-test-start': { | ||
name: 'example-webhook3', | ||
namespace: config.namespace, | ||
events: ['start-test'], | ||
selector: { | ||
asdf: 'asdf', // request: 'asdf=asdf' | ||
bbb: 'ccc', | ||
}, | ||
uri: 'http://webhook-url.example.com', | ||
}, | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type {Page} from '@playwright/test'; | ||
|
||
import type {TriggerData} from '../types'; | ||
|
||
export class CreateTriggerPage { | ||
public readonly page: Page; | ||
|
||
public constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
public async createTrigger(triggerData: Partial<TriggerData>): Promise<void> { | ||
await this.setName(triggerData.name); | ||
await this.setResource(triggerData.resource); | ||
await this.setResourceSelector(triggerData.resourceSelector); | ||
await this.setTriggerEvent(triggerData.event); | ||
await this.clickNextButton(); | ||
await this.setTriggerAction(triggerData.action, triggerData.execution); | ||
await this.setTestSelector(triggerData.testSelector); | ||
await this.clickCreateButton(); | ||
} | ||
|
||
async setName(triggerName: string) { | ||
await this.page.locator(`xpath=//input[@data-test="triggers-add-modal-name"]`).fill(triggerName); | ||
} | ||
|
||
async setResource(resourceType: string) { | ||
await this.page.click( | ||
`xpath=//div[@data-test="triggers-add-modal-condition-resource"]//div[contains(@class,"control-input-content")]` | ||
); | ||
await this.page.click(`xpath=//div[contains(@class,"ant-select-item-option") and @title="${resourceType}"]`); // TODO: data-test (for rc-virtual-list) | ||
} | ||
|
||
async setResourceSelector(resourceSelector: {name: string; namespace: string}) { | ||
if (resourceSelector.name) { | ||
const resourceSelectorString = `${resourceSelector.namespace}/${resourceSelector.name}`; | ||
await this.page.click( | ||
`xpath=//div[@data-test="triggers-add-modal-condition-selector-switch"]//div[@title="BY NAME"]` | ||
); | ||
await this.page | ||
.locator(`xpath=//input[@id="add-trigger-form_resourceNameSelector"]`) | ||
.fill(resourceSelectorString); | ||
} | ||
} | ||
|
||
async setTriggerEvent(triggerEvent: string) { | ||
await this.page.click(`xpath=//input[@id="add-trigger-form_event"]`); | ||
await this.page.click( | ||
`xpath=//div[@class="rc-virtual-list"]//div[contains(@class,"item-option") and @title="${triggerEvent}"]` | ||
); // TODO: data-test (for rc-virtual-list) | ||
} | ||
|
||
async clickNextButton() { | ||
await this.page.click(`xpath=//button[@data-test="triggers-add-modal-next:first"]`); | ||
} | ||
|
||
async setTriggerAction(action: string, execution: string) { | ||
await this.page.click(`xpath=//input[@id="add-trigger-form_action"]`); | ||
await this.page.click( | ||
`xpath=//div[@class="rc-virtual-list"]//div[contains(@class,"item-option") and @title="${action} ${execution}"]` | ||
); | ||
} | ||
|
||
async setTestSelector(testSelector: {name: string}) { | ||
if (testSelector.name) { | ||
await this.page.click(`xpath=//div[@data-test="triggers-add-modal-action-switch"]//div[@title="BY NAME"]`); | ||
await this.page.click(`xpath=//input[@id="add-trigger-form_testNameSelector"]`); | ||
await this.page.click( | ||
`xpath=//div[@class="rc-virtual-list"]//div[contains(@class,"option-content")]//span[text()="${testSelector.name}"]` | ||
); | ||
} | ||
} | ||
|
||
async clickCreateButton() { | ||
await this.page.click(`xpath=//button[@data-test="webhooks-add-modal-next:second"]`); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type {Page} from '@playwright/test'; | ||
|
||
import type {WebhookData} from '../types'; | ||
|
||
export class CreateWebhookPage { | ||
public readonly page: Page; | ||
|
||
public constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
public async createWebhook(webhookData: WebhookData): Promise<void> { | ||
await this.setBasicInput(webhookData.name, 'name'); | ||
await this.selectResourceIdentifier(webhookData.selector); | ||
await this.selectTriggeredEvents(webhookData.events); | ||
|
||
await this.clickNextButton(); | ||
await this.setBasicInput(webhookData.uri, 'uri'); | ||
await this.clickCreateWebhookButton(); | ||
} | ||
|
||
async setBasicInput(value: string | number, inputName: string): Promise<void> { | ||
await this.page.locator(`[id="webhook-creation-modal_${inputName}"]`).fill(`${value}`); | ||
} | ||
|
||
async clickNextButton() { | ||
await this.page.click('//button[@data-test="webhooks-add-modal-next:first"]'); | ||
} | ||
|
||
async clickCreateWebhookButton() { | ||
await this.page.click('//button[@data-test="webhooks-add-modal-next:second"]'); | ||
} | ||
|
||
async selectResourceIdentifier(resources: Record<string, string>): Promise<void> { | ||
const multiSelectElementSelector = 'xpath=//div[@id="webhook-creation-modal_selector"]'; | ||
const multiSelectInputSelector = 'xpath=//div[@id="webhook-creation-modal_selector"]//input'; | ||
|
||
await this.selectLabels(resources, multiSelectElementSelector, multiSelectInputSelector); | ||
} | ||
|
||
async selectTriggeredEvents(events: string[]): Promise<void> { | ||
const multiSelectElementSelector = 'xpath=//div[@id="webhook-creation-modal_events"]'; | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for (const eventName of events) { | ||
await this.selectMultiSelectValue(eventName, multiSelectElementSelector); // eslint-disable-line no-await-in-loop | ||
} | ||
} | ||
|
||
async selectMultiSelectValue(value: string, multiSelectElement: string): Promise<void> { | ||
await this.page.click(multiSelectElement); | ||
await this.page.locator(`${multiSelectElement}//input`).fill(value); | ||
|
||
await this.page.click(`${multiSelectElement}//div[contains(@class,"option") and text()="${value}"]`); | ||
} | ||
|
||
async selectLabels( | ||
labels: Record<string, string>, | ||
labelSelectElement: string, | ||
labelSelectInputElement: string | ||
): Promise<void> { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const [name, value] of Object.entries(labels)) { | ||
await this.selectCreateLabel(`${name}:${value}`, labelSelectElement, labelSelectInputElement); // eslint-disable-line no-await-in-loop | ||
} | ||
} | ||
|
||
async selectCreateLabel(value: string, multiSelectElement: string, multiSelectInputSelector: string): Promise<void> { | ||
await this.page.click(multiSelectElement); | ||
await this.page.locator(multiSelectInputSelector).fill(value); | ||
|
||
await this.page.keyboard.press('Enter'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type {Page} from '@playwright/test'; | ||
|
||
export class TriggersPage { | ||
public readonly page: Page; | ||
|
||
public constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
public async openCreateTriggerDialog(): Promise<void> { | ||
await this.page.click('xpath=//button[@data-test="triggers-add-button"]'); | ||
} | ||
|
||
public async openTriggerDetails(triggerName: string): Promise<void> { | ||
await this.page.click(`xpath=//div[@data-test="triggers-list-item:${triggerName}"]`); | ||
} | ||
} |
Oops, something went wrong.