Skip to content

Commit

Permalink
fix: same comparison in transport integration (#761)
Browse files Browse the repository at this point in the history
* fix: same comparison in transport integration

* review
  • Loading branch information
desoindx authored Dec 16, 2024
1 parent f41900a commit 2b6fdc1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/components/shareable/overScreens/TransportComparison.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useTranslations } from 'next-intl'
import { Dispatch, SetStateAction, useEffect, useMemo } from 'react'
import { ComputedEquivalent } from 'types/equivalent'
import { computedEquivalents } from 'data/categories/computedEquivalents'
import { deplacements } from 'data/categories/deplacement'
import { getEquivalentWithCarpool } from 'utils/carpool'
Expand All @@ -9,6 +10,24 @@ import styles from './TransportListParam.module.css'

const equivalents = computedEquivalents('transport', deplacements).flatMap(getEquivalentWithCarpool)

const findNextEquivalent = (equivalents: ComputedEquivalent[], comparison: string) => {
const [slug] = comparison.split('+')
let equivalent = equivalents.find((equivalent) => {
const [equivalentSlug] = equivalent.slug.split('+')
return slug !== equivalentSlug
})
if (equivalent) {
return equivalent.slug
}

equivalent = equivalents.find((equivalent) => slug !== equivalent.slug)
if (equivalent) {
return equivalent.slug
}

return equivalents[0].slug
}

const TransportComparison = ({
comparison,
setComparison,
Expand Down Expand Up @@ -47,9 +66,9 @@ const TransportComparison = ({
if (!equivalent1 && !equivalent2) {
setComparison([filteredEquivalents[0].slug, filteredEquivalents[1].slug])
} else if (!equivalent1) {
setComparison([filteredEquivalents[0].slug, comparison[1]])
setComparison([findNextEquivalent(filteredEquivalents, comparison[1]), comparison[1]])
} else if (!equivalent2) {
setComparison([comparison[0], filteredEquivalents[1].slug])
setComparison([comparison[0], findNextEquivalent(filteredEquivalents, comparison[0])])
}
}, [equivalent1, equivalent2])

Expand Down
2 changes: 1 addition & 1 deletion teste/distance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const distanceTest = async (page: Page | FrameLocator, prod?: boolean) =>
await page.locator('span').filter({ hasText: /^TER$/ }).nth(2).click()
await page.getByLabel('Intégrer').getByText('Covoiturage thermique', { exact: true }).click()
await expect(page.getByTestId('clipboard-box')).toHaveText(
`<script name="impact-co2" src="${prod ? 'https://impactco2.fr' : 'http://localhost:3000'}/iframe.js" data-type="transport/itineraire" data-search="?theme=default&language=fr&tabs=distance&km=1000&defaultMode=comparison&comparison=voiturethermique,avion&modes=avion,intercites,voiturethermique,voitureelectrique+1,voitureelectrique,autocar,velo,veloelectrique,busthermique,tramway,metro,scooter,moto,rer,buselectrique,trottinette,busgnv"></script>`
`<script name="impact-co2" src="${prod ? 'https://impactco2.fr' : 'http://localhost:3000'}/iframe.js" data-type="transport/itineraire" data-search="?theme=default&language=fr&tabs=distance&km=1000&defaultMode=comparison&comparison=voiturethermique,autocar&modes=avion,intercites,voiturethermique,voitureelectrique+1,voitureelectrique,autocar,velo,veloelectrique,busthermique,tramway,metro,scooter,moto,rer,buselectrique,trottinette,busgnv"></script>`
)
await page.getByTestId('text-select-comparison-1').selectOption('velo')
await page.getByTestId('text-select-comparison-2').selectOption('moto')
Expand Down

0 comments on commit 2b6fdc1

Please sign in to comment.