|
1 | 1 | import { describe, it } from 'mocha';
|
2 | 2 | import expect from 'expect';
|
3 | 3 | import Immutable from 'immutable';
|
| 4 | +import { createSelector } from 'reselect'; |
| 5 | + |
4 | 6 | import { initialReducerState } from '../src/ReduxWPAPI';
|
5 |
| -import { selectQuery } from '../src/selectors'; |
| 7 | +import { selectQuery, withDenormalize } from '../src/selectors'; |
6 | 8 | import { pending, resolved } from '../src/constants/requestStatus';
|
7 | 9 |
|
8 |
| -describe('Selector', () => { |
| 10 | +describe('Selector selectQuery', () => { |
9 | 11 | it('should return a Request for empty state', () => {
|
10 | 12 | const state = { wp: initialReducerState };
|
11 | 13 | expect(selectQuery('test')(state))
|
@@ -141,3 +143,31 @@ describe('Selector', () => {
|
141 | 143 | });
|
142 | 144 | });
|
143 | 145 |
|
| 146 | + |
| 147 | +describe('withDenormalize', () => { |
| 148 | + it('should allow consumers to denormalize resources by local ids within selector', () => { |
| 149 | + const resources = [ |
| 150 | + { id: 1, |
| 151 | + title: 'lol', |
| 152 | + _links: { parent: { url: 'http://dumb.com/test/2' } }, |
| 153 | + _embedded: { parent: 1 }, |
| 154 | + }, |
| 155 | + { id: 2, title: 'lol 2' }, |
| 156 | + ]; |
| 157 | + const storeState = { |
| 158 | + wp: ( |
| 159 | + initialReducerState |
| 160 | + .setIn(['resources'], new Immutable.List(resources)) |
| 161 | + ), |
| 162 | + }; |
| 163 | + |
| 164 | + const selector = withDenormalize( |
| 165 | + createSelector( |
| 166 | + () => 1, |
| 167 | + id => denormalize => denormalize(id) |
| 168 | + ) |
| 169 | + ); |
| 170 | + const selectedState = selector(storeState); |
| 171 | + expect(selectedState).toInclude(resources[1]); |
| 172 | + }); |
| 173 | +}); |
0 commit comments