Skip to content

Commit d0ac3c6

Browse files
committed
added one test
1 parent 6ad9a08 commit d0ac3c6

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
emaildId: '[email protected]',
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+
})

src/containers/HomeContainer/Home.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import styles from './Home.style'
1515
*/
1616
const Home = ({ navigation }) => {
1717
const currentUser = getCurrentAuthenticatedUser()
18-
var universityId = currentUser.universityId
18+
let universityId = currentUser.universityId
1919

2020
/**
2121
* Helper function to filter courses by university id
@@ -88,7 +88,7 @@ const Home = ({ navigation }) => {
8888
}, [setAllUniversities])
8989

9090
const universityItems = universities.map((uni) => {
91-
return <Picker.Item accessibilityRole="button" key={uni.id} value={uni.id} label={uni.name} />
91+
return <Picker.Item key={uni.id} value={uni.id} label={uni.name} />
9292
})
9393

9494
const [university, setUniversity] = useState(universityId)
@@ -108,6 +108,7 @@ const Home = ({ navigation }) => {
108108

109109
return (
110110
<Picker
111+
testID="picker"
111112
style={{ flex: 0, width: '100%' }}
112113
selectedValue={university}
113114
onValueChange={(newUniversityId) => onUniversitySelected(newUniversityId)}
@@ -125,6 +126,7 @@ const Home = ({ navigation }) => {
125126

126127
return (
127128
<FlatList
129+
testID="courseList"
128130
keyExtractor={(idxCourses, index) => index.toString()}
129131
data={courses}
130132
renderItem={renderCourseItem}

0 commit comments

Comments
 (0)