Skip to content

Commit b4156a3

Browse files
authored
refactor: Update Message component stories for responsive layout and fix snapshot tests (#6536)
- Refactored the `responsiveLayoutProviderLargeFontValue` to accept a dynamic font scale. - Wrapped `MessageComponent` in `ResponsiveLayoutContext.Provider` to ensure proper context usage. - Updated snapshot tests to replace NaN values with appropriate dimensions (36 for height and width) for various components. - Ensured that the LoadMore test file correctly unmocked the `useResponsiveLayout` hook for accurate testing.
1 parent 872d8f7 commit b4156a3

File tree

3 files changed

+1038
-1310
lines changed

3 files changed

+1038
-1310
lines changed

app/containers/message/Message.stories.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ const date = new Date(2017, 10, 10, 10);
3434
const longText =
3535
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
3636

37-
const responsiveLayoutProviderLargeFontValue = {
38-
fontScale: FONT_SCALE_LIMIT,
39-
fontScaleLimited: FONT_SCALE_LIMIT,
40-
isLargeFontScale: true,
41-
rowHeight: BASE_ROW_HEIGHT * FONT_SCALE_LIMIT,
42-
rowHeightCondensed: BASE_ROW_HEIGHT_CONDENSED * FONT_SCALE_LIMIT,
37+
const responsiveLayoutProviderLargeFontValue = (fontScale: number) => ({
38+
fontScale,
39+
fontScaleLimited: fontScale,
40+
isLargeFontScale: fontScale > 1,
41+
rowHeight: BASE_ROW_HEIGHT * fontScale,
42+
rowHeightCondensed: BASE_ROW_HEIGHT_CONDENSED * fontScale,
4343
width: 350,
4444
height: 800
45-
};
45+
});
4646

4747
const getCustomEmoji = (content: string) => {
4848
const customEmoji = {
@@ -67,22 +67,24 @@ export default {
6767
};
6868

6969
export const Message = (props: any) => (
70-
<MessageComponent
71-
baseUrl={baseUrl}
72-
user={user}
73-
author={author}
74-
ts={date}
75-
timeFormat='LT'
76-
isHeader
77-
getCustomEmoji={getCustomEmoji}
78-
theme={_theme}
79-
{...props}
80-
/>
70+
<ResponsiveLayoutContext.Provider value={responsiveLayoutProviderLargeFontValue(1)}>
71+
<MessageComponent
72+
baseUrl={baseUrl}
73+
user={user}
74+
author={author}
75+
ts={date}
76+
timeFormat='LT'
77+
isHeader
78+
getCustomEmoji={getCustomEmoji}
79+
theme={_theme}
80+
{...props}
81+
/>
82+
</ResponsiveLayoutContext.Provider>
8183
);
8284

8385
// The large font components are not perfect because the text's font scale increases only with the device's font size setting.
84-
export const MessageLargeFont = (props: any) => (
85-
<ResponsiveLayoutContext.Provider value={responsiveLayoutProviderLargeFontValue}>
86+
const MessageLargeFont = (props: any) => (
87+
<ResponsiveLayoutContext.Provider value={responsiveLayoutProviderLargeFontValue(FONT_SCALE_LIMIT)}>
8688
<MessageComponent
8789
baseUrl={baseUrl}
8890
user={user}

0 commit comments

Comments
 (0)