Skip to content

Commit

Permalink
Merge pull request stakwork#485 from MuhammadUmer44/Cypress-Admin-Sta…
Browse files Browse the repository at this point in the history
…tistics-Custom-Date-Range

[Test][cypress] [Super Admin]: Added Cypress Test For Admin Statistics Custom Date Range
  • Loading branch information
elraphty authored Apr 1, 2024
2 parents 1850c2b + c54f073 commit bc282d1
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions cypress/e2e/50_adminCustomDateSelect.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
describe('Admin Statistics Custom Date Range', () => {
let activeUser = 'alice';

const bounty: Cypress.Bounty = {
title: 'UmerJobs',
category: 'Web development',
coding_language: ['Typescript', 'Javascript', 'Lightning'],
description: 'This is available',
amount: '123'
};

beforeEach(() => {
cy.login(activeUser);
cy.wait(1000);
});

it('Creates 25 bounties, navigates to Admin page, and verifies bounties count and visibility', () => {
for (let i = 1; i <= 25; i++) {
const updatedBounty = { ...bounty, title: `UmerJobs${i}` };
cy.create_bounty(updatedBounty);
cy.wait(1000);
}

cy.visit('http://localhost:3007/admin');
cy.wait(3000);

for (let i = 25; i >= 6; i--) {
cy.contains(`UmerJobs${i}`, { timeout: 10000 }).should('exist');
}

cy.contains('25').should('exist');
cy.wait(1000);

cy.get('[data-testid="DropDown"]').click();
cy.contains('li', 'Custom').click();
cy.wait(1000);

const startDate = new Date();
startDate.setDate(1);
const endDate = new Date();

const formatStartDate = startDate.toLocaleDateString('en-US', {
month: '2-digit',
day: '2-digit',
year: 'numeric'
});
const formatEndDate = endDate.toLocaleDateString('en-US', {
month: '2-digit',
day: '2-digit',
year: 'numeric'
});

cy.get('input[name="start"]').clear().type(formatStartDate);
cy.get('input[name="end"]').clear().type(formatEndDate);
cy.contains('Save').click();
cy.wait(1000);

cy.contains('25').should('exist');
cy.wait(1000);

const expectedStartDateFormat = `${String(startDate.getDate()).padStart(
2,
'0'
)} ${startDate.toLocaleString('default', { month: 'short' })}`;
const expectedEndDateFormat = `${String(endDate.getDate()).padStart(
2,
'0'
)} ${endDate.toLocaleString('default', { month: 'short' })} ${endDate.getFullYear()}`;

const expectedDateRange = `${expectedStartDateFormat} - ${expectedEndDateFormat}`;

cy.get('[data-testid="month"]').should('have.text', expectedDateRange);

cy.logout(activeUser);
});
});

0 comments on commit bc282d1

Please sign in to comment.