Skip to content

Commit

Permalink
test: updated test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Nov 1, 2024
1 parent ec5a527 commit 10b1635
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 106 deletions.
25 changes: 21 additions & 4 deletions page-objects/layout/listLayoutPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ export default abstract class ListLayoutPage<T extends BaseModel> extends Normal
await this.page.waitForSelector(this.listContainer);
}

async waitForDetailPageLoad() {
await this.page.waitForSelector('.detail-layout');
}

async navigateToDetail(rowIndex: number) {
const row = this.page.locator(this.tableRows).nth(rowIndex);
await row.locator(this.viewButton).click();
await this.waitForDetailPageLoad();
}

async clearSearch() {
await this.page.fill(this.searchInput, '');
}

async searchRows(searchTerm: string) {
async searchRows(searchTerm: string, wait = 1000) {
await this.page.fill(this.searchInput, searchTerm);
if (wait) {
await this.page.waitForTimeout(wait);
}
}

async clickCreate() {
Expand All @@ -54,22 +62,31 @@ export default abstract class ListLayoutPage<T extends BaseModel> extends Normal
await row.locator(this.showMoreButton).click();
}

async deleteRow(rowIndex: number) {
async deleteRow(rowIndex: number, wait = 1000) {
await this.clickShowMore(rowIndex);
await this.clickContextMenuItem(this.deleteButton);
await this.page.click(this.deleteConfirmButton);
if (wait) {
await this.page.waitForTimeout(wait);
}
}

async createRow(form: T) {
async createRow(form: T, wait = 1000) {
await this.clickCreate();
await this.formPage.fillForm(form);
await this.confirm();
if (wait) {
await this.page.waitForTimeout(wait);
}
}

async createRowWithRandomName(form: T) {
async createRowWithRandomName(form: T, wait = 1000) {
const randomName = `${form.name} ${Date.now()}`;
const formWithRandomName: T = { ...form, name: randomName };
await this.createRow(formWithRandomName);
if (wait) {
await this.page.waitForTimeout(wait);
}
return formWithRandomName;
}

Expand Down
15 changes: 12 additions & 3 deletions page-objects/views/node/nodeListPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ export class NodeListPage extends ListLayoutPage<Node> {
private nodeStatusFilter = '#filter-select-status .el-select';
private nodeEnabledFilter = '#filter-select-enabled .el-select';

async filterByNodeType(type: string) {
async filterByNodeType(type: string, wait = 1000) {
await this.selectOption(this.nodeTypeFilter, type);
if (wait) {
await this.page.waitForTimeout(wait);
}
}

async filterByNodeStatus(status: string) {
async filterByNodeStatus(status: string, wait = 1000) {
await this.selectOption(this.nodeStatusFilter, status);
if (wait) {
await this.page.waitForTimeout(wait);
}
}

async filterByNodeEnabled(enabled: string) {
async filterByNodeEnabled(enabled: string, wait = 1000) {
await this.selectOption(this.nodeEnabledFilter, enabled);
if (wait) {
await this.page.waitForTimeout(wait);
}
}

// Getters
Expand Down
7 changes: 7 additions & 0 deletions page-objects/views/project/projectListPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ProjectListPage extends ListLayoutPage<Project> {
private nameColumn = 'td:nth-child(2)';
private spidersColumn = 'td:nth-child(3)';
private descriptionColumn = 'td:nth-child(4)';
private viewSpidersButton = '.view-spiders-btn';

async getTableRow(rowIndex: number) {
const row = this.page.locator(this.tableRows).nth(rowIndex);
Expand All @@ -22,5 +23,11 @@ export class ProjectListPage extends ListLayoutPage<Project> {
description: await row.locator(this.descriptionColumn).innerText(),
} as Project;
}

async clickViewSpiders(rowIndex: number) {
await this.clickShowMore(rowIndex);
await this.clickContextMenuItem(this.viewSpidersButton);
await this.waitForDetailPageLoad();
}
}

8 changes: 7 additions & 1 deletion page-objects/views/spider/spiderListPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export class SpiderListPage extends ListLayoutPage<Spider> {
private viewDataButton = '.view-data-btn';
private projectFilterSelector = '#filter-select-project';

async filterByProject(projectName: string) {
async filterByProject(projectName: string, wait = 1000) {
await this.selectOptionByText(this.projectFilterSelector, projectName);
if (wait) {
await this.page.waitForTimeout(wait);
}
}

async isUploadSpiderFilesDialogVisible() {
Expand All @@ -49,16 +52,19 @@ export class SpiderListPage extends ListLayoutPage<Spider> {
async clickViewTasks(rowIndex: number) {
await this.clickShowMore(rowIndex);
await this.clickContextMenuItem(this.viewTasksButton);
await this.waitForDetailPageLoad();
}

async clickViewSchedules(rowIndex: number) {
await this.clickShowMore(rowIndex);
await this.clickContextMenuItem(this.viewSchedulesButton);
await this.waitForDetailPageLoad();
}

async clickViewData(rowIndex: number) {
await this.clickShowMore(rowIndex);
await this.clickContextMenuItem(this.viewDataButton);
await this.waitForDetailPageLoad();
}

async getTableRow(rowIndex: number) {
Expand Down
6 changes: 1 addition & 5 deletions tests/node/nodeList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ test.describe('Node List Tests', () => {
test.describe(CATEGORY_ROW_ACTIONS, { tag: TAG_PRIORITY_HIGH }, () => {
test('should navigate to the node details page', async ({ page }) => {
await nodeListPage.navigateToDetail(0);
await page.waitForSelector('.detail-layout');
expect(page.url()).toMatch(/\/nodes\/[0-9a-f]{24}/);
});
});

test.describe(CATEGORY_FILTER_ROWS, { tag: TAG_PRIORITY_MEDIUM }, () => {
test('should filter nodes by type', async ({ page }) => {
test('should filter nodes by type', async () => {
await nodeListPage.filterByNodeType('true');
await page.waitForTimeout(1000); // Add a 1-second wait
const nodeCount = await nodeListPage.getNodeCount();
expect(nodeCount).toBeGreaterThan(0);

Expand All @@ -34,7 +32,6 @@ test.describe('Node List Tests', () => {

test('should filter nodes by status', async ({ page }) => {
await nodeListPage.filterByNodeStatus('on');
await page.waitForTimeout(1000); // Add a 1-second wait
const nodeCount = await nodeListPage.getNodeCount();
expect(nodeCount).toBeGreaterThan(0);

Expand All @@ -58,7 +55,6 @@ test.describe('Node List Tests', () => {
test('should search for a non-existent node', async ({ page }) => {
const searchTerm = 'Non-Existent Node';
await nodeListPage.searchRows(searchTerm);
await page.waitForTimeout(1000); // Add a 1-second wait

const nodeCount = await nodeListPage.getNodeCount();
expect(nodeCount).toBe(0);
Expand Down
22 changes: 11 additions & 11 deletions tests/project/projectList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,54 @@ test.beforeAll(async ({ browser }) => {

test.describe('Project List Tests', () => {
let projectListPage: ProjectListPage;
let projectFormPage: ProjectFormPage;

test.beforeEach(async ({ page }) => {
projectListPage = new ProjectListPage(page);
projectFormPage = new ProjectFormPage(page);
await projectListPage.navigate();
});

test.describe.serial(CATEGORY_CREATE_DELETE_ROW, { tag: TAG_PRIORITY_HIGH }, () => {
let project: Project;

test('should create a new project', async ({ page }) => {
test('should create a new project', async () => {
// Fill out the project form
project = await projectListPage.createRowWithRandomName(projectData.single as Project);
await page.waitForTimeout(1000);

// Search for the new project
await projectListPage.searchRows(project.name);
await page.waitForTimeout(1000); // Wait for search results

// Verify the new project appears in the list
const lastProjectData = await projectListPage.getTableRow(0);
expect(lastProjectData.name).toBe(project.name);
expect(lastProjectData.description).toBe(project.description);
});

test('should delete a project', async ({ page }) => {
test('should delete a project', async () => {
// Search for the project to delete
await projectListPage.searchRows(project.name);
await page.waitForTimeout(1000); // Wait for search results

// Delete the project
await projectListPage.deleteRow(0);
await page.waitForTimeout(1000); // Wait for deletion to process

// Verify the project has been deleted
expect(await projectListPage.getTableRowCount()).toBe(0);
});
});

test.describe(CATEGORY_ROW_ACTIONS, { tag: TAG_PRIORITY_MEDIUM }, () => {
test.beforeEach(async () => {
await projectListPage.searchRows(project.name);
});

test('should navigate to project detail', async ({ page }) => {
const projectCount = await projectListPage.getTableRowCount();
expect(projectCount).toBeGreaterThan(0);
await projectListPage.navigateToDetail(0);
await page.waitForSelector('.detail-layout');
expect(page.url()).toMatch(/\/projects\/[0-9a-f]{24}/);
});

test('should navigate to project spiders view', async ({ page }) => {
await projectListPage.clickViewSpiders(0);
expect(page.url()).toMatch(/\/projects\/[0-9a-f]{24}\/spiders/);
});
});

test.describe(CATEGORY_FILTER_ROWS, { tag: TAG_PRIORITY_MEDIUM }, () => {
Expand Down
Loading

0 comments on commit 10b1635

Please sign in to comment.