|
| 1 | +import React from 'react'; |
| 2 | +import { fireEvent, waitFor } from '@testing-library/react'; |
| 3 | +import { renderWithProviders, throwGrpcError } from 'util/tests'; |
| 4 | +import { createStore, Store } from 'store'; |
| 5 | +import SidecarWizard from 'components/loop/sidecar/SidecarWizard'; |
| 6 | + |
| 7 | +describe('SidecarWizard', () => { |
| 8 | + let store: Store; |
| 9 | + |
| 10 | + beforeEach(async () => { |
| 11 | + store = createStore(); |
| 12 | + await store.fetchAllData(); |
| 13 | + |
| 14 | + store.registerSidecarView.startRegister(); |
| 15 | + }); |
| 16 | + |
| 17 | + const render = () => { |
| 18 | + return renderWithProviders(<SidecarWizard />, store); |
| 19 | + }; |
| 20 | + |
| 21 | + describe('General behavior', () => { |
| 22 | + it('should display the description labels', () => { |
| 23 | + const { getByText } = render(); |
| 24 | + expect(getByText('Step 1 of 2')).toBeInTheDocument(); |
| 25 | + expect(getByText('Sidecar Registration')).toBeInTheDocument(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should navigate forward and back through each step', () => { |
| 29 | + const { getByText } = render(); |
| 30 | + expect(getByText('Step 1 of 2')).toBeInTheDocument(); |
| 31 | + fireEvent.click(getByText('Next')); |
| 32 | + expect(getByText('Step 2 of 2')).toBeInTheDocument(); |
| 33 | + fireEvent.click(getByText('Confirm')); |
| 34 | + expect(getByText('Registering Sidecar Ticket')).toBeInTheDocument(); |
| 35 | + fireEvent.click(getByText('arrow-left.svg')); |
| 36 | + expect(getByText('Step 2 of 2')).toBeInTheDocument(); |
| 37 | + fireEvent.click(getByText('arrow-left.svg')); |
| 38 | + expect(getByText('Step 1 of 2')).toBeInTheDocument(); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should register a ticket successfully', async () => { |
| 43 | + const { getByText, findByText, getByLabelText, changeInput } = render(); |
| 44 | + expect(getByText('Sidecar Registration')).toBeInTheDocument(); |
| 45 | + expect(getByLabelText('ticket-input')).toBeInTheDocument(); |
| 46 | + changeInput('ticket-input', 'sidecar1e84d7ba'); |
| 47 | + fireEvent.click(getByText('Next')); |
| 48 | + expect(getByText('sidecar1e84d7ba')).toBeInTheDocument(); |
| 49 | + fireEvent.click(getByText('Confirm')); |
| 50 | + expect(getByText('Registering Sidecar Ticket')).toBeInTheDocument(); |
| 51 | + expect( |
| 52 | + await findByText('Ticket Registered Successfully', {}, { timeout: 2000 }), |
| 53 | + ).toBeInTheDocument(); |
| 54 | + fireEvent.click(getByText('arrow-left.svg')); |
| 55 | + expect(store.registerSidecarView.showWizard).toBeFalsy(); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should handle errors when registering a ticket', async () => { |
| 59 | + const { getByText, changeInput } = render(); |
| 60 | + |
| 61 | + changeInput('ticket-input', 'sidecar1e84d7ba'); |
| 62 | + fireEvent.click(getByText('Next')); |
| 63 | + |
| 64 | + // throw a GRPC error when getting the account quote |
| 65 | + throwGrpcError('reg-err', 'RegisterSidecar'); |
| 66 | + fireEvent.click(getByText('Confirm')); |
| 67 | + |
| 68 | + // should show error toast |
| 69 | + await waitFor(() => { |
| 70 | + expect(getByText('Unable to register ticket')).toBeInTheDocument(); |
| 71 | + expect(getByText('reg-err')).toBeInTheDocument(); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
0 commit comments