|
| 1 | +import React, { Suspense } from 'react'; |
| 2 | +import { fireEvent, waitFor } from '@testing-library/react'; |
| 3 | +import { renderWithProviders } from 'util/tests'; |
| 4 | +import { prefixTranslation } from 'util/translate'; |
| 5 | +import { createStore, Store } from 'store'; |
| 6 | +import { Layout } from 'components/layout/Layout'; |
| 7 | +import LoopPage from 'components/loop/LoopPage'; |
| 8 | +import TourHost from 'components/tour/TourHost'; |
| 9 | + |
| 10 | +describe('TourHost component', () => { |
| 11 | + let store: Store; |
| 12 | + |
| 13 | + beforeEach(async () => { |
| 14 | + store = createStore(); |
| 15 | + await store.fetchAllData(); |
| 16 | + }); |
| 17 | + |
| 18 | + const firstLine = (text: string) => text.split('\n')[0]; |
| 19 | + |
| 20 | + const render = () => { |
| 21 | + const cmp = ( |
| 22 | + <Suspense fallback={null}> |
| 23 | + <Layout> |
| 24 | + <LoopPage /> |
| 25 | + </Layout> |
| 26 | + <TourHost /> |
| 27 | + </Suspense> |
| 28 | + ); |
| 29 | + return renderWithProviders(cmp, store); |
| 30 | + }; |
| 31 | + |
| 32 | + it('should open and dismiss the tour', () => { |
| 33 | + const { getByText, queryByText } = render(); |
| 34 | + fireEvent.click(getByText('help-circle.svg')); |
| 35 | + expect(getByText('Welcome to Lightning Terminal!')).toBeInTheDocument(); |
| 36 | + fireEvent.click(getByText('No Thanks')); |
| 37 | + expect(queryByText('Welcome to Lightning Terminal!')).not.toBeInTheDocument(); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should open the sidebar if it is collapsed', () => { |
| 41 | + const { getByText } = render(); |
| 42 | + store.settingsStore.sidebarVisible = false; |
| 43 | + store.settingsStore.autoCollapse = true; |
| 44 | + |
| 45 | + fireEvent.click(getByText('help-circle.svg')); |
| 46 | + expect(getByText('Welcome to Lightning Terminal!')).toBeInTheDocument(); |
| 47 | + |
| 48 | + fireEvent.click(getByText("Yes! Let's Go")); |
| 49 | + expect(store.settingsStore.sidebarVisible).toBe(true); |
| 50 | + |
| 51 | + fireEvent.click(getByText('Next')); |
| 52 | + expect(store.settingsStore.sidebarVisible).toBe(false); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should walk through the full tour', async () => { |
| 56 | + const { getByText } = render(); |
| 57 | + const { l } = prefixTranslation('cmps.tour.TextStep'); |
| 58 | + |
| 59 | + fireEvent.click(getByText('help-circle.svg')); |
| 60 | + expect(getByText('Welcome to Lightning Terminal!')).toBeInTheDocument(); |
| 61 | + |
| 62 | + fireEvent.click(getByText("Yes! Let's Go")); |
| 63 | + expect(getByText(l('nodeStatus'))).toBeInTheDocument(); |
| 64 | + |
| 65 | + // sample data is fetch after step #1 and we need to wait for it |
| 66 | + await waitFor(() => expect(store.swapStore.sortedSwaps).toHaveLength(7)); |
| 67 | + |
| 68 | + fireEvent.click(getByText('Next')); |
| 69 | + expect(getByText(l('history'))).toBeInTheDocument(); |
| 70 | + |
| 71 | + fireEvent.click(getByText('Next')); |
| 72 | + expect(getByText(l('inbound'))).toBeInTheDocument(); |
| 73 | + |
| 74 | + fireEvent.click(getByText('Next')); |
| 75 | + expect(getByText(l('outbound'))).toBeInTheDocument(); |
| 76 | + |
| 77 | + fireEvent.click(getByText('Next')); |
| 78 | + expect(getByText(l('channelList'))).toBeInTheDocument(); |
| 79 | + |
| 80 | + fireEvent.click(getByText('Next')); |
| 81 | + expect(getByText(l('channelListReceive'))).toBeInTheDocument(); |
| 82 | + |
| 83 | + fireEvent.click(getByText('Next')); |
| 84 | + expect(getByText(l('channelListSend'))).toBeInTheDocument(); |
| 85 | + |
| 86 | + fireEvent.click(getByText('Next')); |
| 87 | + expect(getByText(l('channelListFee'))).toBeInTheDocument(); |
| 88 | + |
| 89 | + fireEvent.click(getByText('Next')); |
| 90 | + expect(getByText(l('channelListUptime'))).toBeInTheDocument(); |
| 91 | + |
| 92 | + fireEvent.click(getByText('Next')); |
| 93 | + expect(getByText(l('channelListPeer'))).toBeInTheDocument(); |
| 94 | + |
| 95 | + fireEvent.click(getByText('Next')); |
| 96 | + expect(getByText(l('channelListCapacity'))).toBeInTheDocument(); |
| 97 | + |
| 98 | + fireEvent.click(getByText('Next')); |
| 99 | + expect(getByText(l('export'))).toBeInTheDocument(); |
| 100 | + |
| 101 | + fireEvent.click(getByText('Next')); |
| 102 | + expect(getByText(firstLine(l('loop')))).toBeInTheDocument(); |
| 103 | + |
| 104 | + fireEvent.click(getByText('Loop', { selector: 'button' })); |
| 105 | + expect(getByText(l('loopActions'))).toBeInTheDocument(); |
| 106 | + |
| 107 | + fireEvent.click(getByText('Next')); |
| 108 | + expect(getByText(firstLine(l('channelListSelect')))).toBeInTheDocument(); |
| 109 | + |
| 110 | + fireEvent.click(getByText('Next')); |
| 111 | + expect(getByText(firstLine(l('loopOut')))).toBeInTheDocument(); |
| 112 | + |
| 113 | + fireEvent.click(getByText('Loop Out', { selector: 'button' })); |
| 114 | + expect(getByText(firstLine(l('loopAmount')))).toBeInTheDocument(); |
| 115 | + |
| 116 | + fireEvent.click(getByText('Next', { selector: 'button' })); |
| 117 | + expect(getByText(firstLine(l('loopReview')))).toBeInTheDocument(); |
| 118 | + |
| 119 | + fireEvent.click(getByText('Confirm', { selector: 'button' })); |
| 120 | + expect(getByText(firstLine(l('loopProgress')))).toBeInTheDocument(); |
| 121 | + |
| 122 | + await waitFor(() => { |
| 123 | + expect(getByText(firstLine(l('processingSwaps')))).toBeInTheDocument(); |
| 124 | + }); |
| 125 | + |
| 126 | + fireEvent.click(getByText('Next')); |
| 127 | + expect(getByText(l('swapProgress'))).toBeInTheDocument(); |
| 128 | + |
| 129 | + fireEvent.click(getByText('Next')); |
| 130 | + expect(getByText(firstLine(l('swapMinimize')))).toBeInTheDocument(); |
| 131 | + |
| 132 | + fireEvent.click(getByText('minimize.svg')); |
| 133 | + expect(getByText('Congratulations!')).toBeInTheDocument(); |
| 134 | + |
| 135 | + fireEvent.click(getByText('Close')); |
| 136 | + expect(() => getByText('Congratulations!')).toThrow(); |
| 137 | + }); |
| 138 | +}); |
0 commit comments