Skip to content

Commit

Permalink
(PC-34133)[PRO] chore: reduce offers limit to 100 on offers list
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeoffray-pass committed Jan 29, 2025
1 parent 25dafa9 commit 545903c
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 49 deletions.
2 changes: 1 addition & 1 deletion api/src/pcapi/core/educational/api/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@


logger = logging.getLogger(__name__)
OFFERS_RECAP_LIMIT = 501
OFFERS_RECAP_LIMIT = 101


AnyCollectiveOffer = educational_models.CollectiveOffer | educational_models.CollectiveOfferTemplate
Expand Down
2 changes: 1 addition & 1 deletion api/src/pcapi/core/offers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

AnyOffer = educational_api_offer.AnyCollectiveOffer | models.Offer

OFFERS_RECAP_LIMIT = 501
OFFERS_RECAP_LIMIT = 101


OFFER_LIKE_MODELS = {
Expand Down
14 changes: 7 additions & 7 deletions api/tests/routes/pro/get_offers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def should_filter_offers_by_given_venue_id(self, mocked_get_capped_offers, clien
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=None,
offers_limit=501,
offers_limit=101,
venue_id=venue.id,
category_id=None,
name_keywords_or_ean=None,
Expand All @@ -81,7 +81,7 @@ def should_filter_offers_by_given_status(self, mocked_get_capped_offers, client)
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=None,
offers_limit=501,
offers_limit=101,
venue_id=None,
category_id=None,
name_keywords_or_ean=None,
Expand Down Expand Up @@ -110,7 +110,7 @@ def should_filter_offers_by_given_offerer_id(self, mocked_get_capped_offers, cli
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=offerer_id,
offers_limit=501,
offers_limit=101,
venue_id=None,
category_id=None,
name_keywords_or_ean=None,
Expand All @@ -137,7 +137,7 @@ def should_filter_offers_by_given_creation_mode(self, mocked_get_capped_offers,
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=None,
offers_limit=501,
offers_limit=101,
venue_id=None,
category_id=None,
name_keywords_or_ean=None,
Expand All @@ -164,7 +164,7 @@ def test_results_are_filtered_by_given_period_beginning_date(self, mocked_get_ca
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=None,
offers_limit=501,
offers_limit=101,
venue_id=None,
category_id=None,
name_keywords_or_ean=None,
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_results_are_filtered_by_given_period_ending_date(self, mocked_get_cappe
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=None,
offers_limit=501,
offers_limit=101,
venue_id=None,
category_id=None,
name_keywords_or_ean=None,
Expand All @@ -268,7 +268,7 @@ def should_filter_offers_by_given_category_id(self, mocked_get_capped_offers, cl
user_id=pro.id,
user_is_admin=pro.has_admin_role,
offerer_id=None,
offers_limit=501,
offers_limit=101,
venue_id=None,
category_id="LIVRE",
name_keywords_or_ean=None,
Expand Down
2 changes: 1 addition & 1 deletion pro/src/commons/core/Offers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ALL_COLLECTIVE_OFFER_TYPE = 'all'
const ALL_EVENT_PERIODS = ''
export const DEFAULT_PAGE = 1
export const NUMBER_OF_OFFERS_PER_PAGE = 10
export const MAX_TOTAL_PAGES = 50
export const MAX_TOTAL_PAGES = 10
export const MAX_OFFERS_TO_DISPLAY = MAX_TOTAL_PAGES * NUMBER_OF_OFFERS_PER_PAGE
export const DEFAULT_SEARCH_FILTERS: SearchFiltersParams = {
nameOrIsbn: ALL_OFFERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('ActionsBar', () => {

renderActionsBar(props)

expect(screen.queryByText('500+ offres sélectionnées')).toBeInTheDocument()
expect(screen.queryByText('100+ offres sélectionnées')).toBeInTheDocument()
})

it('should activate selected offers upon publication', async () => {
Expand Down
2 changes: 1 addition & 1 deletion pro/src/components/OffersTable/OffersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const OffersTable = ({
variant={CalloutVariant.INFO}
className={styles['offers-table-callout']}
>
L’affichage est limité à 500 offres. Modifiez les filtres pour
L’affichage est limité à {MAX_OFFERS_TO_DISPLAY} offres. Modifiez les filtres pour
affiner votre recherche.
</Callout>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MAX_OFFERS_TO_DISPLAY } from 'commons/core/Offers/constants'
import { pluralize } from 'commons/utils/pluralize'

export function computeSelectedOffersLabel(offersLength: number) {
return offersLength > 500
? '500+ offres sélectionnées'
return offersLength > MAX_OFFERS_TO_DISPLAY
? `${MAX_OFFERS_TO_DISPLAY}+ offres sélectionnées`
: `${pluralize(offersLength, 'offre sélectionnée')}`
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,37 +388,37 @@ describe('route CollectiveOffers', () => {
).not.toBeInTheDocument()
})

describe('when 501 offers are fetched', () => {
describe('when 101 offers are fetched', () => {
beforeEach(() => {
offersRecap = Array.from({ length: 501 }, () =>
offersRecap = Array.from({ length: 101 }, () =>
collectiveOfferFactory({ stocks })
)
})

it('should have max number page of 50', async () => {
it('should have max number page of 10', async () => {
vi.spyOn(api, 'getCollectiveOffers').mockResolvedValueOnce(offersRecap)

await renderOffers()

expect(screen.getByText('Page 1/50')).toBeInTheDocument()
expect(screen.getByText('Page 1/10')).toBeInTheDocument()
})

it('should not display the 501st offer', async () => {
it('should not display the 101st offer', async () => {
vi.spyOn(api, 'getCollectiveOffers').mockResolvedValueOnce(offersRecap)
await renderOffers()
const nextIcon = screen.getByRole('button', { name: 'Page suivante' })

for (let i = 1; i < 51; i++) {
for (let i = 1; i < 11; i++) {
await userEvent.click(nextIcon)
}

expect(
screen.getByLabelText(
`Sélectionner l'offre "${offersRecap[499].name}"`
`Sélectionner l'offre "${offersRecap[99].name}"`
)
).toBeInTheDocument()
expect(
screen.queryByText(`Sélectionner l'offre "${offersRecap[500].name}"`)
screen.queryByText(`Sélectionner l'offre "${offersRecap[100].name}"`)
).not.toBeInTheDocument()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('CollectiveOffersScreen', () => {
expect(await screen.findByText('1 offre')).toBeInTheDocument()
})

it('should display 500+ for total number of offers if more than 500 offers are fetched', async () => {
it('should display 100+ for total number of offers if more than 500 offers are fetched', async () => {
offersRecap = Array.from({ length: 501 }, () => collectiveOfferFactory())

renderOffers({
Expand All @@ -192,7 +192,7 @@ describe('CollectiveOffersScreen', () => {
})

screen.getByLabelText(`Sélectionner l'offre "${offersRecap[0].name}"`)
expect(await screen.findByText('500+ offres')).toBeInTheDocument()
expect(await screen.findByText('100+ offres')).toBeInTheDocument()
})

it('should render venue filter with default option selected and given venues as options', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ describe('OfferStats', () => {

renderOfferStats()

expect(await screen.findByText('500+')).toBeInTheDocument()
expect(await screen.findByText('100+')).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ describe('IndividualOffersScreen', () => {
expect(await screen.findByText('1 offre')).toBeInTheDocument()
})

it('should display 500+ for total number of offers if more than 500 offers are fetched', async () => {
offersRecap = Array.from({ length: 501 }, () => listOffersOfferFactory())
it('should display 100+ for total number of offers if more than 500 offers are fetched', async () => {
offersRecap = Array.from({ length: 101 }, () => listOffersOfferFactory())

renderOffers({
...props,
offers: offersRecap,
})

screen.getByLabelText(`Sélectionner l'offre "${offersRecap[0].name}"`)
expect(await screen.findByText('500+ offres')).toBeInTheDocument()
expect(await screen.findByText('100+ offres')).toBeInTheDocument()
})

it('should send correct information when filling filter fields', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ describe('ActionsBar', () => {
})

it('should show a generic count when more than 500 offers are selected', () => {
props.selectedOffers = Array(501)
props.selectedOffers = Array(101)
.fill(null)
.map((val, i) => ({ id: i, status: OfferStatus.ACTIVE }))

renderActionsBar(props)

expect(screen.queryByText('500+ offres sélectionnées')).toBeInTheDocument()
expect(screen.queryByText('100+ offres sélectionnées')).toBeInTheDocument()
})

it('should activate selected offers upon publication', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,38 +682,38 @@ describe('route Offers', () => {
).not.toBeInTheDocument()
})

describe('when 501 offers are fetched', () => {
describe('when 101 offers are fetched', () => {
beforeEach(() => {
offersRecap = Array.from({ length: 501 }, () =>
offersRecap = Array.from({ length: 101 }, () =>
listOffersOfferFactory({ stocks: [] })
)
})

it('should have max number page of 50', async () => {
it('should have max number page of 10', async () => {
vi.spyOn(api, 'listOffers').mockResolvedValueOnce(offersRecap)

await renderOffers()

expect(screen.getByText('Page 1/50')).toBeInTheDocument()
expect(screen.getByText('Page 1/10')).toBeInTheDocument()
})

it('should not display the 501st offer', async () => {
it('should not display the 101st offer', async () => {
vi.spyOn(api, 'listOffers').mockResolvedValueOnce(offersRecap)
await renderOffers()
const nextIcon = screen.getByRole('button', { name: 'Page suivante' })

for (let i = 1; i < 51; i++) {
for (let i = 1; i < 11; i++) {
await userEvent.click(nextIcon)
}

expect(
screen.getByLabelText(
`Sélectionner l'offre "${offersRecap[499].name}"`
`Sélectionner l'offre "${offersRecap[99].name}"`
)
).toBeInTheDocument()
expect(
screen.queryByLabelText(
`Sélectionner l'offre "${offersRecap[500].name}"`
`Sélectionner l'offre "${offersRecap[100].name}"`
)
).not.toBeInTheDocument()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,16 @@ describe('TemplateCollectiveOffersScreen', () => {
expect(await screen.findByText('1 offre')).toBeInTheDocument()
})

it('should display 500+ for total number of offers if more than 500 offers are fetched', async () => {
offersRecap = Array.from({ length: 501 }, () => collectiveOfferFactory())
it('should display 100+ for total number of offers if more than 500 offers are fetched', async () => {
offersRecap = Array.from({ length: 101 }, () => collectiveOfferFactory())

renderOffers({
...props,
offers: offersRecap,
})

screen.getByLabelText(`Sélectionner l'offre "${offersRecap[0].name}"`)
expect(await screen.findByText('500+ offres')).toBeInTheDocument()
expect(await screen.findByText('100+ offres')).toBeInTheDocument()
})

it('should render venue filter with default option selected and given venues as options', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,37 +361,37 @@ describe('route TemplateCollectiveOffers', () => {
).not.toBeInTheDocument()
})

describe('when 501 offers are fetched', () => {
describe('when 101 offers are fetched', () => {
beforeEach(() => {
offersRecap = Array.from({ length: 501 }, () =>
offersRecap = Array.from({ length: 101 }, () =>
collectiveOfferFactory({ stocks })
)
})

it('should have max number page of 50', async () => {
it('should have max number page of 10', async () => {
vi.spyOn(api, 'getCollectiveOffers').mockResolvedValueOnce(offersRecap)

await renderOffers()

expect(screen.getByText('Page 1/50')).toBeInTheDocument()
expect(screen.getByText('Page 1/10')).toBeInTheDocument()
})

it('should not display the 501st offer', async () => {
it('should not display the 101st offer', async () => {
vi.spyOn(api, 'getCollectiveOffers').mockResolvedValueOnce(offersRecap)
await renderOffers()
const nextIcon = screen.getByRole('button', { name: 'Page suivante' })

for (let i = 1; i < 51; i++) {
for (let i = 1; i < 11; i++) {
await userEvent.click(nextIcon)
}

expect(
screen.getByLabelText(
`Sélectionner l'offre "${offersRecap[499].name}"`
`Sélectionner l'offre "${offersRecap[99].name}"`
)
).toBeInTheDocument()
expect(
screen.queryByText(`Sélectionner l'offre "${offersRecap[500].name}"`)
screen.queryByText(`Sélectionner l'offre "${offersRecap[100].name}"`)
).not.toBeInTheDocument()
})
})
Expand Down

0 comments on commit 545903c

Please sign in to comment.