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 EYB leads page sort by filter #7465

Merged
merged 4 commits into from
Jan 21, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const EYBLeadCollection = ({
filterOptions,
payload,
optionMetadata,
sortOptions,
...props
}) => {
const location = useLocation()
Expand Down Expand Up @@ -111,10 +112,12 @@ const EYBLeadCollection = ({
<FilteredCollectionList
{...props}
collectionName="EYB lead"
sortOptions={sortOptions}
taskProps={collectionListTask}
entityName="eybLead"
defaultQueryParams={{
page: 1,
sortby: '-triage_created',
}}
selectedFilters={selectedFilters}
>
Expand Down
11 changes: 11 additions & 0 deletions src/client/modules/Investments/EYBLeads/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ export const VALUE_OPTIONS = [
{ value: 'low', label: VALUES.LOW_VALUE },
{ value: 'unknown', label: VALUES.UNKNOWN },
]

export const SORT_OPTIONS = [
{
name: 'Recently created',
value: '-triage_created',
},
{
name: 'Company A-Z',
value: 'company__name',
},
]
2 changes: 2 additions & 0 deletions src/client/modules/Investments/EYBLeads/state.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseQueryString } from '../../../utils'
import { SORT_OPTIONS } from './constants'
import { transformLeadToListItem } from './transformers'

export const INVESTMENT_EYB_LEADS_ID = 'eybLeads'
Expand All @@ -16,5 +17,6 @@ export const state2props = ({ router: { location }, ...state }) => {
results: results.map(transformLeadToListItem),
payload: queryParams,
filterOptions,
sortOptions: SORT_OPTIONS,
}
}
2 changes: 2 additions & 0 deletions src/client/modules/Investments/EYBLeads/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export const getEYBLeads = ({
country = [],
sector = [],
value = [],
sortby,
}) => {
let params = new URLSearchParams({
limit,
offset: limit * (parseInt(page, 10) - 1) || 0,
...(company ? { company } : null),
sortby: sortby ? sortby : '-triage_created',
})
overseas_region.forEach((overseasRegionId) =>
params.append('overseas_region', overseasRegionId)
Expand Down
88 changes: 76 additions & 12 deletions test/functional/cypress/specs/investments/eyb-leads-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ const EYB_LEAD_LIST = Array(
)

const PAYLOADS = {
minimum: { limit: '10', offset: '0' },
minimum: { limit: '10', offset: '0', sortby: '-triage_created' },
companyFilter: { company: COMPANY_NAME },
sectorFilter: { sector: SECTOR_ID },
highValueFilter: { value: HIGH_VALUE },
lowValueFilter: { value: LOW_VALUE },
unknownValueFilter: { value: UNKNOWN_VALUE },
countryFilter: { country: COUNTRY_ID_1 },
sortByCreated: { sortby: '-triage_created' },
sortByCompanyAZ: { sortby: 'company__name' },
}

const buildQueryString = (queryParams = {}) =>
Expand Down Expand Up @@ -245,10 +247,14 @@ describe('EYB leads collection page', () => {
})

it('should filter from user input', () => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.company) {
req.alias = 'filteredRequest'
}
})
cy.visit(`${investments.eybLeads.index()}`)
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`).as('apiRequest')
cy.get(FILTER_ELEMENTS.company).type(`${COMPANY_NAME}{enter}`)
cy.wait('@apiRequest')
cy.wait('@filteredRequest')
.its('request.query')
.should('include', expectedPayload)
assertQueryParams('company', COMPANY_NAME)
Expand Down Expand Up @@ -292,8 +298,12 @@ describe('EYB leads collection page', () => {
})

it('should filter from user input', () => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.sector) {
req.alias = 'filteredRequest'
}
})
cy.visit(`${investments.eybLeads.index()}`)
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`).as('apiRequest')
assertTypeaheadHints({
element: FILTER_ELEMENTS.sector,
label: 'Sector of interest',
Expand All @@ -307,7 +317,7 @@ describe('EYB leads collection page', () => {
element: FILTER_ELEMENTS.sector,
expectedOption: SECTOR_NAME,
})
cy.wait('@apiRequest')
cy.wait('@filteredRequest')
.its('request.query')
.should('include', expectedPayload)
assertQueryParams('sector[0]', SECTOR_ID)
Expand Down Expand Up @@ -387,14 +397,17 @@ describe('EYB leads collection page', () => {
})

it('should filter from user input', () => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`).as('apiRequest')
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.value) {
req.alias = 'filteredRequest'
}
})
cy.visit(`${investments.eybLeads.index()}`)
cy.wait('@apiRequest')
clickCheckboxGroupOption({
element: FILTER_ELEMENTS.value,
value: testCase.queryParamValue,
})
cy.wait('@apiRequest')
cy.wait('@filteredRequest')
.its('request.query')
.should('include', testCase.expectedPayload)
assertQueryParams('value[0]', testCase.queryParamValue)
Expand Down Expand Up @@ -441,8 +454,12 @@ describe('EYB leads collection page', () => {
})

it('should filter from user input', () => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.country) {
req.alias = 'filteredRequest'
}
})
cy.visit(`${investments.eybLeads.index()}`)
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`).as('apiRequest')
assertTypeaheadHints({
element: FILTER_ELEMENTS.country,
label: 'Country',
Expand All @@ -456,7 +473,7 @@ describe('EYB leads collection page', () => {
element: FILTER_ELEMENTS.country,
expectedOption: COUNTRY_NAME_1,
})
cy.wait('@apiRequest')
cy.wait('@filteredRequest')
.its('request.query')
.should('include', expectedPayload)
assertQueryParams('country[0]', COUNTRY_ID_1)
Expand Down Expand Up @@ -504,8 +521,12 @@ describe('EYB leads collection page', () => {
})

it('should filter from user input', () => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.overseas_region) {
req.alias = 'filteredRequest'
}
})
cy.visit(`${investments.eybLeads.index()}`)
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`).as('apiRequest')
assertTypeaheadHints({
element: FILTER_ELEMENTS.overseas_region,
label: 'HMTC region',
Expand All @@ -519,7 +540,7 @@ describe('EYB leads collection page', () => {
element: FILTER_ELEMENTS.overseas_region,
expectedOption: OVERSEAS_REGION_NAME_1,
})
cy.wait('@apiRequest')
cy.wait('@filteredRequest')
.its('request.query')
.should('include', expectedPayload)
assertQueryParams('overseas_region[0]', OVERSEAS_REGION_ID_1)
Expand Down Expand Up @@ -549,4 +570,47 @@ describe('EYB leads collection page', () => {
})
}
)
context('When sorting the EYB leads collection', () => {
beforeEach(() => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`).as('apiRequest')
cy.visit(investments.eybLeads.index())
})

it('should load sort by dropdown', () => {
cy.get('[data-test="sortby"] select option').then((options) => {
const actual = [...options].map((o) => o.value)
expect(actual).to.deep.eq(['-triage_created', 'company__name'])
})
})

it('should sort by most recently created by default', () => {
assertQueryParams('sortby', '-triage_created')
cy.wait('@apiRequest')
.its('request.query')
.should('include', PAYLOADS.sortByCreated)
})

it('should sort by company name A-Z', () => {
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.sortby === 'company__name') req.alias = 'sortedRequest'
})
cy.get('[data-test="sortby"] select').select('company__name')
assertQueryParams('sortby', 'company__name')
cy.wait('@sortedRequest')
.its('request.query')
.should('include', PAYLOADS.sortByCompanyAZ)
})

it('should sort by most recently created when another sort option is selected', () => {
cy.get('[data-test="sortby"] select').select('company__name')
cy.intercept('GET', `${EYB_RETRIEVE_API_ROUTE}?*`, (req) => {
if (req.query.sortby === '-triage_created') req.alias = 'sortedRequest'
})
cy.get('[data-test="sortby"] select').select('-triage_created')
assertQueryParams('sortby', '-triage_created')
cy.wait('@sortedRequest')
.its('request.query')
.should('include', PAYLOADS.sortByCreated)
})
})
})
Loading