Skip to content

Commit

Permalink
fix: broken component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
QuaidBartolomei committed Dec 27, 2021
1 parent 019d0e7 commit 3d637d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 58 deletions.
8 changes: 3 additions & 5 deletions src/components/LeaderBoard.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';

import { mountWithTheme as mount } from '../models/test-utils';
import LeaderBoard from './LeaderBoard';


describe('LeaderBoard', () => {
it('renders', () => {
mount(<LeaderBoard />);
cy.fixture('countries/leader').then(({ countries }) => {
mount(<LeaderBoard countries={countries} />);
});
});
});

68 changes: 15 additions & 53 deletions src/components/common/Filter.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import { mountWithTheme as mount } from '../../models/test-utils';
import Filter from './Filter';
// import the expect function from Chai
Expand All @@ -10,85 +8,49 @@ describe('Filter', () => {
mount(<Filter />);
});

it.only('Submit is success when startDate is less than endDate', () => {
it('Submit is success when startDate is less than endDate', () => {
const handleFilter = cy.stub();

mount(<Filter onFilter={handleFilter} />);
cy.contains(/timeline/i);

// cypress to find the date type of input, choose the first one, and input the date
cy.get('input[type=text]').first().type('2020-01-01');

// find the second date type of input, choose the second one, and input the date
cy.get('input[type=text]').eq(1).type('2020-01-02');

cy.get('input[type=text]')
.invoke('val')
.then((startDate) => {
cy.get('input[type=text]')
.eq(1)
.invoke('val')
.should((endDate) => {
const convertStartDate = new Date(startDate);
const convert_endDate = new Date(endDate);
cy.contains('label', 'Start Date')
.parent()
.find('input')
.type('01-01-2020');

const StartDate_milliSeconds = convertStartDate.getTime();
const endDate_milliSeconds = convert_endDate.getTime();
cy.contains('label', 'End Date').parent().find('input').type('01-02-2020');

expect(StartDate_milliSeconds).to.be.lessThan(endDate_milliSeconds);
});
});
cy.contains(/submit/i)
.click()
.then(() => {
expect(handleFilter).to.be.calledWith({
startDate: '2020-01-01',
endDate: '2020-01-02',
endDate: '2020-02-01',
});
});
});

it.only('Submit is Failed when startDate is greater than endDate', () => {
it('Submit is Failed when startDate is greater than endDate', () => {
const handleFilter = cy.stub();

mount(<Filter onFilter={handleFilter} />);
cy.contains(/timeline/i);
cy.contains('label', 'Start Date')
.parent()
.find('input')
.type('01-05-2020');

// cypress to find the date type of input, choose the first one, and input the date
cy.get('input[type=text]').first().type('2020-01-05');

// find the second date type of input, choose the second one, and input the date
cy.get('input[type=text]').eq(1).type('2020-01-02');
cy.contains('label', 'End Date').parent().find('input').type('01-02-2020');

cy.get('input[type=text]')
.invoke('val')
.then((startDate) => {
cy.get('input[type=text]')
.eq(1)
.invoke('val')
.should((endDate) => {
const convertStartDate = new Date(startDate);
const convert_endDate = new Date(endDate);

const StartDate_milliSeconds = convertStartDate.getTime();
const endDate_milliSeconds = convert_endDate.getTime();

expect(StartDate_milliSeconds).to.be.greaterThan(
endDate_milliSeconds,
);
});
});
cy.contains(/submit/i)
.click()
.then(() => {
expect(handleFilter).to.been.not.calledWith({
startDate: '2020-01-05',
endDate: '2020-01-02',
});
expect(handleFilter).to.have.callCount(0);
});
});

it.only('Cancel Button hides the filters', () => {
it('Cancel Button hides the filters', () => {
mount(<Filter />);
cy.contains(/timeline/i);

Expand Down

0 comments on commit 3d637d7

Please sign in to comment.