Skip to content

Commit

Permalink
activate open break even price parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Jan 10, 2025
1 parent 030bd6b commit c825817
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
1 change: 0 additions & 1 deletion client/src/containers/overview/header/parameters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
Expand Down
1 change: 1 addition & 0 deletions e2e/page-objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PROJECT_OVERVIEW_TABLE_LOCATOR = 'table tbody tr'
31 changes: 30 additions & 1 deletion e2e/tests/projects/projects-overview-table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'}});
Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion shared/lib/e2e-test-manager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -39,6 +39,10 @@ export class E2eTestManager {
await clearTestDataFromDatabase(this.dataSource);
}

async clearTablesByEntities(entities: any[]) {
await clearTablesByEntities(this.dataSource, entities);
}

getDataSource() {
return this.dataSource;
}
Expand Down

0 comments on commit c825817

Please sign in to comment.