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

(PC-34196) feat(carousel): create custom carousel to replace carousel lib #7603

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

tprache-pass
Copy link
Contributor

@tprache-pass tprache-pass commented Jan 29, 2025

Link to JIRA ticket: https://passculture.atlassian.net/browse/PC-34196

Flakiness

If I had to re-run tests in the CI due to flakiness, I add the incident on Notion

Checklist

I have:

  • Made sure my feature is working on web.
  • Made sure my feature is working on mobile (depending on relevance : real or virtual devices)
  • Written unit tests native (and web when implementation is different) for my feature.
  • Added a screenshot for UI tickets or deleted the screenshot section if no UI change
  • If my PR is a bugfix, I add the link of the "résolution de problème sur le bug" on Notion
  • I am aware of all the best practices and respected them.

Screenshots

delete if no UI change

Platform Mockup/Before After
iOS
Simulator.Screen.Recording.-.iPhone.13.mini.-.2025-01-29.at.18.07.14.mp4
Android
Phone - Chrome
Enregistrement.de.l.ecran.2025-01-29.a.18.12.19.mov
Enregistrement.de.l.ecran.2025-01-29.a.18.09.59.mov
Desktop - Chrome
Enregistrement.de.l.ecran.2025-01-29.a.18.12.42.mov
Enregistrement.de.l.ecran.2025-01-29.a.18.09.22.mov

Best Practices

Click to expand These rules apply to files that you make changes to. If you can't respect one of these rules, be sure to explain why with a comment. If you consider correcting the issue is too time consuming/complex: create a ticket. Link the ticket in the code.
  • In the production code: remove type assertions with as (type assertions are removed at compile-time, there is no runtime checking associated with a type assertion. There won’t be an exception or null generated if the type assertion is wrong). In certain cases as const is acceptable (for example when defining readonly arrays/objects). Using as in tests is tolerable.
  • Remove bypass type checking with any (when you want to accept anything because you will be blindly passing it through without interacting with it, you can use unknown). Using any in tests is tolerable.
  • Remove non-null assertion operators (just like other type assertions, this doesn’t change the runtime behavior of your code, so it’s important to only use ! when you know that the value can’t be null or undefined).
  • Remove all @ts-expect-error and @eslint-disable.
  • Remove all warnings, and errors that we are used to ignore (yarn test:lint, yarn test:types, yarn start:web...).
  • Use gap (ViewGap) instead of <Spacer.Column />, <Spacer.Row /> or <Spacer.Flex />.
  • Don't add new "alias hooks" (hooks created to group other hooks together). When adding new logic, this hook will progressively become more complex and harder to maintain.
  • Remove logic from components that should be dumb.

Test specific:

  • Avoid mocking internal parts of our code. Ideally, mock only external calls.
  • When you see a local variable that is over-written in every test, mock it.
  • Prefer user to fireEvent.
  • When mocking feature flags, use setFeatureFlags. If not possible, mention which one(s) you want to mock in a comment (example: jest.spyOn(useFeatureFlagAPI, 'useFeatureFlag').mockReturnValue(true) // WIP_NEW_OFFER_TILE in renderPassPlaylist.tsx )
  • In component tests, replace await act(async () => {}) and await waitFor(/* ... */) by await screen.findBySomething().
  • In hooks tests, use act by default and waitFor as a last resort.
  • Make a snapshot test for pages and modals ONLY.
  • Make a web specific snapshot when your web page/modal is specific to the web.
  • Make an a11y test for web pages.

Advice:

  • Use TDD
  • Use Storybook
  • Use pair programming/mobs

@tprache-pass tprache-pass force-pushed the pc-34196/replace-carousel branch 2 times, most recently from 4328791 to f08c2cc Compare February 14, 2025 16:14
@tprache-pass tprache-pass marked this pull request as ready for review February 14, 2025 16:15
@tprache-pass tprache-pass force-pushed the pc-34196/replace-carousel branch from 8c34140 to d02ca97 Compare February 17, 2025 14:12
@tprache-pass tprache-pass added the preview Triggers a deployment to testing (firebase) label Feb 17, 2025
@@ -83,7 +83,8 @@ function renderOfferContent({
)
}

describe('<OfferContent />', () => {
// TODO(PC-34650) : react-native-web bump needed becasue of "setNativeProps is deprecated" warning making the test to fail
describe.skip('<OfferContent />', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint.disable ?

@@ -8,7 +8,8 @@ jest.mock('libs/firebase/remoteConfig/remoteConfig.services')

const mockOnPress = jest.fn()

describe('<OfferImageContainer />', () => {
// TODO(PC-34650) : react-native-web bump needed becasue of "setNativeProps is deprecated" warning making the test to fail
describe.skip('<OfferImageContainer />', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint.disable ?

@@ -60,7 +60,8 @@ jest.mock('api/useSearchVenuesOffer/useSearchVenueOffers', () => ({
jest.mock('libs/firebase/analytics/analytics')
jest.mock('libs/firebase/remoteConfig/remoteConfig.services')

describe('<Offer/>', () => {
// TODO(PC-34650) : react-native-web bump needed becasue of "setNativeProps is deprecated" warning making the test to fail
describe.skip('<Offer/>', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint.disable ?


type CarouselProps = {
data: unknown[]
// We use any on purpose in this file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui mais pourquoi ?

Comment on lines 22 to 28
it('should not display pagination with dots and buttons', () => {
render(
<OfferImageCarouselPagination
progressValue={{ value: 0 }}
progressValue={PROGRESS_VALUE}
offerImages={['image1', 'image2']}
handlePressButton={jest.fn()}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne comprends pas la pertinence de ce test, j'ai l'impression que l'on veut tester dans un test natif que l'on n'affiche pas le composant web ?
Ton premier test me semble suffisant 🙂

Comment on lines 26 to 32
it('should not display pagination with only dots', () => {
render(
<OfferImageCarouselPagination
progressValue={{ value: 0 }}
progressValue={PROGRESS_VALUE}
offerImages={['image1', 'image2']}
handlePressButton={mockHandlePressButton}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil ici, ce test semble vérifier que l'on affiche pas le composant natif, je pense que l'on peut s'en passer 🙂

const onViewableItemsChanged = ({
viewableItems,
}: {
changed: ViewToken[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cette props ne semble plus être d'actualité 🙂

bounces={false}
pagingEnabled
viewabilityConfigCallbackPairs={
viewabilityConfigCallbackPairs.current as ViewabilityConfigCallbackPairs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j'ai l'impression que l'on peut se passer de as 🤔

@imouandjolobe-pass
Copy link
Contributor

data: unknown[]
// We use any on purpose in this file
// eslint-disable-next-line @typescript-eslint/no-explicit-any
renderItem: ({ item, index }: { item: any; index: number }) => any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en utilisant les alias de types on peut pas enlever les "any" ?

@tprache-pass tprache-pass force-pushed the pc-34196/replace-carousel branch from d02ca97 to 544458b Compare February 24, 2025 12:58
Copy link

Visit the preview URL for this PR (updated for commit 544458b):

https://pc-native-testing--pr7603-pc-34196-replace-car-3p3y499k.web.app

(expires Thu, 27 Feb 2025 13:02:14 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 54dd253190f9fbd3911a4f3fbe0f3af45c56e75f

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
80.0% Coverage on New Code (required ≥ 85%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Triggers a deployment to testing (firebase)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants