-
Notifications
You must be signed in to change notification settings - Fork 183
ROX-34990: Add Between date range condition to date filter input #21051
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
Open
sachaudh
wants to merge
14
commits into
ROX-34989-date-range-filter-utils
Choose a base branch
from
ROX-34990-date-range-between-condition
base: ROX-34989-date-range-filter-utils
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ef8ea08
ROX-34990: Add Between date range condition to date filter input
sachaudh 851b34d
ROX-34990: Gate Between date condition behind feature flag
sachaudh 555cf07
ROX-34990: Move Between date condition opt-in to attribute inputProps
sachaudh 22b2244
refactor(ui): split single and range date filter bodies
sachaudh c808067
ROX-34990: Enable Between date condition on vulnerability views
sachaudh 52783de
fix(ui): keep user-chosen end date when date range start changes
sachaudh 6088507
test(ui): loosen date-picker inputProps assertion in config test
sachaudh 5c8f454
refactor(ui): drop useMemo around date range condition opt-in
sachaudh b9a5288
refactor(ui): simplify date filter parsing and default condition
sachaudh ba19692
fix(ui): guard against null date range serialization value
sachaudh 107cf98
feat(ui): enable Between date condition on all date filters
sachaudh c835476
fix(ui): apply On date filter despite empty condition prefix
sachaudh 33fb312
test(ui): assert defaulted end date in range re-default spec
sachaudh 747bbf4
test(ui): simplify condition selection helper in date filter spec
sachaudh 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
216 changes: 216 additions & 0 deletions
216
.../platform/src/Components/CompoundSearchFilter/components/SearchFilterConditionDate.cy.jsx
This file contains hidden or 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,216 @@ | ||
| import { Toolbar, ToolbarContent } from '@patternfly/react-core'; | ||
|
|
||
| import SearchFilterConditionDate from './SearchFilterConditionDate'; | ||
|
|
||
| const attribute = { | ||
| displayName: 'Discovered time', | ||
| filterChipLabel: 'CVE discovered time', | ||
| searchTerm: 'CVE Created Time', | ||
| inputType: 'date-picker', | ||
| }; | ||
|
|
||
| const selectors = { | ||
| conditionSelectToggle: 'button[aria-label="Condition selector toggle"]', | ||
| conditionSelectItems: '[aria-label="Condition selector menu"] li', | ||
| singleDateInput: 'input[aria-label="Filter by date"]', | ||
| startDateInput: 'input[aria-label="Filter by start date"]', | ||
| endDateInput: 'input[aria-label="Filter by end date"]', | ||
| applyButton: 'button[aria-label="Apply condition and date input to search"]', | ||
| }; | ||
|
|
||
| const endBeforeStartErrorText = 'The end date must be on or after the start date'; | ||
|
|
||
| function setup() { | ||
| const onSearch = cy.stub().as('onSearch'); | ||
|
|
||
| cy.mount( | ||
| <Toolbar> | ||
| <ToolbarContent> | ||
| <SearchFilterConditionDate attribute={attribute} onSearch={onSearch} /> | ||
| </ToolbarContent> | ||
| </Toolbar> | ||
| ); | ||
| } | ||
|
|
||
| function selectCondition(condition) { | ||
| cy.get(selectors.conditionSelectToggle).click(); | ||
| cy.get(`${selectors.conditionSelectItems} button:contains("${condition}")`).click(); | ||
| } | ||
|
|
||
| describe(Cypress.spec.relative, () => { | ||
| it('should include Between in the condition selector after Before/On/After', () => { | ||
| setup(); | ||
|
|
||
| cy.get(selectors.conditionSelectToggle).click(); | ||
|
|
||
| cy.get(selectors.conditionSelectItems).should('have.length', 4); | ||
| cy.get(selectors.conditionSelectItems).eq(0).should('have.text', 'Before'); | ||
| cy.get(selectors.conditionSelectItems).eq(1).should('have.text', 'On'); | ||
| cy.get(selectors.conditionSelectItems).eq(2).should('have.text', 'After'); | ||
| cy.get(selectors.conditionSelectItems).eq(3).should('have.text', 'Between'); | ||
| }); | ||
|
|
||
| it('should keep single-date apply behavior for the After condition', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('After'); | ||
|
|
||
| cy.get(selectors.singleDateInput).type('01/15/2034'); | ||
| cy.get(selectors.applyButton).click(); | ||
|
|
||
| cy.get('@onSearch').should('have.been.calledWithExactly', [ | ||
| { | ||
| action: 'APPEND', | ||
| category: 'CVE Created Time', | ||
| value: '>01/15/2034', | ||
| }, | ||
| ]); | ||
| cy.get(selectors.singleDateInput).should('have.value', ''); | ||
| }); | ||
|
|
||
| it('should apply the On condition as a bare date with no prefix', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('On'); | ||
|
|
||
| cy.get(selectors.singleDateInput).type('01/15/2034'); | ||
| cy.get(selectors.applyButton).click(); | ||
|
|
||
| cy.get('@onSearch').should('have.been.calledWithExactly', [ | ||
| { | ||
| action: 'APPEND', | ||
| category: 'CVE Created Time', | ||
| value: '01/15/2034', | ||
| }, | ||
| ]); | ||
| cy.get(selectors.singleDateInput).should('have.value', ''); | ||
| }); | ||
|
|
||
| it('should reveal start and end date inputs when Between is selected', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.singleDateInput).should('not.exist'); | ||
| cy.get(selectors.startDateInput).should('exist'); | ||
| cy.get(selectors.endDateInput).should('exist'); | ||
| }); | ||
|
|
||
| it('should disable the end date input until the start date is valid', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.endDateInput).should('be.disabled'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
|
|
||
| cy.get(selectors.endDateInput).should('be.enabled'); | ||
| // End date defaults to the day after the start date. | ||
| cy.get(selectors.endDateInput).should('have.value', '01/16/2034'); | ||
| }); | ||
|
|
||
| it('should keep a chosen end date when the start date changes to an earlier date', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
| cy.get(selectors.endDateInput).clear(); | ||
| cy.get(selectors.endDateInput).type('03/20/2034'); | ||
|
|
||
| cy.get(selectors.startDateInput).clear(); | ||
| cy.get(selectors.startDateInput).type('01/10/2034'); | ||
|
|
||
| cy.get(selectors.endDateInput).should('have.value', '03/20/2034'); | ||
| }); | ||
|
|
||
| it('should re-default the end date when the start date moves past it', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
| // The defaulted end date is before the new start date below. | ||
| cy.get(selectors.endDateInput).should('have.value', '01/16/2034'); | ||
| cy.get(selectors.startDateInput).clear(); | ||
| cy.get(selectors.startDateInput).type('02/01/2034'); | ||
|
|
||
| cy.get(selectors.endDateInput).should('have.value', '02/02/2034'); | ||
| }); | ||
|
|
||
| it('should apply a valid range as a tr/<startMs>-<endMs> value and clear the inputs', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
| cy.get(selectors.endDateInput).clear(); | ||
| cy.get(selectors.endDateInput).type('01/20/2034'); | ||
|
|
||
| cy.get(selectors.applyButton).click(); | ||
|
|
||
| const startMs = new Date(2034, 0, 15, 0, 0, 0, 0).getTime(); | ||
| const endMs = new Date(2034, 0, 20, 23, 59, 59, 999).getTime(); | ||
| cy.get('@onSearch').should('have.been.calledWithExactly', [ | ||
| { | ||
| action: 'APPEND', | ||
| category: 'CVE Created Time', | ||
| value: `tr/${startMs}-${endMs}`, | ||
| }, | ||
| ]); | ||
| cy.get(selectors.startDateInput).should('have.value', ''); | ||
| cy.get(selectors.endDateInput).should('have.value', ''); | ||
| }); | ||
|
|
||
| it('should apply a same-day range', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
| cy.get(selectors.endDateInput).clear(); | ||
| cy.get(selectors.endDateInput).type('01/15/2034'); | ||
|
|
||
| cy.get(selectors.applyButton).click(); | ||
|
|
||
| const startMs = new Date(2034, 0, 15, 0, 0, 0, 0).getTime(); | ||
| const endMs = new Date(2034, 0, 15, 23, 59, 59, 999).getTime(); | ||
| cy.get('@onSearch').should('have.been.calledWithExactly', [ | ||
| { | ||
| action: 'APPEND', | ||
| category: 'CVE Created Time', | ||
| value: `tr/${startMs}-${endMs}`, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should show an inline error and not emit when the end date is before the start date', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
| cy.get(selectors.endDateInput).clear(); | ||
| cy.get(selectors.endDateInput).type('01/10/2034'); | ||
|
|
||
| cy.contains(endBeforeStartErrorText).should('exist'); | ||
|
|
||
| cy.get(selectors.applyButton).click(); | ||
|
|
||
| cy.get('@onSearch').should('not.have.been.called'); | ||
| }); | ||
|
|
||
| it('should not emit when the end date is empty', () => { | ||
| setup(); | ||
|
|
||
| selectCondition('Between'); | ||
|
|
||
| cy.get(selectors.startDateInput).type('01/15/2034'); | ||
| cy.get(selectors.endDateInput).clear(); | ||
|
|
||
| cy.get(selectors.applyButton).click(); | ||
|
|
||
| cy.get('@onSearch').should('not.have.been.called'); | ||
| }); | ||
| }); |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.