Skip to content

Commit

Permalink
feat(chat/polls/native): added ids for tests (#14994)
Browse files Browse the repository at this point in the history
* feat(chat/polls/navigation): added ids for tests and removed some unused helpers
  • Loading branch information
Calinteodor committed Aug 12, 2024
1 parent ceeea7a commit 22cca16
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 62 deletions.
1 change: 1 addition & 0 deletions react/features/base/react/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface IIconButtonProps {
accessibilityLabel?: string;
color?: string;
disabled?: boolean;
id?: string;
onPress?: (e?: GestureResponderEvent) => void;
size?: number | string;
src: Function;
Expand Down
21 changes: 12 additions & 9 deletions react/features/base/ui/components/native/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { TouchableHighlight } from 'react-native';
import { StyleProp, TouchableHighlight } from 'react-native';
import { Button as NativePaperButton, Text } from 'react-native-paper';
import { IconSource } from 'react-native-paper/lib/typescript/components/Icon';

import { BUTTON_MODES, BUTTON_TYPES } from '../../constants.native';
import BaseTheme from '../BaseTheme.native';
Expand All @@ -13,6 +14,7 @@ import styles from './buttonStyles';
export interface IProps extends IButtonProps {
color?: string | undefined;
contentStyle?: Object | undefined;
id?: string;
labelStyle?: Object | undefined;
mode?: any;
style?: Object | undefined;
Expand All @@ -24,6 +26,7 @@ const Button: React.FC<IProps> = ({
contentStyle,
disabled,
icon,
id,
labelKey,
labelStyle,
mode = BUTTON_MODES.CONTAINED,
Expand Down Expand Up @@ -74,16 +77,17 @@ const Button: React.FC<IProps> = ({
<TouchableHighlight
accessibilityLabel = { accessibilityLabel }
disabled = { disabled }
id = { id }
onPress = { onPress }
style = { [
buttonStyles,
style
] }>
] as StyleProp<object> }>
<Text
style = { [
buttonLabelStyles,
labelStyle
] }>{ t(labelKey ?? '') }</Text>
] as StyleProp<object> }>{ t(labelKey ?? '') }</Text>
</TouchableHighlight>
);
}
Expand All @@ -96,21 +100,20 @@ const Button: React.FC<IProps> = ({
contentStyle = { [
styles.buttonContent,
contentStyle
] }
] as StyleProp<object> }
disabled = { disabled }

// @ts-ignore
icon = { icon }
icon = { icon as IconSource | undefined }
id = { id }
labelStyle = { [
buttonLabelStyles,
labelStyle
] }
] as StyleProp<object> }
mode = { mode }
onPress = { onPress }
style = { [
buttonStyles,
style
] } />
] as StyleProp<object> } />
);
};

Expand Down
2 changes: 2 additions & 0 deletions react/features/base/ui/components/native/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const IconButton: React.FC<IIconButtonProps> = ({
accessibilityLabel,
color: iconColor,
disabled,
id,
onPress,
size,
src,
Expand Down Expand Up @@ -52,6 +53,7 @@ const IconButton: React.FC<IIconButtonProps> = ({
<TouchableHighlight
accessibilityLabel = { accessibilityLabel }
disabled = { disabled }
id = { id }
onPress = { onPress }
style = { [
iconButtonContainerStyles,
Expand Down
12 changes: 10 additions & 2 deletions react/features/base/ui/components/native/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ColorValue } from 'react-native';
import { ColorValue, StyleProp } from 'react-native';
import { Switch as NativeSwitch } from 'react-native-paper';

import { ISwitchProps } from '../types';
Expand All @@ -12,6 +12,12 @@ import {

interface IProps extends ISwitchProps {

/**
* Id for the switch.
*/

id?: string;

/**
* Custom styles for the switch.
*/
Expand All @@ -31,6 +37,7 @@ interface IProps extends ISwitchProps {
const Switch = ({
checked,
disabled,
id,
onChange,
thumbColor = THUMB_COLOR,
trackColor = {
Expand All @@ -41,9 +48,10 @@ const Switch = ({
}: IProps) => (
<NativeSwitch
disabled = { disabled }
id = { id }
ios_backgroundColor = { DISABLED_TRACK_COLOR }
onValueChange = { onChange }
style = { style }
style = { style as StyleProp<object> }
thumbColor = { thumbColor }
trackColor = { trackColor }
value = { checked } />
Expand Down
3 changes: 3 additions & 0 deletions react/features/chat/components/native/ChatInputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ class ChatInputBar extends Component<IProps, IState> {

return (
<View
id = 'chat-input'
style = { [
inputBarStyles,
this.state.addPadding ? styles.extraBarPadding : null
] as ViewStyle[] }>
<Input
blurOnSubmit = { false }
customStyles = {{ container: styles.customInputContainer }}
id = 'chat-input-messagebox'
multiline = { false }
onBlur = { this._onFocused(false) }
onChange = { this._onChangeText }
Expand All @@ -101,6 +103,7 @@ class ChatInputBar extends Component<IProps, IState> {
value = { this.state.message } />
<IconButton
disabled = { !this.state.message }
id = { this.props.t('chat.sendButton') }
onPress = { this._onSubmit }
src = { IconSend }
type = { BUTTON_TYPES.PRIMARY } />
Expand Down
4 changes: 3 additions & 1 deletion react/features/chat/components/native/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class ChatMessage extends Component<IChatMessageProps> {
const messageText = getMessageText(this.props.message);

return (
<View style = { styles.messageWrapper as ViewStyle } >
<View
id = { message.messageId }
style = { styles.messageWrapper as ViewStyle } >
{ this._renderAvatar() }
<View style = { detailsWrapperStyle }>
<View style = { messageBubbleStyle }>
Expand Down
1 change: 1 addition & 0 deletions react/features/chat/components/native/GifMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const GifMessage = ({ message }: IProps) => {
const url = message.substring(GIF_PREFIX.length, message.length - 1);

return (<View
id = 'gif-message'
style = { styles.gifContainer }>
<Image
source = {{ uri: url }}
Expand Down
4 changes: 3 additions & 1 deletion react/features/chat/components/native/MessageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class MessageContainer extends AbstractMessageContainer<IProps, any> {
const { t } = this.props;

return (
<View style = { styles.emptyComponentWrapper as ViewStyle }>
<View
id = 'no-messages-message'
style = { styles.emptyComponentWrapper as ViewStyle }>
<Text style = { styles.emptyComponentText as TextStyle }>
{ t('chat.noMessagesMessage') }
</Text>
Expand Down
9 changes: 7 additions & 2 deletions react/features/chat/components/native/MessageRecipient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class MessageRecipient extends AbstractMessageRecipient<IProps> {

if (isLobbyChatActive) {
return (
<View style = { styles.lobbyMessageRecipientContainer as ViewStyle }>
<View
id = 'chat-recipient'
style = { styles.lobbyMessageRecipientContainer as ViewStyle }>
<Text style = { styles.messageRecipientText }>
{ t('chat.lobbyChatMessageTo', {
recipient: lobbyMessageRecipient?.name
Expand All @@ -123,13 +125,16 @@ class MessageRecipient extends AbstractMessageRecipient<IProps> {
}

return (
<View style = { styles.messageRecipientContainer as ViewStyle }>
<View
id = 'message-recipient'
style = { styles.messageRecipientContainer as ViewStyle }>
<Text style = { styles.messageRecipientText }>
{ t('chat.messageTo', {
recipient: privateMessageRecipient.name
}) }
</Text>
<TouchableHighlight
id = 'message-recipient-cancel-button'
onPress = { this._onResetPrivateMessageRecipient }
underlayColor = { 'transparent' }>
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ interface IProps {
*/
disabled?: boolean;

/**
* ID of the header navigation button.
*/
id?: string;

/**
* Label of the button.
*/
Expand All @@ -47,7 +52,7 @@ interface IProps {
twoActions?: boolean;
}

const HeaderNavigationButton = ({ color, disabled, label, onPress, src, style, twoActions }: IProps) => {
const HeaderNavigationButton = ({ color, id, disabled, label, onPress, src, style, twoActions }: IProps) => {

let btnStyle;
let labelStyle;
Expand All @@ -70,6 +75,7 @@ const HeaderNavigationButton = ({ color, disabled, label, onPress, src, style, t
src ? (
<IconButton
color = { color }
id = { id }
onPress = { onPress }
size = { 24 }
src = { src }
Expand All @@ -80,6 +86,7 @@ const HeaderNavigationButton = ({ color, disabled, label, onPress, src, style, t
) : (
<Button
disabled = { disabled }
id = { id }
labelKey = { label }
labelStyle = { labelStyle }
onClick = { onPress }
Expand Down
21 changes: 0 additions & 21 deletions react/features/mobile/navigation/components/welcome/functions.tsx

This file was deleted.

26 changes: 5 additions & 21 deletions react/features/mobile/navigation/functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getFeatureFlag } from '../../base/flags/functions';
import { IconCloseLarge } from '../../base/icons/svg';
import { toState } from '../../base/redux/functions';
import { cancelKnocking } from '../../lobby/actions.native';
import { isPrejoinEnabledInConfig } from '../../prejoin/functions';
import { isPrejoinEnabledInConfig } from '../../prejoin/functions.native';

import HeaderNavigationButton from './components/HeaderNavigationButton';

Expand All @@ -28,13 +28,15 @@ export function screenHeaderCloseButton(goBack: (e?: GestureResponderEvent | Rea
if (Platform.OS === 'ios') {
return (
<HeaderNavigationButton
id = { 'close-screen-button' }
label = { t('dialog.close') }
onPress = { goBack } />
);
}

return (
<HeaderNavigationButton
id = { 'close-screen-button' }
onPress = { goBack }
src = { IconCloseLarge } />
);
Expand Down Expand Up @@ -71,34 +73,16 @@ export function lobbyScreenHeaderCloseButton() {
if (Platform.OS === 'ios') {
return (
<HeaderNavigationButton
id = { 'close-screen-button' }
label = { t('dialog.close') }
onPress = { goBack } />
);
}

return (
<HeaderNavigationButton
id = { 'close-screen-button' }
onPress = { goBack }
src = { IconCloseLarge } />
);
}

/**
* Returns true if we should auto-knock in case prejoin is enabled for the room.
*
* @param {Function|Object} stateful - The redux state or {@link getState}
* function.
* @returns {boolean}
*/
export function shouldEnableAutoKnock(stateful: IStateful) {
const state = toState(stateful);
const { displayName } = state['features/base/settings'];

if (isPrejoinPageEnabled(state)) {
if (displayName) {
return true;
}
} else {
return false;
}
}
9 changes: 8 additions & 1 deletion react/features/polls/components/native/PollAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const PollAnswer = (props: AbstractProps) => {
src = { IconCloseLarge } />
}
</View>
<View style = { pollsStyles.answerContent as ViewStyle }>
<View
id = 'answer-content'
style = { pollsStyles.answerContent as ViewStyle }>
{
poll.answers.map((answer, index: number) => (
<View
Expand All @@ -59,6 +61,7 @@ const PollAnswer = (props: AbstractProps) => {
<Switch
checked = { checkBoxStates[index] }
disabled = { poll.saved }
id = 'answer-switch'
onChange = { state => setCheckbox(index, state) } />
<Text style = { pollsStyles.switchLabel as TextStyle }>
{ answer.name }
Expand All @@ -72,6 +75,7 @@ const PollAnswer = (props: AbstractProps) => {
? <View style = { pollsStyles.buttonRow as ViewStyle }>
<Button
accessibilityLabel = 'polls.answer.edit'
id = { t('polls.answer.edit') }
labelKey = 'polls.answer.edit'
onClick = { () => {
setCreateMode(true);
Expand All @@ -81,6 +85,7 @@ const PollAnswer = (props: AbstractProps) => {
type = { SECONDARY } />
<Button
accessibilityLabel = 'polls.answer.send'
id = { t('polls.answer.send') }
labelKey = 'polls.answer.send'
onClick = { sendPoll }
style = { pollsStyles.pollCreateButton }
Expand All @@ -89,13 +94,15 @@ const PollAnswer = (props: AbstractProps) => {
: <View style = { pollsStyles.buttonRow as ViewStyle }>
<Button
accessibilityLabel = 'polls.answer.skip'
id = { t('polls.answer.skip') }
labelKey = 'polls.answer.skip'
onClick = { changingVote ? skipChangeVote : skipAnswer }
style = { pollsStyles.pollCreateButton }
type = { SECONDARY } />
<Button
accessibilityLabel = 'polls.answer.submit'
disabled = { isSubmitAnswerDisabled(checkBoxStates) }
id = { t('polls.answer.submit') }
labelKey = 'polls.answer.submit'
onClick = { submitAnswer }
style = { pollsStyles.pollCreateButton }
Expand Down
Loading

0 comments on commit 22cca16

Please sign in to comment.