Skip to content

Commit caa9ee8

Browse files
committed
Hotfix for the failing LightboxTest.tsx after the merge of context split
1 parent 87ce5ef commit caa9ee8

1 file changed

Lines changed: 41 additions & 30 deletions

File tree

tests/unit/LightboxTest.tsx

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {fireEvent, render, screen} from '@testing-library/react-native';
22
import React from 'react';
33
import type {View as RNView} from 'react-native';
44
import type {SharedValue} from 'react-native-reanimated';
5-
import AttachmentCarouselPagerContext from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
6-
import type {AttachmentCarouselPagerContextValue} from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
5+
import {AttachmentCarouselPagerActionsContext, AttachmentCarouselPagerStateContext} from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
6+
import type {AttachmentCarouselPagerActionsContextType, AttachmentCarouselPagerStateContextType} from '@components/Attachments/AttachmentCarousel/Pager/AttachmentCarouselPagerContext';
77
import Lightbox from '@components/Lightbox';
88
import CONST from '@src/CONST';
99
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
@@ -65,27 +65,38 @@ function createPagerItems(count: number) {
6565
}));
6666
}
6767

68-
function createContextValue(activePage: number, itemCount: number): AttachmentCarouselPagerContextValue {
68+
type ContextValues = {
69+
stateValue: AttachmentCarouselPagerStateContextType;
70+
actionsValue: AttachmentCarouselPagerActionsContextType;
71+
};
72+
73+
function createContextValues(activePage: number, itemCount: number): ContextValues {
6974
return {
70-
pagerItems: createPagerItems(itemCount),
71-
activePage,
72-
isPagerScrolling: createSharedValue(false),
73-
isScrollEnabled: createSharedValue(true),
74-
pagerRef: {current: null},
75-
onTap: jest.fn(),
76-
onScaleChanged: jest.fn(),
77-
onSwipeDown: jest.fn(),
75+
stateValue: {
76+
pagerItems: createPagerItems(itemCount),
77+
activePage,
78+
isPagerScrolling: createSharedValue(false),
79+
isScrollEnabled: createSharedValue(true),
80+
pagerRef: {current: null},
81+
},
82+
actionsValue: {
83+
onTap: jest.fn(),
84+
onScaleChanged: jest.fn(),
85+
onSwipeDown: jest.fn(),
86+
},
7887
};
7988
}
8089

81-
async function renderLightboxInCarousel(attachmentID: string, uri: string, contextValue: AttachmentCarouselPagerContextValue) {
90+
async function renderLightboxInCarousel(attachmentID: string, uri: string, contextValues: ContextValues) {
8291
render(
83-
<AttachmentCarouselPagerContext.Provider value={contextValue}>
84-
<Lightbox
85-
attachmentID={attachmentID}
86-
uri={uri}
87-
/>
88-
</AttachmentCarouselPagerContext.Provider>,
92+
<AttachmentCarouselPagerStateContext.Provider value={contextValues.stateValue}>
93+
<AttachmentCarouselPagerActionsContext.Provider value={contextValues.actionsValue}>
94+
<Lightbox
95+
attachmentID={attachmentID}
96+
uri={uri}
97+
/>
98+
</AttachmentCarouselPagerActionsContext.Provider>
99+
</AttachmentCarouselPagerStateContext.Provider>,
89100
);
90101

91102
await waitForBatchedUpdatesWithAct();
@@ -100,25 +111,25 @@ async function renderLightboxInCarousel(attachmentID: string, uri: string, conte
100111
describe('Lightbox', () => {
101112
describe('fallback rendering range', () => {
102113
it('should not render any image for distant pages outside FALLBACK_OFFSET range', async () => {
103-
const contextValue = createContextValue(15, 30);
114+
const contextValues = createContextValues(15, 30);
104115

105-
await renderLightboxInCarousel('attachment-0', TEST_URI, contextValue);
116+
await renderLightboxInCarousel('attachment-0', TEST_URI, contextValues);
106117

107118
expect(screen.queryAllByTestId('image')).toHaveLength(0);
108119
});
109120

110121
it('should render fallback image for pages within FALLBACK_OFFSET range', async () => {
111-
const contextValue = createContextValue(15, 30);
122+
const contextValues = createContextValues(15, 30);
112123

113-
await renderLightboxInCarousel('attachment-13', TEST_URI, contextValue);
124+
await renderLightboxInCarousel('attachment-13', TEST_URI, contextValues);
114125

115126
expect(screen.getAllByTestId('image').length).toBeGreaterThan(0);
116127
});
117128

118129
it('should render lightbox image for the active page', async () => {
119-
const contextValue = createContextValue(15, 30);
130+
const contextValues = createContextValues(15, 30);
120131

121-
await renderLightboxInCarousel('attachment-15', TEST_URI, contextValue);
132+
await renderLightboxInCarousel('attachment-15', TEST_URI, contextValues);
122133

123134
expect(screen.getByTestId('multi-gesture-canvas')).toBeTruthy();
124135
expect(screen.getAllByTestId('image').length).toBeGreaterThan(0);
@@ -127,9 +138,9 @@ describe('Lightbox', () => {
127138

128139
describe('image priority', () => {
129140
it('should assign HIGH priority to the active page image', async () => {
130-
const contextValue = createContextValue(5, 30);
141+
const contextValues = createContextValues(5, 30);
131142

132-
await renderLightboxInCarousel('attachment-5', TEST_URI, contextValue);
143+
await renderLightboxInCarousel('attachment-5', TEST_URI, contextValues);
133144

134145
const images = screen.getAllByTestId('image');
135146
expect(images.length).toBeGreaterThan(0);
@@ -139,9 +150,9 @@ describe('Lightbox', () => {
139150
});
140151

141152
it('should assign NORMAL priority to non-active pages within the lightbox visible range', async () => {
142-
const contextValue = createContextValue(5, 30);
153+
const contextValues = createContextValues(5, 30);
143154

144-
await renderLightboxInCarousel('attachment-4', TEST_URI, contextValue);
155+
await renderLightboxInCarousel('attachment-4', TEST_URI, contextValues);
145156

146157
const images = screen.getAllByTestId('image');
147158
expect(images.length).toBeGreaterThan(0);
@@ -151,9 +162,9 @@ describe('Lightbox', () => {
151162
});
152163

153164
it('should assign LOW priority to fallback images outside the lightbox window', async () => {
154-
const contextValue = createContextValue(15, 30);
165+
const contextValues = createContextValues(15, 30);
155166

156-
await renderLightboxInCarousel('attachment-13', TEST_URI, contextValue);
167+
await renderLightboxInCarousel('attachment-13', TEST_URI, contextValues);
157168

158169
const images = screen.getAllByTestId('image');
159170
expect(images.length).toBeGreaterThan(0);

0 commit comments

Comments
 (0)