-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: lägg till empty state för barnlistan (#126)
- Loading branch information
Showing
7 changed files
with
287 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import { | ||
useChildList, | ||
useCalendar, | ||
useClassmates, | ||
useNews, | ||
useNotifications, | ||
useSchedule, | ||
} from '@skolplattformen/api-hooks' | ||
import { render } from '../../utils/testHelpers' | ||
import React from 'react' | ||
import { Children } from '../children.component.js' | ||
|
||
jest.mock('@skolplattformen/api-hooks') | ||
|
||
const setup = () => { | ||
return render(<Children />) | ||
} | ||
|
||
beforeEach(() => { | ||
useCalendar.mockReturnValueOnce({ data: [], status: 'loaded' }) | ||
useNotifications.mockReturnValueOnce({ data: [], status: 'loaded' }) | ||
useNews.mockReturnValueOnce({ data: [], status: 'loaded' }) | ||
useClassmates.mockReturnValueOnce({ data: [], status: 'loaded' }) | ||
useSchedule.mockReturnValueOnce({ data: [], status: 'loaded' }) | ||
}) | ||
|
||
test('renders loading state', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [], | ||
status: 'loading', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText(/laddar/i)).toBeTruthy() | ||
}) | ||
|
||
test('renders empty state message', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect( | ||
screen.getByText( | ||
'Det finns inga barn registrerade för ditt personnummer i Stockholms Stad' | ||
) | ||
).toBeTruthy() | ||
}) | ||
|
||
test('renders child in preschool', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Test Testsson', | ||
status: 'F', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Test Testsson')).toBeTruthy() | ||
expect(screen.getByText('Förskoleklass')).toBeTruthy() | ||
}) | ||
|
||
test('renders child in elementary school', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Test Testsson', | ||
status: 'GR', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Test Testsson')).toBeTruthy() | ||
expect(screen.getByText('Grundskolan')).toBeTruthy() | ||
}) | ||
|
||
test('renders child in high school', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Test Testsson', | ||
status: 'G', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Test Testsson')).toBeTruthy() | ||
expect(screen.getByText('Gymnasiet')).toBeTruthy() | ||
}) | ||
|
||
test('renders multiple children', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Storasyster Testsson', | ||
status: 'G', | ||
}, | ||
{ | ||
name: 'Lillebror Testsson', | ||
status: 'GR', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Storasyster Testsson')).toBeTruthy() | ||
expect(screen.getByText('Gymnasiet')).toBeTruthy() | ||
|
||
expect(screen.getByText('Lillebror Testsson')).toBeTruthy() | ||
expect(screen.getByText('Grundskolan')).toBeTruthy() | ||
}) | ||
|
||
test('displays class name if child has class mates', () => { | ||
useClassmates.mockReset() | ||
useClassmates.mockReturnValueOnce({ | ||
data: [ | ||
{ | ||
className: '8C', | ||
}, | ||
], | ||
status: 'loaded', | ||
}) | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Test Testsson', | ||
status: 'G', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Test Testsson')).toBeTruthy() | ||
expect(screen.getByText('8C')).toBeTruthy() | ||
expect(screen.queryByText('Gymnasiet')).toBeFalsy() | ||
}) | ||
|
||
test('removes any parenthesis from name', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Test Testsson(något annat)', | ||
status: 'G', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Test Testsson')).toBeTruthy() | ||
}) | ||
|
||
test('handles multiple statuses for a child', () => { | ||
useChildList.mockImplementationOnce(() => ({ | ||
data: [ | ||
{ | ||
name: 'Test Testsson(något annat)', | ||
status: 'G;GR;F', | ||
}, | ||
], | ||
status: 'loaded', | ||
})) | ||
|
||
const screen = setup() | ||
|
||
expect(screen.getByText('Test Testsson')).toBeTruthy() | ||
expect(screen.getByText('Gymnasiet, Grundskolan, Förskoleklass')).toBeTruthy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import 'react-native-gesture-handler/jestSetup' | ||
|
||
// Silence useNativeDriver error | ||
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper') |
Oops, something went wrong.