Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convert to export win functional tests #6590

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client/modules/ExportWins/Form/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export const getTwelveMonthsAgo = () => {
return new Date(today.getFullYear() - 1, today.getMonth(), 1)
}

export const getRandomDate = ({ start, end }) =>
new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()))

export const isDateWithinLastTwelveMonths = (date) => {
// Business date logic
const today = new Date()
Expand Down
117 changes: 116 additions & 1 deletion test/functional/cypress/specs/export-win/add-export-win-spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { omit } from 'lodash'

import { getTwelveMonthsAgo } from '../../../../../src/client/modules/ExportWins/Form/utils'
import {
getRandomDate,
getTwelveMonthsAgo,
} from '../../../../../src/client/modules/ExportWins/Form/utils'
import { winTypeId } from '../../../../../src/client/modules/ExportWins/Form/constants'
import { clickContinueButton } from '../../support/actions'
import { companyFaker } from '../../fakers/companies'
import { contactFaker } from '../../fakers/contacts'
import { exportFaker } from '../../fakers/export'
import urls from '../../../../../src/lib/urls'
import {
assertUrl,
Expand All @@ -18,7 +22,9 @@ import {
assertFieldTypeahead,
assertFieldDateShort,
assertFieldCheckboxes,
assertTypeaheadValues,
assertFieldRadiosWithLegend,
assertSingleTypeaheadOptionSelected,
} from '../../support/assertions'

const company = companyFaker({
Expand Down Expand Up @@ -1112,4 +1118,113 @@ describe('Adding an export win', () => {
})
})
})

context('Pre-propulating the form with an export project', () => {
const { officerDetails, customerDetails, winDetails } = formFields

const today = new Date()
const exportProject = exportFaker()
const create = urls.companies.exportWins.createFromExport(
company.id,
exportProject.id
)

const officerDetailsStep = create + '?step=officer_details'
const customerDetailsStep = create + '?step=customer_details'
const winDetailsStep = create + '?step=win_details'

const interceptExportApiCall = (overrides = {}) => {
cy.intercept('GET', `/api-proxy/v4/export/${exportProject.id}`, {
...exportProject,
...overrides,
})
}

beforeEach(() => {
cy.setUserFeatureGroups(['export-wins'])
interceptExportApiCall()
})

it('should pre-populate the lead officer field', () => {
cy.visit(officerDetailsStep)
cy.get(officerDetails.leadOfficer)
.find('input')
.should('have.value', exportProject.owner.name)
})

it('should pre-populate the team members field', () => {
cy.visit(officerDetailsStep)
assertTypeaheadValues(
'[data-test="field-team_members"]',
exportProject.team_members.map(({ name }) => name)
)
})

it('should pre-populate the exporter experience field', () => {
cy.visit(customerDetailsStep)
assertSingleTypeaheadOptionSelected({
element: customerDetails.experience,
expectedOption: exportProject.exporter_experience.name,
})
})

it('should pre-populate the export destination country', () => {
cy.visit(winDetailsStep)
assertSingleTypeaheadOptionSelected({
element: winDetails.country,
expectedOption: exportProject.destination_country.name,
})
})

it('should not pre-populate the win date when the estimated win date is greater than twelve months ago', () => {
const thirteenMonthsAgo = new Date(
today.getFullYear() - 1,
today.getMonth() - 1,
1
)

interceptExportApiCall({
estimated_win_date: thirteenMonthsAgo.toISOString(),
})

cy.visit(winDetailsStep)
cy.get(winDetails.dateMonth).should('have.value', '')
cy.get(winDetails.dateYear).should('have.value', '')
})

it('should pre-populate the win date when the estimated date is less than or equal to 12 months ago', () => {
const date = getRandomDate({
start: twelveMonthsAgo,
end: today,
})

interceptExportApiCall({
estimated_win_date: date.toISOString(),
})

cy.visit(winDetailsStep)
cy.get(winDetails.dateYear).should('have.value', date.getFullYear())
cy.get(winDetails.dateMonth).should('have.value', date.getMonth() + 1)
})

it('should not pre-populate the win date when the estimated date is in the future', () => {
const nextMonth = new Date(today.getFullYear(), today.getMonth() + 1)

interceptExportApiCall({
estimated_win_date: nextMonth.toISOString(),
})

cy.visit(winDetailsStep)
cy.get(winDetails.dateYear).should('have.value', '')
cy.get(winDetails.dateMonth).should('have.value', '')
})

it('should pre-populate the sector', () => {
cy.visit(winDetailsStep)
assertSingleTypeaheadOptionSelected({
element: winDetails.sector,
expectedOption: exportProject.sector.name,
})
})
})
})
Loading