2023-08-24 08:03:56 +00:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2024-03-01 14:25:56 +00:00
|
|
|
import {
|
|
|
|
MockedWalletProvider,
|
|
|
|
mockConfig,
|
|
|
|
} from '@vegaprotocol/wallet-react/testing';
|
2023-08-07 10:35:55 +00:00
|
|
|
import { GetStarted } from './get-started';
|
2024-03-01 14:25:56 +00:00
|
|
|
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
|
|
import { useOnboardingStore } from '../../stores/onboarding';
|
2023-08-07 10:35:55 +00:00
|
|
|
|
2023-08-24 08:03:56 +00:00
|
|
|
let mockStep = 1;
|
2024-03-01 14:25:56 +00:00
|
|
|
|
|
|
|
jest.mock('../../lib/hooks/use-get-onboarding-step', () => ({
|
|
|
|
...jest.requireActual('../../lib/hooks/use-get-onboarding-step'),
|
2023-08-24 08:03:56 +00:00
|
|
|
useGetOnboardingStep: jest.fn(() => mockStep),
|
|
|
|
}));
|
|
|
|
|
2023-08-07 10:35:55 +00:00
|
|
|
describe('GetStarted', () => {
|
2024-03-01 14:25:56 +00:00
|
|
|
const renderComponent = () => {
|
|
|
|
return (
|
2023-08-24 08:03:56 +00:00
|
|
|
<MemoryRouter>
|
2024-03-01 14:25:56 +00:00
|
|
|
<MockedWalletProvider>
|
2023-08-24 08:03:56 +00:00
|
|
|
<GetStarted />
|
2024-03-01 14:25:56 +00:00
|
|
|
</MockedWalletProvider>
|
2023-08-24 08:03:56 +00:00
|
|
|
</MemoryRouter>
|
2023-08-07 10:35:55 +00:00
|
|
|
);
|
|
|
|
};
|
2023-08-24 08:03:56 +00:00
|
|
|
const checkTicks = (elements: Element[]) => {
|
|
|
|
elements.forEach((item, i) => {
|
2023-09-12 15:07:37 +00:00
|
|
|
if (i + 1 < mockStep - 1) {
|
2023-08-24 08:03:56 +00:00
|
|
|
expect(item.querySelector('[data-testid="icon-tick"]')).toBeTruthy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
2023-08-07 10:35:55 +00:00
|
|
|
|
2024-03-01 14:25:56 +00:00
|
|
|
afterEach(() => {
|
|
|
|
act(() => {
|
|
|
|
mockConfig.reset();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-07 10:35:55 +00:00
|
|
|
it('renders full get started content if not connected and no browser wallet detected', () => {
|
2024-03-01 14:25:56 +00:00
|
|
|
render(renderComponent());
|
2023-08-07 10:35:55 +00:00
|
|
|
expect(screen.getByTestId('get-started-banner')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders connect prompt if no pubKey but wallet installed', () => {
|
|
|
|
globalThis.window.vega = {} as Vega;
|
2024-03-01 14:25:56 +00:00
|
|
|
render(renderComponent());
|
2023-08-24 08:03:56 +00:00
|
|
|
expect(screen.getByTestId('get-started-banner')).toBeInTheDocument();
|
2023-08-07 10:35:55 +00:00
|
|
|
globalThis.window.vega = undefined as unknown as Vega;
|
|
|
|
});
|
|
|
|
|
2023-09-14 19:10:33 +00:00
|
|
|
it('renders nothing if dismissed', () => {
|
2024-03-01 14:25:56 +00:00
|
|
|
mockConfig.store.setState({ status: 'connected', pubKey: 'my-key' });
|
2023-09-14 19:10:33 +00:00
|
|
|
useOnboardingStore.setState({ dismissed: true });
|
2023-08-24 08:03:56 +00:00
|
|
|
mockStep = 0;
|
2024-03-01 14:25:56 +00:00
|
|
|
const { container } = render(renderComponent());
|
2023-08-07 10:35:55 +00:00
|
|
|
expect(container).toBeEmptyDOMElement();
|
|
|
|
});
|
2023-08-24 08:03:56 +00:00
|
|
|
|
|
|
|
it('steps should be ticked', () => {
|
2024-03-01 14:25:56 +00:00
|
|
|
mockConfig.store.setState({ status: 'connected', pubKey: 'my-key' });
|
2023-09-14 19:10:33 +00:00
|
|
|
useOnboardingStore.setState({ dismissed: false });
|
2023-08-24 08:03:56 +00:00
|
|
|
const navigatorGetter: jest.SpyInstance = jest.spyOn(
|
|
|
|
window.navigator,
|
|
|
|
'userAgent',
|
|
|
|
'get'
|
|
|
|
);
|
|
|
|
navigatorGetter.mockReturnValue('Chrome');
|
|
|
|
|
|
|
|
mockStep = 2;
|
2024-03-01 14:25:56 +00:00
|
|
|
const { rerender, container } = render(renderComponent());
|
2023-08-24 08:03:56 +00:00
|
|
|
checkTicks(screen.getAllByRole('listitem'));
|
|
|
|
expect(screen.getByRole('button', { name: 'Connect' })).toBeInTheDocument();
|
|
|
|
|
|
|
|
mockStep = 3;
|
2024-03-01 14:25:56 +00:00
|
|
|
rerender(renderComponent());
|
2023-08-24 08:03:56 +00:00
|
|
|
checkTicks(screen.getAllByRole('listitem'));
|
2023-09-15 14:10:38 +00:00
|
|
|
expect(screen.getByRole('link', { name: 'Deposit' })).toBeInTheDocument();
|
2023-08-24 08:03:56 +00:00
|
|
|
|
|
|
|
mockStep = 4;
|
2024-03-01 14:25:56 +00:00
|
|
|
rerender(renderComponent());
|
2023-08-24 08:03:56 +00:00
|
|
|
checkTicks(screen.getAllByRole('listitem'));
|
2023-09-12 15:07:37 +00:00
|
|
|
expect(
|
2023-09-15 14:10:38 +00:00
|
|
|
screen.getByRole('link', { name: 'Ready to trade' })
|
2023-09-12 15:07:37 +00:00
|
|
|
).toBeInTheDocument();
|
2023-08-24 08:03:56 +00:00
|
|
|
|
2023-09-15 14:10:38 +00:00
|
|
|
fireEvent.click(screen.getByRole('link', { name: 'Ready to trade' }));
|
2023-09-14 19:10:33 +00:00
|
|
|
|
2023-08-24 08:03:56 +00:00
|
|
|
mockStep = 5;
|
2024-03-01 14:25:56 +00:00
|
|
|
rerender(renderComponent());
|
2023-08-24 08:03:56 +00:00
|
|
|
expect(container).toBeEmptyDOMElement();
|
|
|
|
});
|
2023-08-07 10:35:55 +00:00
|
|
|
});
|