Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import { findByTestId, renderWithProviders } from 'src/support/tests/hooksHelper
import { Preloader } from '../Preloader';
import * as selectShouldDisplayDeviceCompromisedModule from '../selectShouldDisplayDeviceCompromisedOnRoute';

class ResizeObserverMock {
observe = jest.fn();
unobserve = jest.fn();
disconnect = jest.fn();
}

window.ResizeObserver = ResizeObserverMock;

// render only Translation.id in data-test attribute
jest.mock('src/components/suite/Translation', () => ({
Translation: ({ id }: any) => <span data-testid={id}>{id}</span>,
Expand Down Expand Up @@ -218,7 +226,7 @@ describe(`${Preloader.name} component`, () => {
const { unmount } = renderWithProviders(store, <Index app={store.getState().router.app} />);

expect(findByTestId('@connect-device-prompt')).not.toBeNull();
fireEvent.click(findByTestId('@onboarding/expand-troubleshooting-tips/toggle'));
fireEvent.click(findByTestId('@onboarding/troubleshooting-tips/button'));
expect(screen.getAllByText('TR_ACQUIRE_DEVICE_TITLE').length).toBe(2);

unmount();
Expand Down Expand Up @@ -270,7 +278,7 @@ describe(`${Preloader.name} component`, () => {
const { unmount } = renderWithProviders(store, <Index app={store.getState().router.app} />);

expect(findByTestId('@connect-device-prompt')).not.toBeNull();
fireEvent.click(findByTestId('@onboarding/expand-troubleshooting-tips/toggle'));
fireEvent.click(findByTestId('@onboarding/troubleshooting-tips/button'));
expect(findByTestId('@connect-device-prompt/unreadable-udev')).not.toBeNull();

unmount();
Expand Down Expand Up @@ -345,7 +353,7 @@ describe(`${Preloader.name} component`, () => {
const { unmount } = renderWithProviders(store, <Index app={store.getState().router.app} />);

expect(findByTestId('@connect-device-prompt')).not.toBeNull();
fireEvent.click(findByTestId('@onboarding/expand-troubleshooting-tips/toggle'));
fireEvent.click(findByTestId('@onboarding/troubleshooting-tips/button'));
expect(findByTestId(/TR_UNKNOWN_DEVICE/)).not.toBeNull();

unmount();
Expand All @@ -371,7 +379,7 @@ describe(`${Preloader.name} component`, () => {
const { unmount } = renderWithProviders(store, <Index app={store.getState().router.app} />);

expect(findByTestId('@connect-device-prompt')).not.toBeNull();
fireEvent.click(findByTestId('@onboarding/expand-troubleshooting-tips/toggle'));
fireEvent.click(findByTestId('@onboarding/troubleshooting-tips/button'));
expect(findByTestId(/TR_YOUR_DEVICE_IS_SEEDLESS/)).not.toBeNull();
expect(findByTestId('TR_SEEDLESS_SETUP_IS_NOT_SUPPORTED_TITLE')).not.toBeNull();

Expand Down Expand Up @@ -449,7 +457,8 @@ describe(`${Preloader.name} component`, () => {
const { unmount } = renderWithProviders(store, <Index app={store.getState().router.app} />);

expect(findByTestId('@connect-device-prompt')).not.toBeNull();
expect(findByTestId(/TR_DEVICE_IN_BOOTLOADER/)).not.toBeNull();
expect(findByTestId('TR_DEVICE_CONNECTED_BOOTLOADER')).not.toBeNull();
fireEvent.click(findByTestId('@onboarding/troubleshooting-tips/button'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's really bad practice to check hidden content, it was pretty hard to debug 🤷‍♂️

Now we click first before we check.

expect(findByTestId('TR_DEVICE_CONNECTED_BOOTLOADER_RECONNECT')).not.toBeNull();

unmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import {
Banner,
BannerVariant,
Box,
Button,
Card,
Collapsible,
Column,
ElevationContext,
ElevationDown,
ElevationUp,
IconName,
Modal,
Row,
SelectBar,
Text,
} from '@trezor/components';
import { spacings } from '@trezor/theme';
import { typedObjectKeys } from '@trezor/utils';

import { TroubleshootingTipsFooter } from './TroubleshootingTipsFooter';
import { TroubleshootingTipsList } from './TroubleshootingTipsList';
import { TroubleshootingTipsToggle } from './TroubleshootingTipsToggle';
import { useLayoutSize } from '../../../hooks/suite';
import { Translation } from '../Translation';
import { TroubleshootingTipsFooter } from './TroubleshootingTipsFooter';

export type TroubleshootingTipsItem = {
key: string;
Expand Down Expand Up @@ -108,47 +106,55 @@ export const TroubleshootingTipsWithSections = <K extends string, T extends K>({
);
};

const CollapsibleTroubleshooting = () => (
<Collapsible
defaultIsOpen={initiallyIsOpen === true}
data-testid={dataTest || '@onboarding/expand-troubleshooting-tips'}
>
<Column gap={20} alignItems="center">
<Collapsible.Toggle>
<TroubleshootingTipsToggle>{toggleText}</TroubleshootingTipsToggle>
</Collapsible.Toggle>
<Collapsible.Content>
<ElevationContext baseElevation={-1}>
<ElevationDown>
<Card paddingType="small" maxWidth="656px">
<Column gap={spacings.sm}>
{labelRow}
{/* Custom design, where upper card is -1, and this card is 1 */}
<ElevationUp>
<Card>
<TroubleshootingTipsList
items={items[selectedSection].items}
/>
</Card>
</ElevationUp>
<TroubleshootingTipsFooter />
</Column>
</Card>
</ElevationDown>
</ElevationContext>
</Collapsible.Content>
const TroubleshootingButton = () => {
const [isTroubleshootingModalVisible, setIsTroubleshootingModalVisible] = useState(false);
const onOpen = () => {
setIsTroubleshootingModalVisible(true);
};
const onCancel = () => {
setIsTroubleshootingModalVisible(false);
};

return (
<Column
alignItems="center"
data-testid={dataTest || '@onboarding/troubleshooting-tips'}
>
<Button
onClick={onOpen}
variant="tertiary"
size="small"
isSubtle={!initiallyIsOpen}
icon="question"
data-testid="@onboarding/troubleshooting-tips/button"
>
{toggleText ?? <Translation id="TR_TROUBLE_SHOOTING_TIPS" />}
</Button>
{isTroubleshootingModalVisible && (
<Modal
heading={toggleText ?? <Translation id="TR_TROUBLE_SHOOTING_TIPS" />}
onCancel={onCancel}
variant="info"
bottomContent={<TroubleshootingTipsFooter />}
data-testid="@onboarding/troubleshooting-tips/modal"
>
<Card header={labelRow}>
<TroubleshootingTipsList items={items[selectedSection].items} />
</Card>
</Modal>
)}
</Column>
</Collapsible>
);
);
};

return cta ? (
<Column gap={80} alignItems="center">
<ActionBanner />
<CollapsibleTroubleshooting />
<TroubleshootingButton />
</Column>
) : (
<Box margin={{ top: 80 }}>
<CollapsibleTroubleshooting />
<TroubleshootingButton />
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const TroubleshootingTipsFooter = () => {
justifyContent="space-between"
gap={spacings.xs}
alignItems="center"
width="100%"
>
<Text typographyStyle="hint">
<Translation id="TR_ONBOARDING_TROUBLESHOOTING_FAILED" />
Expand Down

This file was deleted.