-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
133 additions
and
0 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,133 @@ | ||
import deepFreeze from 'deep-freeze'; | ||
import tags from '../../app/assets/javascripts/reducers/tags'; | ||
import { | ||
RECEIVE_TAGS, | ||
RECEIVE_ALL_TAGS, | ||
ADD_TAG, | ||
REMOVE_TAG | ||
} from '../../app/assets/javascripts/constants'; | ||
|
||
|
||
describe('tags', () => { | ||
it('should return the initial state', () => { | ||
const initialState = { | ||
tags: [], | ||
allTags: [] | ||
}; | ||
deepFreeze(initialState); | ||
|
||
const result = tags(undefined, {}); | ||
expect(result).toEqual(initialState); | ||
}); | ||
|
||
it('should handle ADD_TAG action', () => { | ||
const prevState = { | ||
tags: ['existingTag'], | ||
allTags: [] | ||
}; | ||
deepFreeze(prevState); | ||
|
||
const action = { | ||
type: ADD_TAG, | ||
data: { | ||
course: { | ||
tags: ['existingTag', 'newTag'] | ||
} | ||
} | ||
}; | ||
|
||
const result = tags(prevState, action); | ||
|
||
expect(result).toEqual({ | ||
tags: ['existingTag', 'newTag'], | ||
allTags: [] | ||
}); | ||
}); | ||
it('should handle REMOVE_TAG action', () => { | ||
const prevState = { | ||
tags: ['existingTag', 'tagToRemove'], | ||
allTags: [] | ||
}; | ||
deepFreeze(prevState); | ||
|
||
const action = { | ||
type: REMOVE_TAG, | ||
data: { | ||
course: { | ||
tags: ['tagToRemove'] | ||
} | ||
} | ||
}; | ||
|
||
const result = tags(prevState, action); | ||
|
||
expect(result).toEqual({ | ||
tags: ['tagToRemove'], // Assuming your reducer directly replaces tags with the provided tags | ||
allTags: [] | ||
}); | ||
}); | ||
|
||
|
||
|
||
it('should handle RECEIVE_TAGS action', () => { | ||
const prevState = { | ||
tags: [], | ||
allTags: [] | ||
}; | ||
deepFreeze(prevState); | ||
|
||
const action = { | ||
type: RECEIVE_TAGS, | ||
data: { | ||
course: { | ||
tags: ['tag1', 'tag2'] | ||
} | ||
} | ||
}; | ||
|
||
const result = tags(prevState, action); | ||
|
||
expect(result).toEqual({ | ||
tags: ['tag1', 'tag2'], | ||
allTags: [] | ||
}); | ||
}); | ||
|
||
it('should handle RECEIVE_ALL_TAGS action', () => { | ||
const prevState = { | ||
tags: [], | ||
allTags: ['existingTag'] | ||
}; | ||
deepFreeze(prevState); | ||
|
||
const action = { | ||
type: RECEIVE_ALL_TAGS, | ||
data: { | ||
values: ['tag1', 'tag2'] | ||
} | ||
}; | ||
|
||
const result = tags(prevState, action); | ||
|
||
expect(result).toEqual({ | ||
tags: [], | ||
allTags: ['tag1', 'tag2'] | ||
}); | ||
}); | ||
|
||
it('should return the current state for unknown action types', () => { | ||
const prevState = { | ||
tags: ['existingTag'], | ||
allTags: [] | ||
}; | ||
deepFreeze(prevState); | ||
|
||
const action = { | ||
type: 'UNKNOWN_ACTION_TYPE' | ||
}; | ||
|
||
const result = tags(prevState, action); | ||
|
||
expect(result).toEqual(prevState); | ||
}); | ||
}); |