Skip to content

Commit

Permalink
fixed tests adapted to new dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsingal authored and yulia-bel committed Nov 21, 2022
1 parent 860441f commit 0943244
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 32 deletions.
4 changes: 4 additions & 0 deletions client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

- Toggle to set the visibility (public or private) of a scenario. [LANDGRIF-1009](https://vizzuality.atlassian.net/browse/LANDGRIF-1009)

### Fixed

- Tests were failing due to a change in the dev environment

## [v0.3.0]

### Added
Expand Down
46 changes: 27 additions & 19 deletions client/cypress/e2e/analysis-filters.cy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
describe('Analysis and filters', () => {
beforeEach(() => {
cy.intercept('GET', '/api/v1/impact/table*', {
fixture: 'impact/table.json',
}).as('impactTable');
cy.login();
});

it('should be able to select and indicator', () => {
// data integrity check
cy.intercept('GET', '/api/v1/**/indicators', {
cy.intercept('GET', '/api/v1/indicators', {
fixture: 'indicators/index.json',
}).as('indicators');
cy.visit('/analysis/table');
cy.wait('@indicators').then((interception) => {
expect(interception.response.body.data).have.length(4);
expect(interception.response.body?.data).have.length(4);
});
cy.get('[data-testid="analysis-table"]', {
timeout: 5000,
}).should('be.visible');

cy.url().should('not.include', 'indicator');

Expand All @@ -36,44 +42,46 @@ describe('Analysis and filters', () => {
it('should update the params playing with the filters', () => {
cy.visit('/analysis/table');

cy.intercept('GET', '/api/v1/materials/trees*', {
cy.intercept('GET', '/api/v1/materials/trees?depth=1&withSourcingLocations=true', {
fixture: 'trees/materials.json',
}).as('materialsTrees');
cy.intercept('GET', '/api/v1/admin-regions/trees*', {
cy.intercept('GET', '/api/v1/admin-regions/trees?withSourcingLocations=true', {
fixture: 'trees/admin-regions.json',
}).as('originsTrees');
cy.intercept('GET', '/api/v1/suppliers/trees*', {
cy.intercept('GET', '/api/v1/suppliers/trees?withSourcingLocations=true', {
fixture: 'trees/suppliers.json',
}).as('suppliersTrees');

cy.intercept(
'GET',
'/api/v1/suppliers/trees?*originIds[]=8bd7e578-f64f-4042-8a3a-2a7652ce850b',
{
fixture: 'trees/suppliers-filtered.json',
},
).as('suppliersTreesFiltered');

// Step 1: open more filters
cy.get('[data-testid="more-filters-button"]').click();
cy.wait('@materialsTrees');
cy.wait('@originsTrees');
cy.wait('@suppliersTrees');

// Step 2: Selecting Angola in the admin regions selector
cy.get('[data-testid="tree-select-origins-filter"]').find('div[role="combobox"]').click();
cy.get('#floating-ui-root').find('.rc-tree-treenode').eq(1).click();
cy.get('[data-testid="tree-select-origins-filter"]').find('input:visible').type('{enter}');
// Adding new interceptors after selecting a filter
cy.intercept(
'GET',
'/api/v1/suppliers/trees?*originIds[]=8bd7e578-f64f-4042-8a3a-2a7652ce850b*',
{
fixture: 'trees/suppliers-filtered.json',
},
).as('suppliersTreesFiltered');

// Step 3: Selecting Moll in the material selector
cy.intercept(
'GET',
'/api/v1/materials/trees?*supplierIds[]=c8bca40d-1aec-44e3-b82b-8170898800ad',
'/api/v1/materials/trees?*supplierIds[]=c8bca40d-1aec-44e3-b82b-8170898800ad*',
{
fixture: 'trees/materials-filtered.json',
},
).as('materialsTreesFiltered');

// Step 2: Selecting Angola in the admin regions selector
cy.get('[data-testid="tree-select-origins-filter"]').find('div[role="combobox"]').click();
cy.get('#floating-ui-root').find('.rc-tree-treenode').eq(1).click();
cy.get('[data-testid="tree-select-origins-filter"]').find('input:visible').type('{enter}');
cy.wait('@suppliersTreesFiltered');

// Step 3: Selecting Moll in the material selector
cy.get('[data-testid="tree-select-suppliers-filter"]').find('div[role="combobox"]').click();
cy.get('#floating-ui-root').find('.rc-tree-treenode').eq(1).click();
cy.get('[data-testid="tree-select-materials-filter"]').find('input:visible').type('{enter}');
Expand Down
14 changes: 13 additions & 1 deletion client/cypress/e2e/analysis.cy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
describe('Analysis navigation across table, map and chart', () => {
beforeEach(() => {
cy.intercept('GET', '/api/v1/impact/ranking?*').as('fetchChartRanking');
cy.intercept('GET', '/api/v1/indicators', {
fixture: 'indicators/index.json',
}).as('fetchIndicators');
cy.intercept('GET', '/api/v1/impact/ranking?*', {
fixture: 'impact/chart.json',
}).as('fetchChartRanking');
cy.intercept('GET', '/api/v1/impact/table*', {
fixture: 'impact/table.json',
}).as('fetchImpactTable');
cy.intercept('GET', '/api/v1/h3/map/impact*', {
fixture: 'impact/map.json',
}).as('fetchImpactMap');
cy.login();
});

it('should load the charts', () => {
cy.visit('/analysis/chart');
cy.wait('@fetchIndicators');
cy.wait('@fetchChartRanking');
cy.get('[data-testid="analysis-chart"]')
.should('be.visible')
Expand Down
1 change: 1 addition & 0 deletions client/cypress/fixtures/impact/chart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"impactTable":[{"indicatorShortName":"Water use","indicatorId":"9c2124c7-5df0-40d5-962e-d35480d48cd3","groupBy":"material","rows":[{"name":"Cotton","children":[],"values":[{"year":2020,"value":342181440,"isProjected":false},{"year":2021,"value":347314161.6,"isProjected":true},{"year":2022,"value":352523874.02400005,"isProjected":true}]},{"name":"Raw hides, skins and leather","children":[],"values":[{"year":2020,"value":266131567,"isProjected":false},{"year":2021,"value":270123540.505,"isProjected":true},{"year":2022,"value":274175393.612575,"isProjected":true}]},{"name":"Rubber and articles thereof","children":[],"values":[{"year":2020,"value":41207428,"isProjected":false},{"year":2021,"value":41825539.42,"isProjected":true},{"year":2022,"value":42452922.511300005,"isProjected":true}]},{"name":"Animal or vegetable fats and oils","children":[{"name":"Palm oil and its fractions","children":[],"values":[{"year":2020,"value":5657224,"isProjected":false},{"year":2021,"value":5742082.36,"isProjected":true},{"year":2022,"value":5828213.5954,"isProjected":true}]}],"values":[{"year":2020,"value":5657224,"isProjected":false},{"year":2021,"value":5742082.36,"isProjected":true},{"year":2022,"value":5828213.5954,"isProjected":true}]}],"yearSum":[{"year":2020,"value":655177659},{"year":2021,"value":665005323.885},{"year":2022,"value":674980403.743275}],"metadata":{"unit":"Mm3/yr"},"others":{"aggregatedValues":[{"year":2020,"value":0},{"year":2021,"value":0},{"year":2022,"value":0}],"numberOfAggregatedEntities":0,"sort":"DES"}}],"purchasedTonnes":[{"year":2020,"value":6015778,"isProjected":false},{"year":2021,"value":6106014.67,"isProjected":true},{"year":2022,"value":6197604.89005,"isProjected":true}]}
1 change: 1 addition & 0 deletions client/cypress/fixtures/impact/map.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/cypress/fixtures/impact/table.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"@types/react": "18.0.17",
"@typescript-eslint/eslint-plugin": "5.13.0",
"@typescript-eslint/parser": "5.13.0",
"cypress": "10.3.1",
"cypress": "10.9.0",
"eslint": "8.23.1",
"eslint-config-next": "12.2.3",
"eslint-config-prettier": "8.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,22 @@ const AnalysisTable = () => {
: impactActualComparisonData;

const {
data: {
data: { impactTable = [] },
metadata,
},
data: impactData,
isLoading,
isFetching,
} = useMemo(() => {
if (isComparisonEnabled && !!scenarioToCompare) return impactComparisonData;
return plainImpactData;
}, [impactComparisonData, plainImpactData, isComparisonEnabled, scenarioToCompare]);

const {
data: { impactTable = [] },
metadata,
} = useMemo(() => {
if (impactData) return impactData;
return { data: { impactTable: [] }, metadata: {} };
}, [impactData]);

const totalRows = useMemo(() => {
return !isLoading && impactTable.length === 1 ? impactTable[0].rows.length : impactTable.length;
}, [isLoading, impactTable]);
Expand Down
14 changes: 7 additions & 7 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10412,9 +10412,9 @@ __metadata:
languageName: node
linkType: hard

"cypress@npm:10.3.1":
version: 10.3.1
resolution: "cypress@npm:10.3.1"
"cypress@npm:10.9.0":
version: 10.9.0
resolution: "cypress@npm:10.9.0"
dependencies:
"@cypress/request": ^2.88.10
"@cypress/xvfb": ^1.2.4
Expand All @@ -10435,7 +10435,7 @@ __metadata:
dayjs: ^1.10.4
debug: ^4.3.2
enquirer: ^2.3.6
eventemitter2: ^6.4.3
eventemitter2: 6.4.7
execa: 4.1.0
executable: ^4.1.1
extract-zip: 2.0.1
Expand All @@ -10460,7 +10460,7 @@ __metadata:
yauzl: ^2.10.0
bin:
cypress: bin/cypress
checksum: 7c76157195ec9409b9665aa9f7698ffd221c74c17f5026769fa20f90a60869cc8274282fa5b9b65e495429839f7a0ba05d69cf12a8af7a318ebcd704f96156c2
checksum: 79e3dccbb82d0b0c92bb8888682766a9738374f473cf2e9a04825a6b3dbe4420c57948cabaf757af0929192a8e61b7f08b32d7f6ee0c3cddf2736cf4f408edc1
languageName: node
linkType: hard

Expand Down Expand Up @@ -11988,7 +11988,7 @@ __metadata:
languageName: node
linkType: hard

"eventemitter2@npm:^6.4.3":
"eventemitter2@npm:6.4.7":
version: 6.4.7
resolution: "eventemitter2@npm:6.4.7"
checksum: 1b36a77e139d6965ebf3a36c01fa00c089ae6b80faa1911e52888f40b3a7057b36a2cc45dcd1ad87cda3798fe7b97a0aabcbb8175a8b96092a23bb7d0f039e66
Expand Down Expand Up @@ -15256,7 +15256,7 @@ __metadata:
axios: 0.27.2
chroma-js: 2.1.2
classnames: 2.3.1
cypress: 10.3.1
cypress: 10.9.0
d3-array: 3.0.2
d3-format: 3.0.1
d3-scale: 4.0.2
Expand Down

0 comments on commit 0943244

Please sign in to comment.