Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barbara-chaves authored and davidsingal committed Mar 2, 2023
1 parent bfe85e3 commit 53e078b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
37 changes: 35 additions & 2 deletions client/cypress/e2e/analysis.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
DEFAULT_END_YEAR_GAP,
MAX_END_YEAR_RANGE,
} from '../../src/containers/analysis-visualization/analysis-filters/years-range/constants';

beforeEach(() => {
cy.interceptAllRequests();
cy.login();
Expand Down Expand Up @@ -205,27 +210,54 @@ describe('Analysis table', () => {
it('user should be able to select year filters', () => {
cy.wait('@h2Years').then((int) => {
const years = int.response.body.data;
// Check default filter values
cy.wait('@fetchImpactTable').then((req) => {
expect(req.request.query.startYear).to.eq(years[0].toString());
expect(req.request.query.endYear).to.eq(
(years[years.length - 1] + DEFAULT_END_YEAR_GAP).toString(),
);
});

// Check 'from' options
cy.get('[data-testid="years-range-btn"]').click();
cy.get('[data-testid="select-year-selector-from"]').click();
cy.get('[data-testid="year-selector-from-option"]').should('have.length', years.length);

const fromYear = years[2];
// Check if can select a typed value
cy.get('[data-testid="select-year-selector-from"] input')
.focus()
.clear({ force: true })
.type(`${fromYear}{enter}`, {
force: true,
})
.should('have.value', fromYear);
// Check if the payload request is correct
cy.wait('@fetchImpactTable')
.its('request.query.startYear')
.should('eql', fromYear.toString());

const toYear = years[0] + MAX_END_YEAR_RANGE;
cy.get('[data-testid="select-year-selector-to"]').click();

const toYear = years[0] + 1000;
// Check that the 'to' options years smaller than the selected 'from' year are disabled
cy.get('[data-testid="year-selector-to-option"][aria-disabled="true"]').should(
'have.length',
3,
);

// Check if can select a typed value
cy.get('[data-testid="select-year-selector-to"] input')
.focus()
.clear({ force: true })
.type(toYear, {
.type(`${toYear}`, {
force: true,
delay: 300,
})
.type('{enter}', { force: true })
.should('have.value', toYear);
// Check if the payload request is correct
cy.wait('@fetchImpactTable').its('request.query.endYear').should('eql', toYear.toString());
});
});
});
Expand Down Expand Up @@ -253,6 +285,7 @@ describe('Analysis scenarios', () => {
const url = new URL(interception.request.url);
const scenarioIds = url.searchParams.get('scenarioIds');
expect(scenarioIds).to.be.null;
expect(scenarioIds).to.be.null;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useEffect, useMemo, useState } from 'react';
import { isFinite, toNumber, range } from 'lodash-es';
import toast from 'react-hot-toast';

import { DEFAULT_END_YEAR_GAP, MAX_END_YEAR_RANGE } from './constants';

import { useAppDispatch, useAppSelector } from 'store/hooks';
import { analysisUI } from 'store/features/analysis/ui';
import { analysisFilters, setFilters } from 'store/features/analysis/filters';
Expand All @@ -10,11 +12,6 @@ import YearsRangeFilter, { useYearsRange } from 'containers/filters/years-range'

import type { YearsRangeParams } from 'containers/filters/years-range';

/** Arbitrary value to define the end year list range */
const DEFAULT_END_YEAR_GAP = 5;
/** Arbitrary value to define the max range of end year options to avoid performance issues */
const MAX_END_YEAR_RANGE = 1000;

const YearsRange: React.FC = () => {
const dispatch = useAppDispatch();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Arbitrary value to define the end year list range */
export const DEFAULT_END_YEAR_GAP = 5;

/** Arbitrary value to define the max range of end year options to avoid performance issues */
export const MAX_END_YEAR_RANGE = 1000;

1 comment on commit 53e078b

@vercel
Copy link

@vercel vercel bot commented on 53e078b Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

landgriffon-client – ./client

landgriffon-client.vercel.app
landgriffon-client-vizzuality1.vercel.app
landgriffon-client-git-dev-vizzuality1.vercel.app

Please sign in to comment.