|
| 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 | +}) |
0 commit comments