Skip to content

Commit

Permalink
WIP unittests, redux state function
Browse files Browse the repository at this point in the history
  • Loading branch information
reebalazs committed Jun 20, 2024
1 parent a017a91 commit 02428df
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/reducers/solrsearch/solrSearchSuggestions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import searchSuggestions from './solrSearchSuggestions';
import { GET_SOLR_SEARCH_SUGGESTIONS } from '../../actions/solrsearch/solrSearchSuggestions';

describe('SOLR search suggestions reducer', () => {
it('should return the initial state', () => {
expect(searchSuggestions()).toEqual({
error: null,
items: [],
loaded: false,
loading: false,
});
});

it('should handle GET_SOLR_SEARCH_SUGGESTIONS_PENDING', () => {
expect(
searchSuggestions(undefined, {
type: `${GET_SOLR_SEARCH_SUGGESTIONS}_PENDING`,
}),
).toEqual({
error: null,
items: [],
loaded: false,
loading: true,
});
});

it('should handle GET_SOLR_SEARCH_SUGGESTIONS_SUCCESS', () => {
expect(
searchSuggestions(undefined, {
type: `${GET_SOLR_SEARCH_SUGGESTIONS}_SUCCESS`,
result: {
suggestions: ['{DOC1}', '{DOC2}'],
},
}),
).toEqual({
error: null,
items: ['{DOC1}', '{DOC2}'],
loaded: true,
loading: false,
});
});

it('should handle GET_SOLR_SEARCH_SUGGESTIONS_FAIL', () => {
expect(
searchSuggestions(undefined, {
type: `${GET_SOLR_SEARCH_SUGGESTIONS}_FAIL`,
error: 'failed',
}),
).toEqual({
error: 'failed',
items: [],
loaded: false,
loading: false,
});
});
});

0 comments on commit 02428df

Please sign in to comment.