-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] Per-field diffs test coverage #177399
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
172 changes: 172 additions & 0 deletions
172
...detection_engine/rule_management/components/rule_details/per_field_rule_diff_tab.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,172 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
KqlQueryType, | ||
ThreeWayDiffOutcome, | ||
ThreeWayMergeOutcome, | ||
} from '../../../../../common/api/detection_engine'; | ||
import type { PartialRuleDiff } from '../../../../../common/api/detection_engine'; | ||
import { TestProviders } from '../../../../common/mock'; | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { PerFieldRuleDiffTab } from './per_field_rule_diff_tab'; | ||
|
||
const ruleFieldsDiffBaseFieldsMock = { | ||
diff_outcome: ThreeWayDiffOutcome.StockValueCanUpdate, | ||
has_conflict: false, | ||
has_update: true, | ||
merge_outcome: ThreeWayMergeOutcome.Target, | ||
}; | ||
|
||
const ruleFieldsDiffMock: PartialRuleDiff = { | ||
fields: { | ||
version: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: 1, | ||
current_version: 1, | ||
merged_version: 2, | ||
target_version: 2, | ||
}, | ||
}, | ||
has_conflict: false, | ||
}; | ||
|
||
const renderPerFieldRuleDiffTab = (ruleDiff: PartialRuleDiff) => { | ||
return render( | ||
<TestProviders> | ||
<PerFieldRuleDiffTab ruleDiff={ruleDiff} /> | ||
</TestProviders> | ||
); | ||
}; | ||
|
||
describe('PerFieldRuleDiffTab', () => { | ||
test('Field groupings should be rendered together in the same accordion panel', () => { | ||
const mockData: PartialRuleDiff = { | ||
...ruleFieldsDiffMock, | ||
fields: { | ||
kql_query: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: { | ||
filters: [], | ||
language: 'lucene', | ||
query: 'old query', | ||
type: KqlQueryType.inline_query, | ||
}, | ||
current_version: { | ||
filters: [], | ||
language: 'lucene', | ||
query: 'old query', | ||
type: KqlQueryType.inline_query, | ||
}, | ||
merged_version: { | ||
filters: [], | ||
language: 'kuery', | ||
query: 'new query', | ||
type: KqlQueryType.inline_query, | ||
}, | ||
target_version: { | ||
filters: [], | ||
language: 'kuery', | ||
query: 'new query', | ||
type: KqlQueryType.inline_query, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const wrapper = renderPerFieldRuleDiffTab(mockData); | ||
|
||
const matchedSubtitleElements = wrapper.queryAllByTestId('ruleUpgradePerFieldDiffSubtitle'); | ||
const subtitles = matchedSubtitleElements.map((element) => element.textContent); | ||
|
||
dplumlee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// `filters` and `type` have not changed between versions so shouldn't be displayed | ||
expect(subtitles).toEqual(['Query', 'Language']); | ||
}); | ||
|
||
describe('Undefined values are displayed with empty diffs', () => { | ||
test('Displays only an updated field value when changed from undefined', () => { | ||
const mockData: PartialRuleDiff = { | ||
...ruleFieldsDiffMock, | ||
fields: { | ||
timestamp_field: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: undefined, | ||
current_version: undefined, | ||
merged_version: 'new timestamp field', | ||
target_version: 'new timestamp field', | ||
}, | ||
}, | ||
}; | ||
const wrapper = renderPerFieldRuleDiffTab(mockData); | ||
const diffContent = wrapper.getByTestId('ruleUpgradePerFieldDiffContent').textContent; | ||
|
||
// Only the new timestamp field should be displayed | ||
expect(diffContent).toEqual('+new timestamp field'); | ||
}); | ||
|
||
test('Displays only an outdated field value when incoming update is undefined', () => { | ||
const mockData: PartialRuleDiff = { | ||
...ruleFieldsDiffMock, | ||
fields: { | ||
timestamp_field: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: 'old timestamp field', | ||
current_version: 'old timestamp field', | ||
merged_version: undefined, | ||
target_version: undefined, | ||
}, | ||
}, | ||
}; | ||
const wrapper = renderPerFieldRuleDiffTab(mockData); | ||
const diffContent = wrapper.getByTestId('ruleUpgradePerFieldDiffContent').textContent; | ||
|
||
// Only the old timestamp_field should be displayed | ||
expect(diffContent).toEqual('-old timestamp field'); | ||
}); | ||
}); | ||
|
||
test('Field diff components have the same grouping and order as in rule details overview', () => { | ||
const mockData: PartialRuleDiff = { | ||
...ruleFieldsDiffMock, | ||
fields: { | ||
setup: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: 'old setup', | ||
current_version: 'old setup', | ||
merged_version: 'new setup', | ||
target_version: 'new setup', | ||
}, | ||
timestamp_field: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: undefined, | ||
current_version: undefined, | ||
merged_version: 'new timestamp', | ||
target_version: 'new timestamp', | ||
}, | ||
name: { | ||
...ruleFieldsDiffBaseFieldsMock, | ||
base_version: 'old name', | ||
current_version: 'old name', | ||
merged_version: 'new name', | ||
target_version: 'new name', | ||
}, | ||
}, | ||
}; | ||
const wrapper = renderPerFieldRuleDiffTab(mockData); | ||
|
||
const matchedSectionElements = wrapper.queryAllByTestId('ruleUpgradePerFieldDiffSectionHeader'); | ||
const sectionLabels = matchedSectionElements.map((element) => element.textContent); | ||
|
||
// Schedule doesn't have any fields in the diff and shouldn't be displayed | ||
expect(sectionLabels).toEqual(['About', 'Definition', 'Setup guide']); | ||
|
||
const matchedFieldElements = wrapper.queryAllByTestId('ruleUpgradePerFieldDiffLabel'); | ||
const fieldLabels = matchedFieldElements.map((element) => element.textContent); | ||
|
||
expect(fieldLabels).toEqual(['Name', 'Timestamp Field', 'Setup']); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I get it right the tooltip isn't implement yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we are pushing it back since we're not sure how best to implement it yet. I figured the best move would be to take it off here for now, but maybe we leave it in and just make a note to rewrite the test whenever it becomes available? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion a note in the test plan should convey the intention much better.