|
| 1 | +import axios from 'axios' |
| 2 | +import React from 'react' |
| 3 | +import MockAdapter from 'axios-mock-adapter' |
| 4 | +import { render } from '@testing-library/react-native' |
| 5 | +import { setUserData } from '../../src/api/auth' |
| 6 | +import { ENDPOINTS as UNI_ENDPOINTS } from '../../src/api/universities' |
| 7 | +import { ENDPOINTS as OFFER_ENDPOINTS } from '../../src/api/offerings' |
| 8 | +import { format } from '../../src/utils/string' |
| 9 | + |
| 10 | +import { HTTP_STATUS_CODES } from '../../src/api' |
| 11 | +import { UNIVERSITY_RESPONSE } from '../mock_responses/mock-university-response' |
| 12 | +import Home from '../../src/containers/HomeContainer/Home' |
| 13 | +import { OFFERINGS_RESPONSE_1 } from '../mock_responses/mock-offerings-response' |
| 14 | + |
| 15 | +// const assertNoButtonsRendered = async () => { |
| 16 | +// const { queryAllByA11yRole } = render(<UniversityListContainer />) |
| 17 | +// const universityList = await waitFor(() => queryAllByA11yRole('button')) |
| 18 | +// expect(universityList.length).toBe(0) |
| 19 | +// } |
| 20 | + |
| 21 | +const mock = new MockAdapter(axios) |
| 22 | +describe('Check universities rendering', () => { |
| 23 | + const USER_DATA = { |
| 24 | + authToken: 'A', |
| 25 | + universityId: '1001', |
| 26 | + userId: 'test user', |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + const offeringId = 'ac5b1727-629c-443b-8c1a-cc1bd541af6a' |
| 31 | + |
| 32 | + afterEach(() => { |
| 33 | + mock.reset() |
| 34 | + }) |
| 35 | + |
| 36 | + test('Check that components render', async () => { |
| 37 | + const mockNavigator = { push: jest.fn() } |
| 38 | + |
| 39 | + mock.onGet(`${UNI_ENDPOINTS.UNIVERSITIES}`).reply(HTTP_STATUS_CODES.OK, UNIVERSITY_RESPONSE) |
| 40 | + mock |
| 41 | + .onGet(`${OFFER_ENDPOINTS.OFFERINGBYSTUDENT}`) |
| 42 | + .reply(HTTP_STATUS_CODES.OK, OFFERINGS_RESPONSE_1) |
| 43 | + mock |
| 44 | + .onGet(`${format(OFFER_ENDPOINTS.OFFERING, offeringId)}`) |
| 45 | + .reply(HTTP_STATUS_CODES.OK, OFFERINGS_RESPONSE_1) |
| 46 | + |
| 47 | + setUserData(USER_DATA) |
| 48 | + |
| 49 | + const { getByTestId } = render(<Home navigation={mockNavigator} />) |
| 50 | + |
| 51 | + const picker = await getByTestId('picker') |
| 52 | + expect(picker).not.toBe(null) |
| 53 | + |
| 54 | + const courseList = await getByTestId('courseList') |
| 55 | + expect(courseList).not.toBe(null) |
| 56 | + }) |
| 57 | +}) |
0 commit comments