forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM] Fix rule delete/duplicate actions (elastic#59306)
- Loading branch information
1 parent
0522b39
commit ef5e095
Showing
2 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import uuid from 'uuid'; | ||
import { createMemoryHistory } from 'history'; | ||
|
||
const history = createMemoryHistory(); | ||
|
||
import { mockRule } from './__mocks__/mock'; | ||
import { getActions } from './columns'; | ||
|
||
jest.mock('./actions', () => ({ | ||
duplicateRulesAction: jest.fn(), | ||
deleteRulesAction: jest.fn(), | ||
})); | ||
|
||
import { duplicateRulesAction, deleteRulesAction } from './actions'; | ||
|
||
describe('AllRulesTable Columns', () => { | ||
describe('getActions', () => { | ||
const rule = mockRule(uuid.v4()); | ||
let results: string[] = []; | ||
const dispatch = jest.fn(); | ||
const dispatchToaster = jest.fn(); | ||
const reFetchRules = jest.fn(); | ||
|
||
beforeEach(() => { | ||
results = []; | ||
|
||
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(() => { | ||
results.push('duplicateRulesAction'); | ||
resolve(); | ||
}, 500) | ||
) | ||
); | ||
|
||
const duplicateRulesActionObject = getActions( | ||
dispatch, | ||
dispatchToaster, | ||
history, | ||
reFetchRules | ||
)[1]; | ||
await duplicateRulesActionObject.onClick(rule); | ||
expect(results).toEqual(['duplicateRulesAction', 'reFetchRules']); | ||
}); | ||
|
||
test('delete rule onClick should call refetch after the rule is deleted', async () => { | ||
(deleteRulesAction as jest.Mock).mockImplementation( | ||
() => | ||
new Promise(resolve => | ||
setTimeout(() => { | ||
results.push('deleteRulesAction'); | ||
resolve(); | ||
}, 500) | ||
) | ||
); | ||
|
||
const deleteRulesActionObject = getActions( | ||
dispatch, | ||
dispatchToaster, | ||
history, | ||
reFetchRules | ||
)[3]; | ||
await deleteRulesActionObject.onClick(rule); | ||
expect(results).toEqual(['deleteRulesAction', 'reFetchRules']); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters