Skip to content

Commit

Permalink
update cypress commands + minor style tweak (#8)
Browse files Browse the repository at this point in the history
* update cypress tests

* fix cypress commands

* style tweak and clean-up

* tweak
  • Loading branch information
patrickpeinanw authored Jun 25, 2024
1 parent 7475402 commit 1dc3f50
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 83 deletions.
2 changes: 1 addition & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000/BC0871427',
baseUrl: 'http://localhost:3000',
setupNodeEvents (on) {
on('task', {
log (message) {
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/accessibility/business-dash.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ context('Accessibility -> Business Dashboard', () => {
})

it('check page passes accessibility after initial page load', () => {
cy.getOfficeAddresses()
cy.getDirectorParties()
cy.get('[data-cy="business-dashboard"]').should('exist')
cy.checkA11y('[data-cy="business-dashboard"]')
})
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/components/addresses.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
context('Business dashboard -> Address side component', () => {
beforeEach(() => {
cy.visitBusinessDash()
})

it('Address accordion is rendered for Registered Office and Record Office', () => {
cy.getOfficeAddresses()
cy.visitBusinessDash('BC0871427', 'BEN')

// the accordion exists
cy.get('[data-cy="accordion_officeAddresses"]').should('exist')
Expand All @@ -31,7 +27,11 @@ context('Business dashboard -> Address side component', () => {
})

it('Business Addresses section is rendered for SP and GP', () => {
cy.getBusinessAddresses()
cy.visitBusinessDash('FM1060270', 'SP')
cy.get('[data-cy="accordion_officeAddresses"]').should('not.exist')
cy.get('[data-cy="businessAddresses"]').should('exist')

cy.visitBusinessDash('FM1060265', 'GP')
cy.get('[data-cy="accordion_officeAddresses"]').should('not.exist')
cy.get('[data-cy="businessAddresses"]').should('exist')
})
Expand Down
10 changes: 3 additions & 7 deletions cypress/e2e/components/parties.cy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
context('Business dashboard -> Parties side components', () => {
beforeEach(() => {
cy.visitBusinessDash()
})

it('Directors accordion is rendered', () => {
cy.getDirectorParties()
cy.visitBusinessDash('BC0871427', 'BEN')
cy.get('[data-cy="accordion_directors"]').should('exist')
cy.get('[data-cy="accordion_directors"]').children().eq(0).children().should('have.length', 5)
})

it('Partners accordion is rendered', () => {
cy.getPartnerParties()
cy.visitBusinessDash('FM1060265', 'GP')
cy.get('[data-cy="accordion_partners"]').should('exist')
cy.get('[data-cy="accordion_partners"]').children().eq(0).children().should('have.length', 3)
})

it('Proprietors accordion is rendered', () => {
cy.getProprietorParties()
cy.visitBusinessDash('FM1060270', 'SP')
cy.get('[data-cy="accordion_proprietors"]').should('exist')
cy.get('[data-cy="accordion_proprietors"]').children().eq(0).children().should('have.length', 1)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
"streetAddressAdditional": ""
}
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"adminFreeze": false,
"goodStanding": true,
"identifier": "BC0871427",
"legalName": "0871427 B.C. LTD.",
"legalType": "BEN",
"state": "ACTIVE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"businessIdentifier": "BC0871427",
"contacts": [
{
"email": "test@test.com",
"phone": "(123) 456 7890",
"email": "test1@test.com",
"phone": "(123) 456 7891",
"phoneExtension": ""
}
],
Expand Down
19 changes: 19 additions & 0 deletions cypress/fixtures/businessContactGP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"contacts": [
{
"email": "[email protected]",
"phone": "(123) 456 7893",
"phoneExtension": ""
}
],
"corpType": {
"code": "GP",
"default": false,
"desc": "General Partnership"
},
"created": "2023-06-27T21:48:47+00:00",
"modified": "2023-10-19T16:58:23+00:00",
"modifiedBy": "Tester Fake Account",
"name": "Test GP Company",
"passCodeClaimed": false
}
19 changes: 19 additions & 0 deletions cypress/fixtures/businessContactSP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"contacts": [
{
"email": "[email protected]",
"phone": "(123) 456 7892",
"phoneExtension": ""
}
],
"corpType": {
"code": "SP",
"default": false,
"desc": "Sole Proprietorship"
},
"created": "2023-06-27T21:48:47+00:00",
"modified": "2023-10-19T16:58:23+00:00",
"modifiedBy": "Tester Fake Account",
"name": "Test SP Company",
"passCodeClaimed": false
}
8 changes: 8 additions & 0 deletions cypress/fixtures/businessGP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"adminFreeze": false,
"goodStanding": true,
"legalName": "Test GP Company",
"legalType": "GP",
"state": "ACTIVE",
"taxId": "123456789BC0003"
}
8 changes: 8 additions & 0 deletions cypress/fixtures/businessSP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"adminFreeze": false,
"goodStanding": true,
"legalName": "Test SP Company",
"legalType": "SP",
"state": "ACTIVE",
"taxId": "123456789BC0002"
}
108 changes: 50 additions & 58 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Cypress.Commands.add('interceptBusinessSlim', () => {
cy.fixture('business').then((business) => {
Cypress.Commands.add('interceptBusinessSlim', (identifier, legalType) => {
cy.fixture(`business${legalType}`).then((business) => {
business.identifier = identifier
cy.intercept(
'GET',
`**/api/v2/businesses/${business.identifier}?slim=true`,
{ business })
})
})

Cypress.Commands.add('interceptBusinessContact', () => {
cy.fixture('business').then((business) => {
cy.fixture('businessContact').then((contact) => {
Cypress.Commands.add('interceptBusinessContact', (identifier, legalType) => {
cy.fixture(`business${legalType}`).then((business) => {
business.identifier = identifier
cy.fixture(`businessContact${legalType}`).then((contact) => {
contact.businessIdentifier = identifier
cy.intercept(
'GET',
`**/api/v1/entities/${business.identifier}`,
Expand All @@ -18,78 +21,67 @@ Cypress.Commands.add('interceptBusinessContact', () => {
})
})

Cypress.Commands.add('visitBusinessDash', () => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')
cy.intercept('GET', '**/api/v1/users/**/settings', { fixture: 'settings.json' }).as('getSettings')
cy.intercept(
'REPORT',
'https://app.launchdarkly.com/sdk/evalx/**/context',
{ fixture: 'ldarklyContext.json' }
).as('getLdarklyContext')
cy.intercept('GET', '**/api/v1/orgs/**/products*', { fixture: 'products.json' }).as('getProducts')
cy.interceptBusinessContact().as('getBusinessContact')
cy.interceptBusinessSlim().as('getBusinessSlim')
cy.visit('')
cy.wait(['@getSettings', '@getProducts', '@getBusinessContact', '@getBusinessSlim'])
cy.injectAxe()
})
Cypress.Commands.add('interceptAddresses', (legalType) => {
let addressFixture = 'addressBEN'
if (legalType === 'SP' || legalType === 'GP') {
addressFixture = 'addressSPandGP'
}

Cypress.Commands.add('getBusinessAddresses', () => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')

cy.intercept('GET', '**/api/v2/businesses/**/addresses*', { fixture: 'addressSFandGF.json' }).as('getAddresses')
cy.visit('')
cy.wait(['@getAddresses'])
cy.injectAxe()
})

Cypress.Commands.add('getOfficeAddresses', () => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')

cy.intercept('GET', '**/api/v2/businesses/**/addresses*', { fixture: 'address.json' }).as('getAddresses')
cy.visit('')
cy.wait(['@getAddresses'])
cy.injectAxe()
cy.fixture(addressFixture).then((address) => {
cy.intercept(
'GET',
'**/api/v2/businesses/**/addresses*',
address)
})
})

Cypress.Commands.add('getDirectorParties', () => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')
Cypress.Commands.add('interceptParties', (legalType) => {
let partyFixture = 'directorParties'

cy.intercept('GET', '**/api/v2/businesses/**/parties*', { fixture: 'directorParties.json' }).as('getParties')
cy.visit('')
cy.wait(['@getParties'])
cy.injectAxe()
})
if (legalType === 'SP') {
partyFixture = 'proprietorParties'
} else if (legalType === 'GP') {
partyFixture = 'partnerParties'
}

Cypress.Commands.add('getPartnerParties', () => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')

cy.intercept('GET', '**/api/v2/businesses/**/parties*', { fixture: 'partnerParties.json' }).as('getParties')
cy.visit('')
cy.wait(['@getParties'])
cy.injectAxe()
cy.fixture(partyFixture).then((parties) => {
cy.intercept(
'GET',
'**/api/v2/businesses/**/parties*',
parties)
})
})

Cypress.Commands.add('getProprietorParties', () => {
Cypress.Commands.add('visitBusinessDash', (identifier = 'BC0871427', legalType = 'BEN') => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')
cy.intercept('GET', '**/api/v1/users/**/settings', { fixture: 'settings.json' }).as('getSettings')
cy.intercept(
'REPORT',
'https://app.launchdarkly.com/sdk/evalx/**/context',
{ fixture: 'ldarklyContext.json' }
).as('getLdarklyContext')
cy.intercept('GET', '**/api/v1/orgs/**/products*', { fixture: 'products.json' }).as('getProducts')
cy.interceptBusinessContact(identifier, legalType).as('getBusinessContact')
cy.interceptBusinessSlim(identifier, legalType).as('getBusinessSlim')
cy.interceptAddresses(legalType).as('getAddresses')
cy.interceptParties(legalType).as('getParties')

cy.intercept('GET', '**/api/v2/businesses/**/parties*', { fixture: 'proprietorParties.json' }).as('getParties')
cy.visit('')
cy.wait(['@getParties'])
cy.visit(`/${identifier}`)
cy.wait(['@getSettings', '@getProducts', '@getBusinessContact', '@getBusinessSlim', '@getAddresses', '@getParties'])
cy.injectAxe()
})

Cypress.Commands.add('visitBusinessDashAuthError', () => {
Cypress.Commands.add('visitBusinessDashAuthError', (identifier = 'BC0871427', legalType = 'BEN') => {
sessionStorage.setItem('FAKE_CYPRESS_LOGIN', 'true')
cy.intercept('GET', '**/api/v1/users/**/settings', { statusCode: 500, body: {} }).as('getSettingsError')
cy.intercept(
'REPORT',
'https://app.launchdarkly.com/sdk/evalx/**/context',
{ fixture: 'ldarklyContext.json' }
).as('getLdarklyContext')
cy.interceptBusinessContact().as('getBusinessContact')
cy.interceptBusinessSlim().as('getBusinessSlim')
cy.visit('')
cy.interceptBusinessContact(identifier, legalType).as('getBusinessContact')
cy.interceptBusinessSlim(identifier, legalType).as('getBusinessSlim')
cy.visit(`/${identifier}`)
cy.wait(['@getSettingsError'])
cy.injectAxe()
})
2 changes: 1 addition & 1 deletion src/components/bcros/AccordionItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="text-gray-900 pb-1">
{{ $t('label.general.email') }}
</div>
<span v-if="item.email">
<span v-if="item.email" class="break-all">
{{ item.email }}
</span>
<span v-else>
Expand Down
3 changes: 2 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"label": {
"general": {
"email": "Email",
"phone": "Phone"
"phone": "Phone",
"notEntered": "Not entered"
},
"business": {
"businessNum": "Business Number",
Expand Down
7 changes: 5 additions & 2 deletions src/pages/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ const containRole = (roleType) => {
party.roles.find(role => role.roleType === roleType && !role.cessationDate)
)
}
onBeforeMount(() => {
const loadAddressesAndParties = () => {
if (route.params.identifier) {
business.loadBusinessAddresses(route.params.identifier as string)
business.loadParties(route.params.identifier as string)
}
}
onBeforeMount(() => {
loadAddressesAndParties()
})
</script>

0 comments on commit 1dc3f50

Please sign in to comment.