Skip to content

Commit da68a18

Browse files
committed
add tests around redux favorite building hours
1 parent bc0bb2c commit da68a18

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {reducer, State, toggleFavoriteBuilding} from '../parts/buildings'
2+
3+
describe('toggle favorite building hours', () => {
4+
it('should return the initial state', () => {
5+
const {favorites} = reducer(undefined, {type: undefined})
6+
expect(favorites).toEqual([])
7+
})
8+
9+
it('should handle a favorite being added to an empty list', () => {
10+
const previousState: State = {favorites: []}
11+
const {favorites} = reducer(previousState, toggleFavoriteBuilding('a'))
12+
expect(favorites).toEqual(['a'])
13+
})
14+
15+
it('should handle a favorite being added to an existing list', () => {
16+
const previousState: State = {favorites: ['a', 'b']}
17+
const {favorites} = reducer(previousState, toggleFavoriteBuilding('c'))
18+
expect(favorites).toEqual(['a', 'b', 'c'])
19+
})
20+
21+
it('should handle a favorite being removed from an existing list', () => {
22+
const previousState: State = {favorites: ['a']}
23+
const {favorites} = reducer(previousState, toggleFavoriteBuilding('a'))
24+
expect(favorites).toEqual([])
25+
})
26+
27+
it('should handle a favorite being removed from an existing list of multiple favorites', () => {
28+
const previousState: State = {favorites: ['a', 'b']}
29+
const {favorites} = reducer(previousState, toggleFavoriteBuilding('a'))
30+
expect(favorites).toEqual(['b'])
31+
})
32+
})

source/redux/parts/buildings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {createSlice} from '@reduxjs/toolkit'
22
import type {PayloadAction} from '@reduxjs/toolkit'
33
import type {RootState} from '../store'
44

5-
type State = {
5+
export type State = {
66
favorites: Array<string>
77
}
88

0 commit comments

Comments
 (0)