|
| 1 | +import React from 'react' |
| 2 | +import {render, screen, fireEvent} from '@testing-library/react' |
| 3 | +import '@testing-library/jest-dom/extend-expect' // needed this to extend the jest-dom assertions (ex toHaveTextContent) |
| 4 | +import ErrorContainer from '../containers/ErrorContainer' |
| 5 | +import { useStoreContext } from '../store'; |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +const state = { |
| 10 | + "currentTab": null, |
| 11 | + "currentTitle": "No Target", |
| 12 | + "tabs": {}, |
| 13 | +} |
| 14 | + |
| 15 | +const MockErrorMsg = jest.fn(); |
| 16 | +jest.mock('../components/ErrorMsg', () => () => { |
| 17 | + MockErrorMsg(); |
| 18 | + return (<div>MockErrorMsg</div> ); |
| 19 | +}); |
| 20 | + |
| 21 | +jest.mock('../store'); |
| 22 | +const dispatch = jest.fn(); |
| 23 | +useStoreContext.mockImplementation(() => [state, dispatch]); |
| 24 | + |
| 25 | +describe('unit testing for ErrorContainer.tsx', () => { |
| 26 | + test("logo image renders as expected", ()=>{ |
| 27 | + render(<ErrorContainer/>); |
| 28 | + expect(screen.getByAltText('Reactime Logo')).toBeInTheDocument() |
| 29 | + }) |
| 30 | + |
| 31 | + test("ErrorMsg component renders as expected", ()=>{ |
| 32 | + render(<ErrorContainer/>); |
| 33 | + expect(screen.getByText('MockErrorMsg')).toBeInTheDocument() |
| 34 | + }) |
| 35 | + |
| 36 | + test("Reactime website shows as expected", ()=>{ |
| 37 | + render(<ErrorContainer/>); |
| 38 | + expect(screen.getByText('Please visit the Reactime webiste for more info.')).toBeInTheDocument() |
| 39 | + }) |
| 40 | + |
| 41 | + describe('Loading Checks show up as expected', () => { |
| 42 | + test("Content script launching check shows", () => { |
| 43 | + render(<ErrorContainer/>); |
| 44 | + expect(screen.getByText(`Checking if content script has been launched on current tab`)).toBeInTheDocument() |
| 45 | + }); |
| 46 | + test("React Dev Tool Install check shows", () => { |
| 47 | + render(<ErrorContainer/>); |
| 48 | + expect(screen.getByText(`Checking if React Dev Tools has been installed`)).toBeInTheDocument() |
| 49 | + }); |
| 50 | + test("Compatible app check shows", () => { |
| 51 | + render(<ErrorContainer/>); |
| 52 | + expect(screen.getByText(`Checking if target is a compatible React app`)).toBeInTheDocument() |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('Launching header shows correct tab info', () => { |
| 57 | + test("When currentTitle has no target", () => { |
| 58 | + render(<ErrorContainer/>); |
| 59 | + expect(screen.getByText(`Launching Reactime on tab: No Target`)).toBeInTheDocument() |
| 60 | + expect(screen.queryByText(`Launching Reactime on tab: Test Page`)).not.toBeInTheDocument() |
| 61 | + }); |
| 62 | + |
| 63 | + test("When currentTitle has a target title", () => { |
| 64 | + state.currentTitle = 'Test Page' |
| 65 | + render(<ErrorContainer/>); |
| 66 | + screen.debug() |
| 67 | + expect(screen.getByText(`Launching Reactime on tab: Test Page`)).toBeInTheDocument() |
| 68 | + expect(screen.queryByText(`Launching Reactime on tab: No Target`)).not.toBeInTheDocument() |
| 69 | + |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments