diff --git a/cypress/e2e/51_adminCustomDateInput.cy.ts b/cypress/e2e/51_adminCustomDateInput.cy.ts new file mode 100644 index 00000000..d5a6bb1c --- /dev/null +++ b/cypress/e2e/51_adminCustomDateInput.cy.ts @@ -0,0 +1,79 @@ +describe('Admin Custom Date Input', () => { + const activeUser = 'alice'; + + const bounty: Cypress.Bounty = { + title: 'Admin', + category: 'Web development', + description: 'This is available', + amount: '123', + assign: 'carol', + deliverables: 'We are good to go man' + }; + + const today = new Date(); + const startDate = `${(today.getMonth() + 1).toString().padStart(2, '0')}/${today + .getDate() + .toString() + .padStart(2, '0')}/${today.getFullYear().toString().slice(-2)}`; + + const endDate = new Date(today.getTime()); + endDate.setDate(today.getDate() + 1); + + const endDateFormatted = `${(endDate.getMonth() + 1).toString().padStart(2, '0')}/${endDate + .getDate() + .toString() + .padStart(2, '0')}/${endDate.getFullYear()}`; + + beforeEach(() => { + cy.login(activeUser); + cy.wait(1000); + }); + + it('should create 22 bounties, navigate to admin page, and assert custom date input functionality', () => { + for (let i = 1; i <= 22; i++) { + const updatedBounty = { ...bounty, title: `Admin${i}` }; + cy.create_bounty(updatedBounty); + cy.wait(1000); + } + + cy.visit('http://localhost:3007/admin'); + cy.wait(3000); + + cy.contains('22'); + cy.contains('Bounties'); + + cy.contains('Last 7 Days').click(); + cy.contains('Custom').click(); + + cy.get('input[placeholder="MM/DD/YY"]').eq(0).clear().type(startDate); + + cy.get('input[placeholder="MM/DD/YY"]').eq(1).clear().type(endDateFormatted); + + cy.contains('Save').click(); + cy.wait(2000); + + cy.contains('22'); + cy.contains('Bounties'); + + const [startMonth, startDay, startYear] = startDate.split('/').map(Number); + const [endMonth, endDay, endYear] = endDateFormatted.split('/').map(Number); + + const date = new Date(startYear, startMonth - 1, startDay); + const date2 = new Date(endYear, endMonth - 1, endDay); + + const formattedDate = date.toLocaleDateString('en-GB', { day: '2-digit', month: 'short' }); + const formattedDate2 = date2.toLocaleDateString('en-GB', { + day: '2-digit', + month: 'short', + year: 'numeric' + }); + + cy.get('[data-testid="month"]').contains(`${formattedDate} - ${formattedDate2}`); + + for (let i = 1; i <= 22; i++) { + cy.contains(`Admin${i}`); + } + + cy.logout(activeUser); + }); +}); diff --git a/src/pages/superadmin/header/__tests__/SuperAdminHeader.spec.tsx b/src/pages/superadmin/header/__tests__/SuperAdminHeader.spec.tsx index 62662625..8bd92765 100644 --- a/src/pages/superadmin/header/__tests__/SuperAdminHeader.spec.tsx +++ b/src/pages/superadmin/header/__tests__/SuperAdminHeader.spec.tsx @@ -83,7 +83,7 @@ describe('Header Component', () => { const StartDate90 = today.clone().subtract(90, 'days'); expect(monthElement).toHaveTextContent( - `${StartDate90.format('DD MMM YYYY')} - ${expectedEndDate.format('DD MMM YYYY')}` + `${StartDate90.format('DD MMM')} - ${expectedEndDate.format('DD MMM YYYY')}` ); }); test('displays same year for startDate and endDate', () => {