Skip to content

Commit

Permalink
fix: add datatestid for radio button in PanelIconButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Nov 26, 2024
1 parent d2dd98c commit 7d81fd1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
4 changes: 4 additions & 0 deletions ts/components/buttons/PanelRadioButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components';
import { SessionDataTestId } from 'react';
import { SessionRadio } from '../basic/SessionRadio';
import { PanelButton, PanelButtonProps, PanelButtonText, StyledContent } from './PanelButton';

Expand All @@ -20,6 +21,7 @@ interface PanelRadioButtonProps extends Omit<PanelButtonProps, 'children' | 'onC
isSelected: boolean;
onSelect?: (...args: Array<any>) => void;
onUnselect?: (...args: Array<any>) => void;
radioInputDataTestId: SessionDataTestId;
}

export const PanelRadioButton = (props: PanelRadioButtonProps) => {
Expand All @@ -32,6 +34,7 @@ export const PanelRadioButton = (props: PanelRadioButtonProps) => {
onUnselect,
disabled = false,
dataTestId,
radioInputDataTestId,
} = props;

return (
Expand All @@ -51,6 +54,7 @@ export const PanelRadioButton = (props: PanelRadioButtonProps) => {
inputName={value}
label=""
disabled={disabled}
inputDataTestId={radioInputDataTestId}
/>
</StyledCheckContainer>
</StyledContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { SessionDataTestId } from 'react';
import { DisappearingMessageConversationModeType } from '../../../../../session/disappearing_messages/types';
import { Localizer } from '../../../../basic/Localizer';
import { PanelButtonGroup, PanelLabel } from '../../../../buttons/PanelButton';
import { PanelRadioButton } from '../../../../buttons/PanelRadioButton';

function toDataTestId(mode: DisappearingMessageConversationModeType): SessionDataTestId {
function toDataTestId(mode: DisappearingMessageConversationModeType) {
switch (mode) {
case 'legacy':
return 'disappear-legacy-option';
return 'disappear-legacy-option' as const;
case 'deleteAfterRead':
return 'disappear-after-read-option';
return 'disappear-after-read-option' as const;
case 'deleteAfterSend':
return 'disappear-after-send-option';
return 'disappear-after-send-option' as const;
case 'off':
default:
return 'disappear-off-option';
return 'disappear-off-option' as const;
}
}

Expand Down Expand Up @@ -57,6 +56,7 @@ export const DisappearingModes = (props: DisappearingModesProps) => {
: mode === 'deleteAfterSend'
? window.i18n('disappearingMessagesDisappearAfterSendDescription')
: undefined;
const parentDataTestId = toDataTestId(mode);

return (
<PanelRadioButton
Expand All @@ -69,7 +69,8 @@ export const DisappearingModes = (props: DisappearingModesProps) => {
setSelected(mode);
}}
disabled={options[mode]}
dataTestId={toDataTestId(mode)}
dataTestId={parentDataTestId}
radioInputDataTestId={`input-${parentDataTestId}`}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isEmpty } from 'lodash';

import { DisappearTimeOptionDataTestId } from 'react';
import { TimerOptionsArray } from '../../../../../session/disappearing_messages/timerOptions';
import { PanelButtonGroup, PanelLabel } from '../../../../buttons/PanelButton';
import { PanelRadioButton } from '../../../../buttons/PanelRadioButton';
Expand Down Expand Up @@ -29,6 +30,8 @@ export const TimeOptions = (props: TimerOptionsProps) => {
)}
<PanelButtonGroup>
{options.map(option => {
// we want "time-option-3600-seconds", etc as accessibility id
const parentDataTestId: DisappearTimeOptionDataTestId = `time-option-${option.value}-seconds`;
return (
<PanelRadioButton
key={option.name}
Expand All @@ -39,7 +42,8 @@ export const TimeOptions = (props: TimerOptionsProps) => {
setSelected(option.value);
}}
disabled={disabled}
dataTestId={`time-option-${option.value}-seconds`} // we want "time-option-3600-seconds", etc as accessibility id
dataTestId={parentDataTestId}
radioInputDataTestId={`input-${parentDataTestId}`}
/>
);
})}
Expand Down
43 changes: 24 additions & 19 deletions ts/react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ import 'react';
*/

declare module 'react' {
// disappear options
type DisappearOptionDataTestId =
| 'disappear-after-send-option'
| 'disappear-after-read-option'
| 'disappear-legacy-option'
| 'disappear-off-option';
type DisappearTimeOptionDataTestId =
| 'time-option-0-seconds'
| 'time-option-5-seconds'
| 'time-option-10-seconds'
| 'time-option-30-seconds'
| 'time-option-60-seconds'
| 'time-option-300-seconds'
| 'time-option-1800-seconds'
| 'time-option-3600-seconds'
| 'time-option-21600-seconds'
| 'time-option-43200-seconds'
| 'time-option-86400-seconds'
| 'time-option-604800-seconds'
| 'time-option-1209600-seconds';
type SessionDataTestId =
| 'group-member-status-text'
| 'loading-spinner'
Expand Down Expand Up @@ -82,19 +102,10 @@ declare module 'react' {
| 'accept-menu-item'

// timer options
| 'time-option-0-seconds'
| 'time-option-5-seconds'
| 'time-option-10-seconds'
| 'time-option-30-seconds'
| 'time-option-60-seconds'
| 'time-option-300-seconds'
| 'time-option-1800-seconds'
| 'time-option-3600-seconds'
| 'time-option-21600-seconds'
| 'time-option-43200-seconds'
| 'time-option-86400-seconds'
| 'time-option-604800-seconds'
| 'time-option-1209600-seconds'
| DisappearTimeOptionDataTestId
| DisappearOptionDataTestId
| `input-${DisappearTimeOptionDataTestId}`
| `input-${DisappearOptionDataTestId}`

// generic readably message (not control message)
| 'message-content'
Expand All @@ -117,12 +128,6 @@ declare module 'react' {
| 'call-notification-started-call'
| 'call-notification-answered-a-call'

// disappear options
| 'disappear-after-send-option'
| 'disappear-after-read-option'
| 'disappear-legacy-option'
| 'disappear-off-option'

// settings toggle and buttons
| 'remove-password-settings-button'
| 'change-password-settings-button'
Expand Down

0 comments on commit 7d81fd1

Please sign in to comment.