Skip to content

Commit f4f74ef

Browse files
committed
Merge branch 'V8' of github.com:GetStream/stream-chat-react-native into draft-message
2 parents c55c654 + aadd78f commit f4f74ef

File tree

4 files changed

+19
-45
lines changed

4 files changed

+19
-45
lines changed

package/src/components/MessageInput/CommandsButton.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ import { Lightning } from '../../icons/Lightning';
99
export type CommandsButtonProps = {
1010
/** Function that opens commands selector. */
1111
handleOnPress?: PressableProps['onPress'];
12-
/**
13-
* Determines if the text input has text
14-
*/
15-
hasText?: boolean;
1612
};
1713

1814
export const CommandsButton = (props: CommandsButtonProps) => {
19-
const { handleOnPress, hasText } = props;
15+
const { handleOnPress } = props;
2016
const messageComposer = useMessageComposer();
2117
const { textComposer } = messageComposer;
2218

@@ -45,10 +41,6 @@ export const CommandsButton = (props: CommandsButtonProps) => {
4541
},
4642
} = useTheme();
4743

48-
if (hasText) {
49-
return null;
50-
}
51-
5244
return (
5345
<Pressable onPress={onPressHandler} style={[commandsButton]} testID='commands-button'>
5446
<Lightning fill={grey} size={32} />

package/src/components/MessageInput/InputButtons.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const InputButtonsWithContext = (props: InputButtonsWithContextProps) =>
7676

7777
const hasAttachmentUploadCapabilities =
7878
(hasCameraPicker || hasFilePicker || hasImagePicker) && ownCapabilitiesUploadFile;
79+
const showCommandsButton = hasCommands && !hasText;
7980

8081
if (command) {
8182
return null;
@@ -96,7 +97,7 @@ export const InputButtonsWithContext = (props: InputButtonsWithContextProps) =>
9697
<AttachButton />
9798
</View>
9899
) : null}
99-
{hasCommands ? <CommandsButton hasText={hasText} /> : null}
100+
{showCommandsButton ? <CommandsButton /> : null}
100101
</>
101102
);
102103
};

package/src/components/MessageInput/__tests__/CommandsButton.test.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,8 @@ describe('CommandsButton', () => {
3131
channel = channels[0];
3232
});
3333

34-
it('should not render component when hasText is true', async () => {
35-
const props = { hasText: true };
36-
renderComponent({ channel, client, props });
37-
38-
const { queryByTestId } = screen;
39-
40-
await waitFor(() => {
41-
expect(queryByTestId('commands-button')).toBeFalsy();
42-
});
43-
});
44-
45-
it('should render component when hasText is false', async () => {
46-
const props = { hasText: false };
34+
it('should render component', async () => {
35+
const props = {};
4736
renderComponent({ channel, client, props });
4837

4938
const { queryByTestId } = screen;
@@ -73,26 +62,4 @@ describe('CommandsButton', () => {
7362
expect(handleOnPress).toHaveBeenCalled();
7463
});
7564
});
76-
77-
it('should call textComposer handleChange when the button is clicked by default', async () => {
78-
const props = {};
79-
80-
renderComponent({ channel, client, props });
81-
82-
const { getByTestId, queryByTestId } = screen;
83-
84-
await waitFor(() => {
85-
expect(queryByTestId('commands-button')).toBeTruthy();
86-
});
87-
88-
await act(() => {
89-
userEvent.press(getByTestId('commands-button'));
90-
});
91-
92-
await waitFor(() => {
93-
expect(channel.messageComposer.textComposer.text).toBe('/');
94-
expect(channel.messageComposer.textComposer.selection.start).toBe(1);
95-
expect(channel.messageComposer.textComposer.selection.end).toBe(1);
96-
});
97-
});
9865
});

package/src/components/MessageInput/__tests__/InputButtons.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ describe('InputButtons', () => {
132132
});
133133
});
134134

135+
it('should not show commands buttons when there is text in the textComposer', async () => {
136+
const props = {};
137+
const channelProps = {
138+
channel,
139+
};
140+
channel.messageComposer.textComposer.setText('hello');
141+
renderComponent({ channelProps, client, props });
142+
const { queryByTestId } = screen;
143+
144+
await waitFor(() => {
145+
expect(queryByTestId('commands-button')).toBeFalsy();
146+
});
147+
});
148+
135149
it('should show more options button when there is text in the textComposer', async () => {
136150
const props = {};
137151
const channelProps = {

0 commit comments

Comments
 (0)