diff --git a/client/src/containers/overview/header/parameters/index.tsx b/client/src/containers/overview/header/parameters/index.tsx index 2cd80f15..192a873e 100644 --- a/client/src/containers/overview/header/parameters/index.tsx +++ b/client/src/containers/overview/header/parameters/index.tsx @@ -37,7 +37,6 @@ export const PROJECT_PARAMETERS: Parameter[] = [ { label: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE, value: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE, - disabled: true, }, ], }, diff --git a/e2e/page-objects.ts b/e2e/page-objects.ts new file mode 100644 index 00000000..6b6e751a --- /dev/null +++ b/e2e/page-objects.ts @@ -0,0 +1 @@ +export const PROJECT_OVERVIEW_TABLE_LOCATOR = 'table tbody tr' \ No newline at end of file diff --git a/e2e/tests/projects/projects-overview-table.spec.ts b/e2e/tests/projects/projects-overview-table.spec.ts index 5d42b206..2897f3ce 100644 --- a/e2e/tests/projects/projects-overview-table.spec.ts +++ b/e2e/tests/projects/projects-overview-table.spec.ts @@ -2,6 +2,8 @@ import { expect, Page, test } from "@playwright/test"; import { E2eTestManager } from "@shared/lib/e2e-test-manager"; import { User } from "@shared/entities/users/user.entity"; import {Country} from "@shared/entities/country.entity"; +import {Project, PROJECT_PRICE_TYPE} from "@shared/entities/projects.entity"; +import {PROJECT_OVERVIEW_TABLE_LOCATOR} from "../../page-objects"; let testManager: E2eTestManager; let page: Page; @@ -14,12 +16,39 @@ test.describe("Projects - Overview Table", () => { testManager = await E2eTestManager.load(page); await testManager.ingestCountries() }); + test.afterEach(async () => { + await testManager.clearTablesByEntities([Project]) + }); test.afterAll(async () => { await testManager.clearDatabase(); await testManager.close(); }); + test('The default price type is Market price and I can filter the price type of Projects', async () => { + const china = await testManager.getDataSource().getRepository(Country).findOneOrFail({where: {name: 'China'}}); + const india = await testManager.getDataSource().getRepository(Country).findOneOrFail({where: {name: 'India'}}); + + for (const priceType of Object.values(PROJECT_PRICE_TYPE)) { + await testManager.mocks().createProject({countryCode: china.code, projectName: `China Mangrove Conservation ${priceType}`, priceType}); + await testManager.mocks().createProject({countryCode: india.code, projectName: `India Mangrove Conservation ${priceType}`, priceType}); + } + await page.goto('http://localhost:3000/'); + const projectsTable = page.locator(PROJECT_OVERVIEW_TABLE_LOCATOR) + const projectsInTable = await projectsTable.count(); + expect(projectsInTable).toBe(2); + const firstRowCells = await projectsTable.nth(0).locator('td').allTextContents(); + expect(firstRowCells).toContain(`China Mangrove Conservation Market price`); + await page.locator('button').filter({ hasText: 'Market price' }).click(); + await page.getByText('Opex breakeven').click(); + const projectsInTableAfterFilter = await projectsTable.count(); + expect(projectsInTableAfterFilter).toBe(2); + const firstRowCellsAfterFilter = await projectsTable.nth(0).locator('td').allTextContents(); + expect(firstRowCellsAfterFilter).toContain(`China Mangrove Conservation Opex breakeven`); + const secondRowCellsAfterFilter = await projectsTable.nth(1).locator('td').allTextContents(); + expect(secondRowCellsAfterFilter).toContain(`India Mangrove Conservation Opex breakeven`); + }); + test('I can filter Projects by Country', async () => { const china = await testManager.getDataSource().getRepository(Country).findOneOrFail({where: {name: 'China'}}); const india = await testManager.getDataSource().getRepository(Country).findOneOrFail({where: {name: 'India'}}); @@ -29,7 +58,7 @@ test.describe("Projects - Overview Table", () => { await page.getByRole('button', { name: 'Filters' }).click(); await page.locator('button').filter({ hasText: 'All countries' }).click(); await page.getByText('China', {exact: true }).click(); - const projectsTable = page.locator('table tbody tr') + const projectsTable = page.locator(PROJECT_OVERVIEW_TABLE_LOCATOR) const projectsInTable = await projectsTable.count(); expect(projectsInTable).toBe(1); const firstRowCells = await projectsTable.nth(0).locator('td').allTextContents(); diff --git a/shared/lib/e2e-test-manager.ts b/shared/lib/e2e-test-manager.ts index 8bedc874..75ecd0fd 100644 --- a/shared/lib/e2e-test-manager.ts +++ b/shared/lib/e2e-test-manager.ts @@ -1,7 +1,7 @@ import { DataSource } from "typeorm"; import { User } from "@shared/entities/users/user.entity"; import {createProject, createUser} from "@shared/lib/entity-mocks"; -import { clearTestDataFromDatabase } from "@shared/lib/db-helpers"; +import {clearTablesByEntities, clearTestDataFromDatabase} from "@shared/lib/db-helpers"; import { JwtPayload, sign } from "jsonwebtoken"; import { TOKEN_TYPE_ENUM } from "@shared/schemas/auth/token-type.schema"; import { COMMON_DATABASE_ENTITIES } from "@shared/lib/db-entities"; @@ -39,6 +39,10 @@ export class E2eTestManager { await clearTestDataFromDatabase(this.dataSource); } + async clearTablesByEntities(entities: any[]) { + await clearTablesByEntities(this.dataSource, entities); + } + getDataSource() { return this.dataSource; }