mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
6.5 KiB
201 lines
6.5 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
|
import BasePage from '../../Base';
|
||
|
import { DashboardPage } from '..';
|
||
|
import { ToolbarPage } from '../common/Toolbar';
|
||
2 years ago
|
|
||
|
export class WebhookFormPage extends BasePage {
|
||
|
readonly dashboard: DashboardPage;
|
||
2 years ago
|
readonly toolbar: ToolbarPage;
|
||
2 years ago
|
readonly addNewButton: Locator;
|
||
|
readonly saveButton: Locator;
|
||
|
readonly testButton: Locator;
|
||
|
|
||
|
constructor(dashboard: DashboardPage) {
|
||
|
super(dashboard.rootPage);
|
||
|
this.dashboard = dashboard;
|
||
2 years ago
|
this.toolbar = dashboard.grid.toolbar;
|
||
2 years ago
|
this.addNewButton = this.dashboard.get().locator('.nc-btn-create-webhook');
|
||
2 years ago
|
this.saveButton = this.get().locator('button:has-text("Save")');
|
||
|
this.testButton = this.get().locator('button:has-text("Test Webhook")');
|
||
|
}
|
||
|
|
||
|
get() {
|
||
2 years ago
|
return this.dashboard.get().locator(`.nc-drawer-webhook-body`);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
// todo: Removing opening webhook drawer logic as it belongs to `Toolbar` page
|
||
2 years ago
|
async create({ title, event, url = 'http://localhost:9090/hook' }: { title: string; event: string; url?: string }) {
|
||
2 years ago
|
await this.toolbar.clickActions();
|
||
2 years ago
|
await this.toolbar.actions.click('Webhooks');
|
||
2 years ago
|
|
||
2 years ago
|
await this.addNewButton.click();
|
||
2 years ago
|
await this.get().waitFor({ state: 'visible' });
|
||
2 years ago
|
|
||
|
await this.configureHeader({
|
||
2 years ago
|
key: 'Content-Type',
|
||
|
value: 'application/json',
|
||
2 years ago
|
});
|
||
|
await this.configureWebhook({ title, event, url });
|
||
2 years ago
|
await this.save();
|
||
|
await this.close();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async configureWebhook({ title, event, url }: { title?: string; event?: string; url?: string }) {
|
||
2 years ago
|
if (title) {
|
||
|
await this.get().locator(`.nc-text-field-hook-title`).fill(title);
|
||
|
}
|
||
|
if (event) {
|
||
|
await this.get().locator(`.nc-text-field-hook-event`).click();
|
||
|
const modal = this.rootPage.locator(`.nc-dropdown-webhook-event`);
|
||
|
await modal.locator(`.ant-select-item:has-text("${event}")`).click();
|
||
|
}
|
||
|
if (url) {
|
||
|
await this.get().locator(`.nc-text-field-hook-url-path`).fill(url);
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
async addCondition({
|
||
|
column,
|
||
|
operator,
|
||
|
value,
|
||
|
save,
|
||
|
}: {
|
||
|
column: string;
|
||
|
operator: string;
|
||
|
value: string;
|
||
|
save: boolean;
|
||
|
}) {
|
||
2 years ago
|
await this.get().locator(`.nc-check-box-hook-condition`).click();
|
||
|
const modal = await this.get().locator(`.menu-filter-dropdown`).last();
|
||
2 years ago
|
|
||
|
// todo: All delays are for api calls that filter does, which rerenders
|
||
|
await this.rootPage.waitForTimeout(1000);
|
||
|
|
||
2 years ago
|
await modal.locator(`button:has-text("Add Filter")`).click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.rootPage.waitForTimeout(1500);
|
||
|
|
||
2 years ago
|
await modal.locator('.nc-filter-field-select').click();
|
||
|
const modalField = await this.dashboard.rootPage.locator('.nc-dropdown-toolbar-field-list:visible');
|
||
2 years ago
|
await modalField.locator(`.ant-select-item:has-text("${column}")`).click();
|
||
|
|
||
2 years ago
|
await this.rootPage.waitForTimeout(1500);
|
||
|
|
||
2 years ago
|
await modal.locator('.nc-filter-operation-select').click();
|
||
|
const modalOp = await this.dashboard.rootPage.locator('.nc-dropdown-filter-comp-op:visible');
|
||
2 years ago
|
await modalOp.locator(`.ant-select-item:has-text("${operator}")`).click();
|
||
|
|
||
2 years ago
|
await this.rootPage.waitForTimeout(1500);
|
||
|
|
||
2 years ago
|
if (operator != 'is null' && operator != 'is not null') {
|
||
|
await modal.locator('input.nc-filter-value-select').fill(value);
|
||
2 years ago
|
}
|
||
|
|
||
|
if (save) {
|
||
|
await this.save();
|
||
|
await this.close();
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async deleteCondition(p: { save: boolean }) {
|
||
2 years ago
|
await this.get().locator(`.nc-filter-item-remove-btn`).click();
|
||
2 years ago
|
if (p.save) {
|
||
|
await this.save();
|
||
|
await this.close();
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
async save() {
|
||
2 years ago
|
const saveAction = this.saveButton.click();
|
||
|
await this.waitForResponse({
|
||
|
uiAction: saveAction,
|
||
2 years ago
|
requestUrlPathToMatch: '/hooks',
|
||
|
httpMethodsToMatch: ['POST', 'PATCH'],
|
||
|
});
|
||
|
await this.verifyToast({ message: 'Webhook details updated successfully' });
|
||
2 years ago
|
}
|
||
|
|
||
|
async test() {
|
||
|
await this.testButton.click();
|
||
2 years ago
|
await this.verifyToast({ message: 'Webhook tested successfully' });
|
||
2 years ago
|
}
|
||
|
|
||
|
async delete({ index }: { index: number }) {
|
||
2 years ago
|
await this.toolbar.clickActions();
|
||
2 years ago
|
await this.toolbar.actions.click('Webhooks');
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator(`.nc-hook-delete-icon`).nth(index).click();
|
||
2 years ago
|
await this.verifyToast({ message: 'Hook deleted successfully' });
|
||
2 years ago
|
|
||
|
// click escape to close the drawer
|
||
2 years ago
|
await this.get().press('Escape');
|
||
2 years ago
|
}
|
||
|
|
||
|
async close() {
|
||
|
// type esc key
|
||
2 years ago
|
await this.get().press('Escape');
|
||
2 years ago
|
}
|
||
|
|
||
|
async open({ index }: { index: number }) {
|
||
2 years ago
|
await this.toolbar.clickActions();
|
||
2 years ago
|
await this.toolbar.actions.click('Webhooks');
|
||
2 years ago
|
await this.dashboard.get().locator(`.nc-hook`).nth(index).click();
|
||
|
}
|
||
|
|
||
2 years ago
|
async openForm({ index }: { index: number }) {
|
||
|
await this.dashboard.get().locator(`.nc-hook`).nth(index).click();
|
||
|
}
|
||
|
|
||
|
async click({ index }: { index: number }) {
|
||
|
await this.dashboard.get().locator(`.nc-hook`).nth(index).click();
|
||
|
}
|
||
|
|
||
2 years ago
|
async configureHeader({ key, value }: { key: string; value: string }) {
|
||
|
// hardcode "Content-type: application/json"
|
||
|
await this.get().locator(`.ant-tabs-tab-btn:has-text("Headers")`).click();
|
||
|
|
||
2 years ago
|
await this.get().locator('.nc-input-hook-header-key >> input').fill(key);
|
||
2 years ago
|
await this.rootPage.locator(`.ant-select-item:has-text("${key}")`).click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator('.nc-input-hook-header-value').type(value);
|
||
|
await this.get().press('Enter');
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator('.nc-hook-header-tab-checkbox').locator('input.ant-checkbox-input').click();
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async verifyForm({
|
||
|
title,
|
||
|
hookEvent,
|
||
|
url,
|
||
|
notificationType,
|
||
|
urlMethod,
|
||
|
condition,
|
||
|
}: {
|
||
|
title: string;
|
||
|
hookEvent: string;
|
||
|
url: string;
|
||
|
notificationType: string;
|
||
|
urlMethod: string;
|
||
|
condition: boolean;
|
||
|
}) {
|
||
2 years ago
|
await expect.poll(async () => await this.get().locator('input.nc-text-field-hook-title').inputValue()).toBe(title);
|
||
|
await expect(this.get().locator('.nc-text-field-hook-event >> .ant-select-selection-item')).toHaveText(hookEvent);
|
||
|
await expect(this.get().locator('.nc-select-hook-notification-type >> .ant-select-selection-item')).toHaveText(
|
||
|
notificationType
|
||
2 years ago
|
);
|
||
2 years ago
|
await expect(this.get().locator('.nc-select-hook-url-method >> .ant-select-selection-item')).toHaveText(urlMethod);
|
||
|
await expect.poll(async () => await this.get().locator('input.nc-text-field-hook-url-path').inputValue()).toBe(url);
|
||
|
|
||
|
const conditionCheckbox = this.get().locator('label.nc-check-box-hook-condition >> input[type="checkbox"]');
|
||
2 years ago
|
if (condition) {
|
||
2 years ago
|
await expect(conditionCheckbox).toBeChecked();
|
||
|
} else {
|
||
|
await expect(conditionCheckbox).not.toBeChecked();
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
async goBackFromForm() {
|
||
2 years ago
|
await this.get().locator('svg.nc-icon-hook-navigate-left').click();
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|