Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update tests for replaceItems with actOnDispatch #752

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion test/hooks/get-replace-items.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from 'vitest';
import { getItems, replaceItems } from '../../src';
import { actOnDispatch, getItems, replaceItems } from '../../src';

// Tests when context.params._actOn === 'dispatch' are in act-on.test.ts

Expand Down Expand Up @@ -183,4 +183,59 @@ describe('services getItems & replaceItems', () => {
assert.deepEqual(hookFindPaginate.result.data, [{ a: 1 }, { b: 2 }]);
});
});

describe('replaceItems actOnDispatch', () => {
beforeEach(() => {
hookBefore = { type: 'before', method: 'create', params: { provider: 'rest' } };
hookAfter = { type: 'after', method: 'create', params: { provider: 'rest' } };
hookFindPaginate = {
type: 'after',
method: 'find',
params: { provider: 'rest' },
dispatch: {
total: 200,
data: [],
},
};
hookFind = {
type: 'after',
method: 'find',
params: { provider: 'rest' },
};
});

it('updates hook after::create item', async () => {
await actOnDispatch(() => replaceItems(hookAfter, { a: 1 }))(hookAfter);
assert.deepEqual(hookAfter.dispatch, { a: 1 });
});

it('updates hook after::create items', async () => {
await actOnDispatch(() => replaceItems(hookAfter, [{ a: 1 }, { b: 2 }]))(hookAfter);
assert.deepEqual(hookAfter.dispatch, [{ a: 1 }, { b: 2 }]);
});

it('updates hook after::find item', async () => {
await actOnDispatch(() => replaceItems(hookFind, { a: 1 }))(hookFind);
assert.deepEqual(hookFind.dispatch, { a: 1 });
});

it('updates hook after::find items', async () => {
await actOnDispatch(() => replaceItems(hookFind, [{ a: 1 }, { b: 2 }]))(hookFind);
assert.deepEqual(hookFind.dispatch, [{ a: 1 }, { b: 2 }]);
});

it('updates hook after::find item paginated NOTE THIS TEST NOTE THIS TEST', async () => {
await actOnDispatch(() => replaceItems(hookFindPaginate, { a: 1 }))(hookFindPaginate);
assert.equal(hookFindPaginate.dispatch.total, 200);
assert.deepEqual(hookFindPaginate.dispatch.data, [{ a: 1 }]);
});

it('updates hook after::find items paginated', async () => {
await actOnDispatch(() => replaceItems(hookFindPaginate, [{ a: 1 }, { b: 2 }]))(
hookFindPaginate,
);
assert.equal(hookFindPaginate.dispatch.total, 200);
assert.deepEqual(hookFindPaginate.dispatch.data, [{ a: 1 }, { b: 2 }]);
});
});
});
Loading