Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski committed Mar 4, 2020
1 parent 0472c1f commit 2f58f71
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { duplicateRulesAction, deleteRulesAction } from './actions';
describe('AllRulesTable Columns', () => {
describe('getActions', () => {
const rule = mockRule(uuid.v4());
let actions: ReturnType<typeof getActions>;
let results: string[] = [];
const dispatch = jest.fn();
const dispatchToaster = jest.fn();
Expand All @@ -31,21 +30,30 @@ describe('AllRulesTable Columns', () => {
beforeEach(() => {
results = [];

reFetchRules.mockImplementation(() => Promise.resolve(results.push('reFetchRules')));
reFetchRules.mockImplementation(() => {
results.push('reFetchRules');
Promise.resolve();
});
});

test('duplicate rule onClick should call refetch after the rule is duplicated', async () => {
(duplicateRulesAction as jest.Mock).mockImplementation(
() =>
new Promise(resolve =>
setTimeout(() => {
resolve(results.push('duplicateRulesAction'));
results.push('duplicateRulesAction');
resolve();
}, 500)
)
);

actions = getActions(dispatch, dispatchToaster, history, reFetchRules);
await actions[1].onClick(rule);
const duplicateRulesActionObject = getActions(
dispatch,
dispatchToaster,
history,
reFetchRules
)[1];
await duplicateRulesActionObject.onClick(rule);
expect(results).toEqual(['duplicateRulesAction', 'reFetchRules']);
});

Expand All @@ -54,13 +62,19 @@ describe('AllRulesTable Columns', () => {
() =>
new Promise(resolve =>
setTimeout(() => {
resolve(results.push('deleteRulesAction'));
results.push('deleteRulesAction');
resolve();
}, 500)
)
);

actions = getActions(dispatch, dispatchToaster, history, reFetchRules);
await actions[3].onClick(rule);
const deleteRulesActionObject = getActions(
dispatch,
dispatchToaster,
history,
reFetchRules
)[3];
await deleteRulesActionObject.onClick(rule);
expect(results).toEqual(['deleteRulesAction', 'reFetchRules']);
});
});
Expand Down

0 comments on commit 2f58f71

Please sign in to comment.