From f23957e717ca4fe5838b2c60e0938bc1974511cb Mon Sep 17 00:00:00 2001 From: aahna-ashina <95955389+aahna-ashina@users.noreply.github.com> Date: Tue, 25 Oct 2022 16:54:34 +0800 Subject: [PATCH] test(cypress): add more integration tests --- components/ProposalBadges.tsx | 2 +- cypress/e2e/proposals.cy.ts | 63 +++++++++++++++++++++++++++++++++-- package.json | 2 +- pages/proposals/[id].tsx | 2 +- pages/proposals/create.tsx | 4 +-- pages/proposals/index.tsx | 8 ++--- pages/proposals/process.tsx | 3 +- yarn.lock | 8 ++--- 8 files changed, 76 insertions(+), 16 deletions(-) diff --git a/components/ProposalBadges.tsx b/components/ProposalBadges.tsx index 9ead9c1..35b28ec 100644 --- a/components/ProposalBadges.tsx +++ b/components/ProposalBadges.tsx @@ -2,7 +2,7 @@ import { Badge } from 'flowbite-react' const ProposalBadges = ({ proposal }: any) => { return ( -
+
#{proposal.content.kind} {proposal.approved === true ? ( Approved diff --git a/cypress/e2e/proposals.cy.ts b/cypress/e2e/proposals.cy.ts index e0494aa..9eab73c 100644 --- a/cypress/e2e/proposals.cy.ts +++ b/cypress/e2e/proposals.cy.ts @@ -1,8 +1,67 @@ describe('Proposals', () => { + it('Should load /proposals list', () => { + cy.visit('/proposals') + cy.get('body').find('#proposalsPage') + }) + + it('Should open a random proposal page', () => { + cy.visit('/proposals') + cy.get('body') + .find('.proposalCard') + .then(proposalCards => { + const proposalCardCount: number = Cypress.$(proposalCards).length + cy.log('proposalCardCount:', proposalCardCount) + const randomProposalCardIndex: number = Math.round((Math.random() * proposalCardCount)) + cy.log('randomProposalCardIndex:', randomProposalCardIndex) + cy.get(`.proposalCard:nth-child(${randomProposalCardIndex + 1})`).click() + cy.get('body').find('#proposalPage') + }) + }) + + it('Should filter by outcome and open a random proposal page', () => { + cy.visit('/proposals') + cy.get('#outcomeSelector') + .find('option') + .then(options => { + // Select a random outome option + const optionsCount: number = Cypress.$(options).length + cy.log('optionsCount:', optionsCount) + const randomOptionIndex: number = 1 + Math.floor((Math.random() * (optionsCount - 1))) + cy.log('randomOptionIndex:', randomOptionIndex) + const randomOptionValue: string = options[randomOptionIndex].value + cy.log('randomOptionValue:', randomOptionValue) + const randomOptionText: string = options[randomOptionIndex].text + cy.log('randomOptionText:', randomOptionText) + cy.get('#outcomeSelector').select(randomOptionValue) + + // Open a random proposal page + cy.get('body') + .find('.proposalCard') + .then(proposalCards => { + const proposalCardCount: number = Cypress.$(proposalCards).length + cy.log('proposalCardCount:', proposalCardCount) + const randomProposalCardIndex: number = Math.floor((Math.random() * proposalCardCount)) + cy.log('randomProposalCardIndex:', randomProposalCardIndex) + cy.get(`.proposalCard:nth-child(${randomProposalCardIndex + 1})`).click() + cy.get('body').find('#proposalPage') + cy.get('.proposalBadges').contains(randomOptionText) + }) + }) + }) +}) + +describe('Create Proposal', () => { + it('Should load /proposals/create', () => { + cy.visit('/proposals') + cy.get('#createButton').click() + cy.get('body').find('#createPage') + }) - it('Should load /proposals page', () => { + it('Should load /proposals/process', () => { cy.visit('/proposals') - cy.get('h1').contains('Proposals') + cy.get('#createButton').click() + cy.get('#governanceProcessLink').click() + cy.get('body').find('#processPage') }) }) diff --git a/package.json b/package.json index 504211d..34a155b 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@types/react-dom": "18.0.6", "@types/react-syntax-highlighter": "^15.5.3", "autoprefixer": "^10.4.7", - "cypress": "^10.8.0", + "cypress": "^10.10.0", "eslint": "8.20.0", "eslint-config-next": "12.2.2", "postcss": "^8.4.14", diff --git a/pages/proposals/[id].tsx b/pages/proposals/[id].tsx index a19fbeb..482dfc3 100644 --- a/pages/proposals/[id].tsx +++ b/pages/proposals/[id].tsx @@ -120,7 +120,7 @@ const proposalComponents = (proposal: any) => { const Proposal: NextPage = ({ proposal }: any) => { return ( -
+