|
1 | 1 | import { assert } from 'vitest';
|
2 |
| -import { getItems, replaceItems } from '../../src'; |
| 2 | +import { actOnDispatch, getItems, replaceItems } from '../../src'; |
3 | 3 |
|
4 | 4 | // Tests when context.params._actOn === 'dispatch' are in act-on.test.ts
|
5 | 5 |
|
@@ -183,4 +183,59 @@ describe('services getItems & replaceItems', () => {
|
183 | 183 | assert.deepEqual(hookFindPaginate.result.data, [{ a: 1 }, { b: 2 }]);
|
184 | 184 | });
|
185 | 185 | });
|
| 186 | + |
| 187 | + describe('replaceItems actOnDispatch', () => { |
| 188 | + beforeEach(() => { |
| 189 | + hookBefore = { type: 'before', method: 'create', params: { provider: 'rest' } }; |
| 190 | + hookAfter = { type: 'after', method: 'create', params: { provider: 'rest' } }; |
| 191 | + hookFindPaginate = { |
| 192 | + type: 'after', |
| 193 | + method: 'find', |
| 194 | + params: { provider: 'rest' }, |
| 195 | + dispatch: { |
| 196 | + total: 200, |
| 197 | + data: [], |
| 198 | + }, |
| 199 | + }; |
| 200 | + hookFind = { |
| 201 | + type: 'after', |
| 202 | + method: 'find', |
| 203 | + params: { provider: 'rest' }, |
| 204 | + }; |
| 205 | + }); |
| 206 | + |
| 207 | + it('updates hook after::create item', async () => { |
| 208 | + await actOnDispatch(() => replaceItems(hookAfter, { a: 1 }))(hookAfter); |
| 209 | + assert.deepEqual(hookAfter.dispatch, { a: 1 }); |
| 210 | + }); |
| 211 | + |
| 212 | + it('updates hook after::create items', async () => { |
| 213 | + await actOnDispatch(() => replaceItems(hookAfter, [{ a: 1 }, { b: 2 }]))(hookAfter); |
| 214 | + assert.deepEqual(hookAfter.dispatch, [{ a: 1 }, { b: 2 }]); |
| 215 | + }); |
| 216 | + |
| 217 | + it('updates hook after::find item', async () => { |
| 218 | + await actOnDispatch(() => replaceItems(hookFind, { a: 1 }))(hookFind); |
| 219 | + assert.deepEqual(hookFind.dispatch, { a: 1 }); |
| 220 | + }); |
| 221 | + |
| 222 | + it('updates hook after::find items', async () => { |
| 223 | + await actOnDispatch(() => replaceItems(hookFind, [{ a: 1 }, { b: 2 }]))(hookFind); |
| 224 | + assert.deepEqual(hookFind.dispatch, [{ a: 1 }, { b: 2 }]); |
| 225 | + }); |
| 226 | + |
| 227 | + it('updates hook after::find item paginated NOTE THIS TEST NOTE THIS TEST', async () => { |
| 228 | + await actOnDispatch(() => replaceItems(hookFindPaginate, { a: 1 }))(hookFindPaginate); |
| 229 | + assert.equal(hookFindPaginate.dispatch.total, 200); |
| 230 | + assert.deepEqual(hookFindPaginate.dispatch.data, [{ a: 1 }]); |
| 231 | + }); |
| 232 | + |
| 233 | + it('updates hook after::find items paginated', async () => { |
| 234 | + await actOnDispatch(() => replaceItems(hookFindPaginate, [{ a: 1 }, { b: 2 }]))( |
| 235 | + hookFindPaginate, |
| 236 | + ); |
| 237 | + assert.equal(hookFindPaginate.dispatch.total, 200); |
| 238 | + assert.deepEqual(hookFindPaginate.dispatch.data, [{ a: 1 }, { b: 2 }]); |
| 239 | + }); |
| 240 | + }); |
186 | 241 | });
|
0 commit comments