Browse Source

test: added create and update field test cases

pull/7408/head
Ramesh Mane 12 months ago
parent
commit
20c7711a61
  1. 4
      packages/nc-gui/components/smartsheet/details/Fields.vue
  2. 62
      tests/playwright/pages/Dashboard/Details/FieldsPage.ts
  3. 3
      tests/playwright/pages/Dashboard/Details/index.ts
  4. 49
      tests/playwright/tests/db/features/multiFieldEditor.spec.ts

4
packages/nc-gui/components/smartsheet/details/Fields.vue

@ -832,6 +832,7 @@ watch(
icon="close" icon="close"
class="mx-1 h-3.5 w-3.5 text-gray-500 group-hover:text-black" class="mx-1 h-3.5 w-3.5 text-gray-500 group-hover:text-black"
@click="searchQuery = ''" @click="searchQuery = ''"
data-testid="nc-field-clear-search"
/> />
</template> </template>
</a-input> </a-input>
@ -895,7 +896,7 @@ watch(
class="flex px-2 hover:bg-gray-100 first:rounded-t-lg border-b-1 last:rounded-b-none border-gray-200 pl-5 group" class="flex px-2 hover:bg-gray-100 first:rounded-t-lg border-b-1 last:rounded-b-none border-gray-200 pl-5 group"
:class="` ${compareCols(field, activeField) ? 'selected' : ''}`" :class="` ${compareCols(field, activeField) ? 'selected' : ''}`"
@click="changeField(field, $event)" @click="changeField(field, $event)"
:data-testid="`nc-field-item-${field.title}`" :data-testid="`nc-field-item-${fieldState(field)?.title || field.title}`"
> >
<div class="flex items-center flex-1 py-2.5 gap-1 w-2/6"> <div class="flex items-center flex-1 py-2.5 gap-1 w-2/6">
<component <component
@ -1106,6 +1107,7 @@ watch(
class="flex px-2 bg-white hover:bg-gray-100 border-b-1 border-gray-200 first:rounded-tl-lg last:border-b-1 pl-5 group" class="flex px-2 bg-white hover:bg-gray-100 border-b-1 border-gray-200 first:rounded-tl-lg last:border-b-1 pl-5 group"
:class="` ${compareCols(displayColumn, activeField) ? 'selected' : ''}`" :class="` ${compareCols(displayColumn, activeField) ? 'selected' : ''}`"
@click="changeField(displayColumn, $event)" @click="changeField(displayColumn, $event)"
:data-testid="`nc-field-item-${fieldState(displayColumn)?.title || displayColumn.title}`"
> >
<div class="flex items-center flex-1 py-2.5 gap-1 w-2/6"> <div class="flex items-center flex-1 py-2.5 gap-1 w-2/6">
<component <component

62
tests/playwright/pages/Dashboard/Details/FieldsPage.ts

@ -11,6 +11,7 @@ export class FieldsPage extends BasePage {
readonly addNewFieldButton: Locator; readonly addNewFieldButton: Locator;
readonly resetFieldChangesButton: Locator; readonly resetFieldChangesButton: Locator;
readonly saveChangesButton: Locator; readonly saveChangesButton: Locator;
readonly addOrEditColumn: Locator; readonly addOrEditColumn: Locator;
readonly fieldListWrapper: Locator; readonly fieldListWrapper: Locator;
@ -29,13 +30,24 @@ export class FieldsPage extends BasePage {
return this.detailsPage.get().locator('.nc-fields-wrapper'); return this.detailsPage.get().locator('.nc-fields-wrapper');
} }
async fillSearch({ title }: { title: string }) {
const searchInput = this.get().getByTestId('nc-field-search-input');
await searchInput.click();
await searchInput.fill(title);
}
async clearSearch() {
await this.get().getByTestId('nc-field-clear-search').click();
}
async clickNewField() { async clickNewField() {
await this.addNewFieldButton.click(); await this.addNewFieldButton.click();
} }
async create({ async createOrUpdate({
title, title,
type = 'SingleLineText', type = 'SingleLineText',
isUpdateMode = false,
formula = '', formula = '',
qrCodeValueColumnTitle = '', qrCodeValueColumnTitle = '',
barcodeValueColumnTitle = '', barcodeValueColumnTitle = '',
@ -52,6 +64,7 @@ export class FieldsPage extends BasePage {
}: { }: {
title: string; title: string;
type?: string; type?: string;
isUpdateMode?: boolean;
formula?: string; formula?: string;
qrCodeValueColumnTitle?: string; qrCodeValueColumnTitle?: string;
barcodeValueColumnTitle?: string; barcodeValueColumnTitle?: string;
@ -66,14 +79,15 @@ export class FieldsPage extends BasePage {
insertAboveColumnTitle?: string; insertAboveColumnTitle?: string;
insertBelowColumnTitle?: string; insertBelowColumnTitle?: string;
}) { }) {
if (insertAboveColumnTitle) { if (!isUpdateMode) {
await this.selectFieldAction({ title: insertAboveColumnTitle, action: 'insert-above' }); if (insertAboveColumnTitle) {
} else if (insertBelowColumnTitle) { await this.selectFieldAction({ title: insertAboveColumnTitle, action: 'insert-above' });
await this.selectFieldAction({ title: insertBelowColumnTitle, action: 'insert-below' }); } else if (insertBelowColumnTitle) {
} else { await this.selectFieldAction({ title: insertBelowColumnTitle, action: 'insert-below' });
await this.clickNewField(); } else {
await this.clickNewField();
}
} }
await this.addOrEditColumn.waitFor({ state: 'visible' }); await this.addOrEditColumn.waitFor({ state: 'visible' });
await this.fillTitle({ title }); await this.fillTitle({ title });
@ -188,18 +202,20 @@ export class FieldsPage extends BasePage {
const locator = this.fieldListWrapper.locator('>div'); const locator = this.fieldListWrapper.locator('>div');
const count = await locator.count(); const count = await locator.count();
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
await locator.nth(i).scrollIntoViewIfNeeded();
const text = await locator.nth(i).getByTestId('nc-field-title').textContent(); const text = await locator.nth(i).getByTestId('nc-field-title').textContent();
fieldsText.push(text); fieldsText.push(text);
} }
// verify field inserted above the target field
if (insertAboveColumnTitle) { if (insertAboveColumnTitle) {
// verify field inserted above the target field
expect(fieldsText[fieldsText.findIndex(title => title.startsWith(insertAboveColumnTitle)) - 1]).toBe(title); expect(fieldsText[fieldsText.findIndex(title => title.startsWith(insertAboveColumnTitle)) - 1]).toBe(title);
} } else if (insertBelowColumnTitle) {
// verify field inserted below the target field
// verify field inserted below the target field expect(fieldsText[fieldsText.findIndex(title => title.startsWith(insertBelowColumnTitle)) + 1]).toBe(title);
if (insertBelowColumnTitle) { } else {
expect(fieldsText[fieldsText.findIndex(title => title.startsWith(insertAboveColumnTitle)) + 1]).toBe(title); // verify field inserted at the end
expect(fieldsText[fieldsText.length - 1]).toBe(title);
} }
} }
@ -222,18 +238,19 @@ export class FieldsPage extends BasePage {
async saveChanges() { async saveChanges() {
await this.waitForResponse({ await this.waitForResponse({
uiAction: async () => await this.saveChangesButton.click(), uiAction: async () => await this.saveChangesButton.click(),
requestUrlPathToMatch: 'api/v1/db/meta/tables/', requestUrlPathToMatch: 'api/v1/db/meta/views/',
httpMethodsToMatch: ['POST'], httpMethodsToMatch: ['GET'],
responseJsonMatcher: json => json['failedOps']?.length === 0, responseJsonMatcher: json => json['list'],
}); });
await this.rootPage.waitForTimeout(200);
} }
async getField({ title }: { title: string }) { getField({ title }: { title: string }) {
return this.fieldListWrapper.getByTestId('nc-field-title').locator(`text=${title}`); return this.fieldListWrapper.getByTestId(`nc-field-item-${title}`);
} }
async getFieldVisibilityCheckbox({ title }: { title: string }) { async getFieldVisibilityCheckbox({ title }: { title: string }) {
return (await this.getField({ title })).getByTestId('nc-field-visibility-checkbox'); return this.getField({ title }).getByTestId('nc-field-visibility-checkbox');
} }
async selectFieldAction({ async selectFieldAction({
@ -245,10 +262,11 @@ export class FieldsPage extends BasePage {
action: 'copy-id' | 'duplicate' | 'insert-above' | 'insert-below' | 'delete'; action: 'copy-id' | 'duplicate' | 'insert-above' | 'insert-below' | 'delete';
isDisplayValueField?: boolean; isDisplayValueField?: boolean;
}) { }) {
const field = await this.getField({ title }); const field = this.getField({ title });
await field.scrollIntoViewIfNeeded();
await field.hover(); await field.hover();
await field.getByTestId('nc-field-item-action-button').waitFor({ state: 'visible' }); // await field.getByTestId('nc-field-item-action-button').waitFor({ state: 'visible' });
await field.getByTestId('nc-field-item-action-button').click(); await field.getByTestId('nc-field-item-action-button').click();
const fieldActionDropdown = isDisplayValueField const fieldActionDropdown = isDisplayValueField

3
tests/playwright/pages/Dashboard/Details/index.ts

@ -4,12 +4,14 @@ import { TopbarPage } from '../common/Topbar';
import { Locator } from '@playwright/test'; import { Locator } from '@playwright/test';
import { WebhookPage } from './WebhookPage'; import { WebhookPage } from './WebhookPage';
import { ErdPage } from './ErdPage'; import { ErdPage } from './ErdPage';
import { FieldsPage } from './FieldsPage';
export class DetailsPage extends BasePage { export class DetailsPage extends BasePage {
readonly dashboard: DashboardPage; readonly dashboard: DashboardPage;
readonly topbar: TopbarPage; readonly topbar: TopbarPage;
readonly webhook: WebhookPage; readonly webhook: WebhookPage;
readonly relations: ErdPage; readonly relations: ErdPage;
readonly fields: FieldsPage;
readonly tab_webhooks: Locator; readonly tab_webhooks: Locator;
readonly tab_apiSnippet: Locator; readonly tab_apiSnippet: Locator;
@ -24,6 +26,7 @@ export class DetailsPage extends BasePage {
this.topbar = dashboard.grid.topbar; this.topbar = dashboard.grid.topbar;
this.webhook = new WebhookPage(this); this.webhook = new WebhookPage(this);
this.relations = new ErdPage(this); this.relations = new ErdPage(this);
this.fields = new FieldsPage(this);
this.tab_webhooks = this.get().locator(`[data-testid="nc-webhooks-tab"]`); this.tab_webhooks = this.get().locator(`[data-testid="nc-webhooks-tab"]`);
this.tab_apiSnippet = this.get().locator(`[data-testid="nc-apis-tab"]`); this.tab_apiSnippet = this.get().locator(`[data-testid="nc-apis-tab"]`);

49
tests/playwright/tests/db/features/multiFieldEditor.spec.ts

@ -0,0 +1,49 @@
import { test } from '@playwright/test';
import { DashboardPage } from '../../../pages/Dashboard';
import { GridPage } from '../../../pages/Dashboard/Grid';
import setup, { unsetup } from '../../../setup';
import { FieldsPage } from '../../../pages/Dashboard/Details/FieldsPage';
test.describe('Multi Field Editor', () => {
let dashboard: DashboardPage, grid: GridPage, fields: FieldsPage;
let context: any;
const defaultFieldName = 'Multi Field Editor';
test.beforeEach(async ({ page }) => {
context = await setup({ page, isEmptyProject: true });
dashboard = new DashboardPage(page, context.base);
grid = dashboard.grid;
fields = dashboard.details.fields;
await dashboard.treeView.createTable({ title: 'Multifield', baseTitle: context.base.title });
await dashboard.grid.topbar.openDetailedTab();
await dashboard.details.clickFieldsTab();
// Add New Field
await fields.createOrUpdate({ title: defaultFieldName });
});
test.afterEach(async () => {
await unsetup(context);
});
const openMultiFieldOfATable = async (tableName: string) => {
await dashboard.treeView.openTable({ title: tableName });
await dashboard.grid.topbar.openDetailedTab();
await dashboard.details.clickRelationsTab();
};
test('Add New field and update', async () => {
// Add New Field
await fields.createOrUpdate({ title: 'Name' });
// Update Field title
await fields.getField({ title: 'Name' }).click();
await fields.createOrUpdate({ title: 'Updated Name', isUpdateMode: true });
});
test('Field action menu: CopyId, Duplicate, InsertAbove, InsertBelow', async () => {
await fields.createOrUpdate({ title: 'Above Inserted Field', insertAboveColumnTitle: defaultFieldName });
await fields.createOrUpdate({ title: 'Below Inserted Field', insertBelowColumnTitle: defaultFieldName });
});
});
Loading…
Cancel
Save