Skip to content

Commit

Permalink
Add tests for order activities
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsunkel committed Dec 13, 2024
1 parent ed58c79 commit e1ce56d
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React from 'react'

import urls from '../../../../../../src/lib/urls'

import { ItemTemplate } from '../../../../../../src/client/modules/Companies/CompanyActivity'
import { transformOrderToListItem } from '../../../../../../src/client/modules/Companies/CompanyActivity/transformers'
import { CollectionList } from '../../../../../../src/client/components'
import {
assertActivitySubject,
assertMetadataItems,
assertOrderKindLabel,
assertText,
} from '../../../support/activity-assertions'
import {
CONTACT_1,
CONTACT_2,
CREATED_BY,
CREATED_ON,
} from '../../../support/activity-constants'

const REFERENCE = 'FYH243/24'
const ORDER_URL = urls.omis.order('2')

const buildAndMountActivity = (contact = CONTACT_1, ukRegion = true) => {
const activity = {
date: CREATED_ON,
order: {
id: '2',
primary_market: {
name: 'Test Country',
},
uk_region: ukRegion
? {
name: 'Test UK Region',
}
: null,
created_by: CREATED_BY,
contact: contact,
reference: REFERENCE,
},
}

cy.mountWithProvider(
<CollectionList
items={[transformOrderToListItem(activity)]}
collectionItemTemplate={ItemTemplate}
/>
)
}

describe('Order activity card', () => {
context('When the card is rendered with a complete order', () => {
beforeEach(() => {
buildAndMountActivity()
cy.get('[data-test=collection-item]').should('exist')
})

it('should render the labels and metadata', () => {
assertOrderLabels()
assertActivitySubject(REFERENCE, ORDER_URL)
assertMetadataItems([
'Date 25 Nov 2058',
'Country Test Country',
'UK region Test UK Region',
'Added by Bernard Harris-Patel [email protected], Test Team 1 ',
'Company contact Alexander Hamilton, Test Job',
])
})
})

context('When the order has missing fields', () => {
beforeEach(() => {
buildAndMountActivity(CONTACT_2, false)
cy.get('[data-test=collection-item]').should('exist')
})

it('should render the labels and metadata', () => {
assertOrderLabels()
assertActivitySubject(REFERENCE, ORDER_URL)
assertMetadataItems([
'Date 25 Nov 2058',
'Country Test Country',
'Added by Bernard Harris-Patel [email protected], Test Team 1 ',
'Company contact Oliver Twist',
])
})
})
})

const assertOrderLabels = () => {
assertText('[data-test="order-theme-label"]', 'Orders (OMIS)')
assertText('[data-test="order-service-label"]', 'Event')
assertOrderKindLabel()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react'

import urls from '../../../../../../../src/lib/urls'

import { transformOrderToListItem } from '../../../../../../../src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/transformers'
import { ItemTemplate } from '../../../../../../../src/client/modules/Companies/CompanyOverview/TableCards/ActivityCards/ActivityCard'
import { CollectionList } from '../../../../../../../src/client/components'
import {
assertActivitySubject,
assertOrderKindLabel,
} from '../../../../support/activity-assertions'
import { CREATED_BY, CREATED_ON } from '../../../../support/activity-constants'

const REFERENCE = 'FYH243/24'
const ORDER_URL = urls.omis.order('2')

const buildAndMountActivity = (showCreatedBy = true) => {
const activity = {
date: CREATED_ON,
order: {
id: '2',
primary_market: {
name: 'Test Country',
},
created_by: showCreatedBy ? CREATED_BY : null,
reference: REFERENCE,
},
}

cy.mountWithProvider(
<CollectionList
items={[transformOrderToListItem(activity)]}
collectionItemTemplate={ItemTemplate}
/>
)
}

describe('Order activity card', () => {
context('When the card is rendered with a complete order', () => {
beforeEach(() => {
buildAndMountActivity()
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertOrderKindLabel()
assertActivitySubject(REFERENCE, ORDER_URL, 'activity-card-wrapper')
cy.get('[data-test="activity-date"]').should('have.text', '25 Nov 2058')
cy.get('[data-test="activity-summary"]').should(
'have.text',
'Export to Test Country added by Bernard Harris-Patel'
)
})
})

context('When the order has no created_by name', () => {
beforeEach(() => {
buildAndMountActivity(false)
cy.get('[data-test="activity-card-wrapper"]').should('exist')
})

it('should render the labels and metadata', () => {
assertOrderKindLabel()
assertActivitySubject(REFERENCE, ORDER_URL, 'activity-card-wrapper')
cy.get('[data-test="activity-date"]').should('have.text', '25 Nov 2058')
cy.get('[data-test="activity-summary"]').should(
'have.text',
'Export to Test Country'
)
})
})
})
4 changes: 4 additions & 0 deletions test/component/cypress/support/activity-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export const assertReferralLabel = (expectedText = 'Completed referral') => {
export const assertProjectKindLabel = () => {
assertText('[data-test="investment-kind-label"]', 'New Investment Project')
}

export const assertOrderKindLabel = () => {
assertText('[data-test="order-kind-label"]', 'New Order')
}
1 change: 1 addition & 0 deletions test/component/cypress/support/activity-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const CREATED_ON = '2058-11-25T00:00:00Z'
export const CONTACT_1 = {
id: '115b4d96-d2ea-40ff-a01d-812507093a98',
name: 'Alexander Hamilton',
job_title: 'Test Job',
}

export const CONTACT_2 = {
Expand Down

0 comments on commit e1ce56d

Please sign in to comment.