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 Oct 24, 2024
1 parent 2a2a983 commit 85bfee8
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 46 deletions.
6 changes: 3 additions & 3 deletions global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { chromium, FullConfig } from '@playwright/test';
import { LoginPage } from './page-objects/login/loginPage';
import { LoginPage } from '@/page-objects/views/login/loginPage';
import userData from './fixtures/userData.json';

async function globalSetup(config: FullConfig) {
const { baseURL, storageState } = config.projects[0].use;
const browser = await chromium.launch();
const page = await browser.newPage();
const loginPage = new LoginPage(page);
await page.goto(baseURL + '/#/login');

await page.goto(baseURL + '/#/login', { waitUntil: 'domcontentloaded' });
await loginPage.login(userData.adminUser.username, userData.adminUser.password);

await page.context().storageState({ path: storageState as string });
Expand Down
7 changes: 7 additions & 0 deletions page-objects/layout/listLayoutPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export default abstract class ListLayoutPage<T> extends NormalLayoutPage {

protected listContainer = '.list-layout';
protected createButton = '#add-btn';
protected confirmButton = '#confirm-btn';
protected searchInput = '#filter-search .el-input input';
protected tableRows = '.list-layout table tbody tr';
protected viewButton = '.view-btn';
protected deleteButton = '.delete-btn';
protected deleteConfirmButton = '.delete-confirm-btn';

async navigate() {
await super.navigate();
Expand All @@ -33,9 +35,14 @@ export default abstract class ListLayoutPage<T> extends NormalLayoutPage {
await this.page.click(this.createButton);
}

async confirm() {
await this.page.click(this.confirmButton);
}

async deleteRow(rowIndex: number) {
const row = this.page.locator(this.tableRows).nth(rowIndex);
await row.locator(this.deleteButton).click();
await this.page.click(this.deleteConfirmButton);
}

async getTableRowCount(): Promise<number> {
Expand Down
2 changes: 1 addition & 1 deletion page-objects/layout/normalLayoutPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Page } from '@playwright/test';
import { LoginPage } from '@/page-objects/login/loginPage';
import { LoginPage } from '@/page-objects/views/login/loginPage';
import userData from '@/fixtures/userData.json';

export default abstract class NormalLayoutPage {
Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeListPage } from '@/page-objects/node/nodeListPage';
import { NodeListPage } from '@/page-objects/views/node/nodeListPage';
import DetailLayoutPage from '@/page-objects/layout/detailLayoutPage';

export class NodeDetailPage extends DetailLayoutPage<Node, NodeListPage> {
Expand Down
File renamed without changes.
55 changes: 55 additions & 0 deletions page-objects/views/project/projectFormPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Page } from '@playwright/test';

export class ProjectFormPage {
private page: Page;

constructor(page: Page) {
this.page = page;
}

// Locators
private nameInput = '[data-test="name"] input';
private descriptionTextarea = '[data-test="description"] textarea';

async fillProjectForm(name: string, description: string) {
await this.setName(name);
await this.setDescription(description);
}

async setName(name: string) {
await this.page.fill(this.nameInput, name);
}

async setDescription(description: string) {
await this.page.fill(this.descriptionTextarea, description);
}

async getName(): Promise<string> {
return await this.page.inputValue(this.nameInput);
}

async getDescription(): Promise<string> {
return await this.page.inputValue(this.descriptionTextarea);
}

async isNameInputDisabled(): Promise<boolean> {
const nameInput = this.page.locator(this.nameInput);
return await nameInput.isDisabled();
}

async isDescriptionInputDisabled(): Promise<boolean> {
const descriptionTextarea = this.page.locator(this.descriptionTextarea);
return await descriptionTextarea.isDisabled();
}

async getNamePlaceholder(): Promise<string | null> {
const nameInput = this.page.locator(this.nameInput);
return await nameInput.getAttribute('placeholder');
}

async getDescriptionPlaceholder(): Promise<string | null> {
const descriptionTextarea = this.page.locator(this.descriptionTextarea);
return await descriptionTextarea.getAttribute('placeholder');
}
}

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/login/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test as base, expect } from '@playwright/test';
import { LoginPage } from '@/page-objects/login/loginPage';
import { LoginPage } from '@/page-objects/views/login/loginPage';
import userData from '@/fixtures/userData.json';

// Define a new test fixture with a blank storage state
Expand Down
2 changes: 1 addition & 1 deletion tests/node/nodeDetail.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import { NodeDetailPage } from '@/page-objects/node/nodeDetailPage';
import { NodeDetailPage } from '@/page-objects/views/node/nodeDetailPage';

test.describe('Node Detail Page', () => {
let nodeDetailPage: NodeDetailPage;
Expand Down
2 changes: 1 addition & 1 deletion tests/node/nodeList.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import { NodeListPage } from '@/page-objects/node/nodeListPage';
import { NodeListPage } from '@/page-objects/views/node/nodeListPage';

test.describe('Node List Tests', () => {
let nodeListPage: NodeListPage;
Expand Down
101 changes: 63 additions & 38 deletions tests/project/projectList.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { test, expect } from '@playwright/test';
import { ProjectListPage } from '@/page-objects/project/projectListPage';
import { ProjectListPage } from '@/page-objects/views/project/projectListPage';
import { ProjectFormPage } from '@/page-objects/views/project/projectFormPage';

test.describe.skip('Project List Tests', () => {
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();
});

Expand All @@ -14,27 +17,6 @@ test.describe.skip('Project List Tests', () => {
expect(projectCount).toBeGreaterThanOrEqual(0);
});

test('should create a new project', async ({ page }) => {
const initialCount = await projectListPage.getTableRowCount();
await projectListPage.clickCreate();

// Here you would interact with the create project dialog
// For this example, we'll assume the dialog is handled elsewhere
// and just check that the button click worked

await page.waitForSelector('.el-dialog');
const dialogVisible = await page.isVisible('.el-dialog');
expect(dialogVisible).toBe(true);

// Close the dialog
await page.click('.el-dialog__close');

// In a real scenario, you'd fill out the form and submit it
// Then you'd verify the new project appears in the list
// const newCount = await projectListPage.getProjectCount();
// expect(newCount).toBe(initialCount + 1);
});

test('should search for a project', async ({ page }) => {
const searchTerm = 'Test Project';
await projectListPage.searchRows(searchTerm);
Expand All @@ -54,30 +36,73 @@ test.describe.skip('Project List Tests', () => {
const projectCount = await projectListPage.getTableRowCount();
if (projectCount > 0) {
await projectListPage.navigateToDetail(0);
await page.waitForNavigation();
await page.waitForSelector('.detail-layout');
expect(page.url()).toContain('/projects/');
} else {
// If no projects, skip this test
test.skip();
}
});

test('should delete a project', async ({ page }) => {
const projectCount = await projectListPage.getTableRowCount();
if (projectCount > 0) {
const initialCount = projectCount;
await projectListPage.deleteRow(0);
test('should verify project form placeholders', async () => {
await projectListPage.clickCreate();

const namePlaceholder = await projectFormPage.getNamePlaceholder();
const descriptionPlaceholder = await projectFormPage.getDescriptionPlaceholder();

expect(namePlaceholder).toBe('Name' || '名称');
expect(descriptionPlaceholder).toBe('Description' || '描述');
});

test('should verify project form field states', async () => {
await projectListPage.clickCreate();

// Assume there's a confirmation dialog
await page.click('.el-message-box__btns .el-button--primary');
const isNameDisabled = await projectFormPage.isNameInputDisabled();
const isDescriptionDisabled = await projectFormPage.isDescriptionInputDisabled();

expect(isNameDisabled).toBe(false);
expect(isDescriptionDisabled).toBe(false);
});

// Sequential tests for create and delete
test.describe.serial('Create and Delete Tests', () => {
test('should create a new project', async ({ page }) => {
const initialCount = await projectListPage.getTableRowCount();
await projectListPage.clickCreate();

// Fill out the project form
const projectName = 'Test Project';
const projectDescription = 'This is a test project';
await projectFormPage.fillProjectForm(projectName, projectDescription);

// Submit the form (you might need to implement this method in ProjectListPage)
await projectListPage.confirm();

// Wait for the new project to appear in the list
await page.waitForTimeout(1000);

await page.waitForTimeout(1000); // Wait for deletion to process
const newCount = await projectListPage.getTableRowCount();
expect(newCount).toBe(initialCount - 1);
} else {
// If no projects, skip this test
test.skip();
}
expect(newCount).toBe(initialCount + 1);

// Verify the new project appears in the list
const lastProjectData = await projectListPage.getTableRow(newCount - 1);
expect(lastProjectData.name).toBe(projectName);
expect(lastProjectData.description).toBe(projectDescription);
});

test('should delete a project', async ({ page }) => {
const projectCount = await projectListPage.getTableRowCount();
if (projectCount > 0) {
const initialCount = projectCount;
await projectListPage.deleteRow(0);

await page.waitForTimeout(1000); // Wait for deletion to process
const newCount = await projectListPage.getTableRowCount();
expect(newCount).toBe(initialCount - 1);
} else {
// If no projects, skip this test
test.skip();
}
});
});
});

0 comments on commit 85bfee8

Please sign in to comment.