|
| 1 | +import React from 'react'; |
| 2 | +import ReactModal from 'react-modal'; |
| 3 | +import TestFile from '../TestFile/TestFile'; |
| 4 | +import { GlobalContext } from '../../../context/globalReducer'; |
| 5 | +import { TestFileModalContext } from '../../../context/testFileModalReducer'; |
| 6 | +import { HooksTestCaseContext } from '../../../context/hooksTestCaseReducer'; |
| 7 | +import { ReduxTestCaseContext } from '../../../context/reduxTestCaseReducer'; |
| 8 | +import { TestCaseContext } from '../../../context/testCaseReducer'; |
| 9 | +import { EndpointTestCaseContext } from '../../../context/endpointTestCaseReducer'; |
| 10 | + |
| 11 | +import '@testing-library/jest-dom/extend-expect'; |
| 12 | +import { mount } from 'enzyme'; |
| 13 | +import { configure } from 'enzyme'; |
| 14 | +import Adapter from 'enzyme-adapter-react-16'; |
| 15 | + |
| 16 | +configure({ adapter: new Adapter() }); |
| 17 | + |
| 18 | +let wrapper, |
| 19 | + globalM, |
| 20 | + dispatchToGlobal, |
| 21 | + hooksTestCase, |
| 22 | + dispatchToHooksTestCase, |
| 23 | + testFileModal, |
| 24 | + dispatchToTestFileModal, |
| 25 | + reduxTestCaseState, |
| 26 | + dispatchToReduxTestCase, |
| 27 | + testCase, |
| 28 | + dispatchToTestCase, |
| 29 | + endpointTestCaseState, |
| 30 | + dispatchToEndpointTestCase; |
| 31 | + |
| 32 | +beforeEach(() => { |
| 33 | + globalM = { |
| 34 | + url: null, |
| 35 | + isProjectLoaded: false, |
| 36 | + fileTree: null, |
| 37 | + componentName: '', |
| 38 | + isFileDirectoryOpen: true, |
| 39 | + rightPanelDisplay: 'browserView', |
| 40 | + displayedFileCode: '', |
| 41 | + isFolderOpen: {}, |
| 42 | + isFileHighlighted: '', |
| 43 | + projectFilePath: '', |
| 44 | + filePathMap: {}, |
| 45 | + }; |
| 46 | + dispatchToGlobal = jest.fn(); |
| 47 | + |
| 48 | + testFileModal = { |
| 49 | + isTestModalOpen: true, |
| 50 | + }; |
| 51 | + dispatchToTestFileModal = jest.fn(); |
| 52 | + |
| 53 | + testCase = { |
| 54 | + testStatement: '', |
| 55 | + statements: [ |
| 56 | + { |
| 57 | + id: 0, |
| 58 | + type: 'render', |
| 59 | + componentName: '', |
| 60 | + filePath: '', |
| 61 | + props: [], |
| 62 | + hasProp: false, |
| 63 | + }, |
| 64 | + { |
| 65 | + id: 1, |
| 66 | + type: 'assertion', |
| 67 | + queryVariant: '', |
| 68 | + querySelector: '', |
| 69 | + queryValue: '', |
| 70 | + isNot: false, |
| 71 | + matcherType: '', |
| 72 | + matcherValue: '', |
| 73 | + suggestions: [], |
| 74 | + }, |
| 75 | + ], |
| 76 | + }; |
| 77 | + dispatchToTestCase = jest.fn(); |
| 78 | + |
| 79 | + hooksTestCase = { |
| 80 | + hooksTestStatement: '', |
| 81 | + hooksStatements: [], |
| 82 | + hasHooks: 0, |
| 83 | + }; |
| 84 | + dispatchToHooksTestCase = jest.fn(); |
| 85 | + |
| 86 | + reduxTestCaseState = { |
| 87 | + reduxTestStatement: '', |
| 88 | + reduxStatements: [], |
| 89 | + hasRedux: 0, |
| 90 | + }; |
| 91 | + dispatchToReduxTestCase = jest.fn(); |
| 92 | + |
| 93 | + endpointTestCaseState = { |
| 94 | + endpointTestStatement: '', |
| 95 | + endpointStatements: [], |
| 96 | + hasEndpoint: 0, |
| 97 | + }; |
| 98 | + dispatchToEndpointTestCase = jest.fn(); |
| 99 | + |
| 100 | + wrapper = mount( |
| 101 | + <GlobalContext.Provider value={[globalM, dispatchToGlobal]}> |
| 102 | + <TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}> |
| 103 | + <HooksTestCaseContext.Provider value={[hooksTestCase, dispatchToHooksTestCase]}> |
| 104 | + <ReduxTestCaseContext.Provider value={[reduxTestCaseState, dispatchToReduxTestCase]}> |
| 105 | + <TestCaseContext.Provider value={[testCase, dispatchToTestCase]}> |
| 106 | + <EndpointTestCaseContext.Provider |
| 107 | + value={[endpointTestCaseState, dispatchToEndpointTestCase]} |
| 108 | + > |
| 109 | + <TestFile /> |
| 110 | + </EndpointTestCaseContext.Provider> |
| 111 | + </TestCaseContext.Provider> |
| 112 | + </ReduxTestCaseContext.Provider> |
| 113 | + </HooksTestCaseContext.Provider> |
| 114 | + </TestFileModalContext.Provider> |
| 115 | + </GlobalContext.Provider> |
| 116 | + ); |
| 117 | + |
| 118 | + jest.resetModules(); |
| 119 | +}); |
| 120 | + |
| 121 | +it('app opens test file modal', () => { |
| 122 | + let testFileModal = wrapper.find(ReactModal); |
| 123 | + expect(testFileModal.length).toEqual(1); |
| 124 | + expect(testFileModal.prop('isOpen')).toEqual(true); |
| 125 | + expect(testFileModal.text()).toContain('What would you like to test?'); |
| 126 | + expect(testFileModal.text()).toContain('React'); |
| 127 | + expect(testFileModal.text()).toContain('Redux'); |
| 128 | + expect(testFileModal.text()).toContain('Hooks/Context'); |
| 129 | + expect(testFileModal.text()).toContain('Endpoint'); |
| 130 | +}); |
0 commit comments