[Security Solutions] Unrevert and fix tests (#93834)
## Summary Unreverts: https://github.com/elastic/kibana/pull/93548 By fixing tests that are relying on date times to be less strict. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
This commit is contained in:
parent
b5ee9f451f
commit
972bf0adc1
|
@ -28,8 +28,8 @@ export const DEFAULT_SEARCH_AFTER_PAGE_SIZE = 100;
|
|||
export const DEFAULT_ANOMALY_SCORE = 'securitySolution:defaultAnomalyScore';
|
||||
export const DEFAULT_MAX_TABLE_QUERY_SIZE = 10000;
|
||||
export const DEFAULT_SCALE_DATE_FORMAT = 'dateFormat:scaled';
|
||||
export const DEFAULT_FROM = 'now-24h';
|
||||
export const DEFAULT_TO = 'now';
|
||||
export const DEFAULT_FROM = 'now/d';
|
||||
export const DEFAULT_TO = 'now/d';
|
||||
export const DEFAULT_INTERVAL_PAUSE = true;
|
||||
export const DEFAULT_INTERVAL_TYPE = 'manual';
|
||||
export const DEFAULT_INTERVAL_VALUE = 300000; // ms
|
||||
|
|
|
@ -82,8 +82,8 @@ describe('QueryBar ', () => {
|
|||
|
||||
expect(searchBarProps).toEqual({
|
||||
dataTestSubj: undefined,
|
||||
dateRangeFrom: 'now-24h',
|
||||
dateRangeTo: 'now',
|
||||
dateRangeFrom: 'now/d',
|
||||
dateRangeTo: 'now/d',
|
||||
filters: [],
|
||||
indexPatterns: [
|
||||
{
|
||||
|
|
|
@ -79,8 +79,7 @@ const timepickerRanges = [
|
|||
},
|
||||
];
|
||||
|
||||
// FLAKY: https://github.com/elastic/kibana/issues/93735
|
||||
describe.skip('SIEM Super Date Picker', () => {
|
||||
describe('SIEM Super Date Picker', () => {
|
||||
describe('#SuperDatePicker', () => {
|
||||
const state: State = mockGlobalState;
|
||||
const { storage } = createSecuritySolutionStorageMock();
|
||||
|
@ -136,8 +135,8 @@ describe.skip('SIEM Super Date Picker', () => {
|
|||
expect(store.getState().inputs.global.timerange.kind).toBe('relative');
|
||||
});
|
||||
|
||||
test('Make Sure it is last 24 hours date', () => {
|
||||
expect(store.getState().inputs.global.timerange.fromStr).toBe('now-24h');
|
||||
test('Make Sure it is last "now-${x}h" where ${x} is in hours/minutes/seconds date', () => {
|
||||
expect(store.getState().inputs.global.timerange.fromStr).toMatch(/^now-[0-9]+/);
|
||||
expect(store.getState().inputs.global.timerange.toStr).toBe('now');
|
||||
});
|
||||
|
||||
|
@ -207,7 +206,7 @@ describe.skip('SIEM Super Date Picker', () => {
|
|||
expect(wrapper.find('div.euiQuickSelectPopover__section').at(1).text()).toBe('Today');
|
||||
});
|
||||
|
||||
test('Today and Last 24 hours are in Recently used date ranges', () => {
|
||||
test('Today and "Last ${x} hours" where ${x} is in hours are in Recently used date ranges', () => {
|
||||
wrapper
|
||||
.find('[data-test-subj="superDatePickerToggleQuickMenuButton"]')
|
||||
.first()
|
||||
|
@ -217,8 +216,8 @@ describe.skip('SIEM Super Date Picker', () => {
|
|||
wrapper.find('button.euiQuickSelect__applyButton').first().simulate('click');
|
||||
wrapper.update();
|
||||
|
||||
expect(wrapper.find('div.euiQuickSelectPopover__section').at(1).text()).toBe(
|
||||
'Last 24 hoursToday'
|
||||
expect(wrapper.find('div.euiQuickSelectPopover__section').at(1).text()).toMatch(
|
||||
/^Last\s[0-9]+\s(.)+Today/
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -276,10 +276,10 @@ describe('Inputs', () => {
|
|||
],
|
||||
timerange: {
|
||||
from: '2020-07-07T08:20:18.966Z',
|
||||
fromStr: 'now-24h',
|
||||
fromStr: 'now/d',
|
||||
kind: 'relative',
|
||||
to: '2020-07-08T08:20:18.966Z',
|
||||
toStr: 'now',
|
||||
toStr: 'now/d',
|
||||
},
|
||||
query: { query: '', language: 'kuery' },
|
||||
filters: [],
|
||||
|
@ -293,10 +293,10 @@ describe('Inputs', () => {
|
|||
queries: [],
|
||||
timerange: {
|
||||
from: '2020-07-07T08:20:18.966Z',
|
||||
fromStr: 'now-24h',
|
||||
fromStr: 'now/d',
|
||||
kind: 'relative',
|
||||
to: '2020-07-08T08:20:18.966Z',
|
||||
toStr: 'now',
|
||||
toStr: 'now/d',
|
||||
},
|
||||
query: { query: '', language: 'kuery' },
|
||||
filters: [],
|
||||
|
|
|
@ -315,6 +315,22 @@ describe('getTimeRangeSettings', () => {
|
|||
expect(to).toBe(new Date(DEFAULT_TO_DATE).toISOString());
|
||||
});
|
||||
|
||||
test('should round up "to" when from and to are both "now/d"', () => {
|
||||
const mockTo = 'now/d';
|
||||
const mockFrom = 'now/d';
|
||||
mockTimeRange({ from: mockFrom, to: mockTo });
|
||||
const { to } = getTimeRangeSettings();
|
||||
expect(to).toContain('59:59.999Z');
|
||||
});
|
||||
|
||||
test('should round up "to" when from and to are different date maths', () => {
|
||||
const mockTo = 'now/d';
|
||||
const mockFrom = 'now/d+1';
|
||||
mockTimeRange({ from: mockFrom, to: mockTo });
|
||||
const { to } = getTimeRangeSettings();
|
||||
expect(to).toContain('59:59.999Z');
|
||||
});
|
||||
|
||||
test('should return the DEFAULT_TO_DATE when the from value is malformed', () => {
|
||||
const malformedTimeRange = { from: true };
|
||||
if (isMalformedTimeRange(malformedTimeRange)) {
|
||||
|
@ -506,5 +522,10 @@ describe('getIntervalSettings', () => {
|
|||
const value = parseDateWithDefault('trashed string', moment('1950-05-31T13:03:54.234Z'));
|
||||
expect(value.toISOString()).toBe(new Date('1950-05-31T13:03:54.234Z').toISOString());
|
||||
});
|
||||
|
||||
test('should round up a valid date string and end with 59:59.999Z', () => {
|
||||
const value = parseDateWithDefault('now/d', moment('1950-05-31T13:03:54.234Z'), true);
|
||||
expect(value.toISOString()).toContain('59:59.999Z');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -51,8 +51,7 @@ export const getTimeRangeSettings = (uiSettings = true) => {
|
|||
const fromStr = (isString(timeRange?.from) && timeRange?.from) || DEFAULT_FROM;
|
||||
const toStr = (isString(timeRange?.to) && timeRange?.to) || DEFAULT_TO;
|
||||
const from = parseDateWithDefault(fromStr, DEFAULT_FROM_MOMENT).toISOString();
|
||||
const to = parseDateWithDefault(toStr, DEFAULT_TO_MOMENT).toISOString();
|
||||
|
||||
const to = parseDateWithDefault(toStr, DEFAULT_TO_MOMENT, true).toISOString();
|
||||
return { from, fromStr, to, toStr };
|
||||
};
|
||||
|
||||
|
@ -72,11 +71,18 @@ export const getIntervalSettings = (uiSettings = true): Policy => {
|
|||
return { kind, duration };
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a date and returns the default if the date string is not valid.
|
||||
* @param dateString The date string to parse
|
||||
* @param defaultDate The defaultDate if we cannot parse the dateMath
|
||||
* @returns The moment of the date time parsed
|
||||
*/
|
||||
export const parseDateWithDefault = (
|
||||
dateString: string,
|
||||
defaultDate: moment.Moment
|
||||
defaultDate: moment.Moment,
|
||||
roundUp: boolean = false
|
||||
): moment.Moment => {
|
||||
const date = dateMath.parse(dateString);
|
||||
const date = dateMath.parse(dateString, { roundUp });
|
||||
if (date != null && date.isValid()) {
|
||||
return date;
|
||||
} else {
|
||||
|
|
|
@ -34,7 +34,7 @@ describe('RecentCases', () => {
|
|||
wrapper.find(`[data-test-subj="no-cases-create-case"]`).first().simulate('click');
|
||||
expect(navigateToApp).toHaveBeenCalledWith('securitySolution:case', {
|
||||
path:
|
||||
"/create?sourcerer=(default:!('apm-*-transaction*','auditbeat-*','endgame-*','filebeat-*','logs-*','packetbeat-*','winlogbeat-*'))&timerange=(global:(linkTo:!(timeline),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now-24h,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now)),timeline:(linkTo:!(global),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now-24h,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now)))",
|
||||
"/create?sourcerer=(default:!('apm-*-transaction*','auditbeat-*','endgame-*','filebeat-*','logs-*','packetbeat-*','winlogbeat-*'))&timerange=(global:(linkTo:!(timeline),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now%2Fd,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now%2Fd)),timeline:(linkTo:!(global),timerange:(from:'2020-07-07T08:20:18.966Z',fromStr:now%2Fd,kind:relative,to:'2020-07-08T08:20:18.966Z',toStr:now%2Fd)))",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -96,8 +96,8 @@ describe('Timeline QueryBar ', () => {
|
|||
);
|
||||
const queryBarProps = wrapper.find(QueryBar).props();
|
||||
|
||||
expect(queryBarProps.dateRangeFrom).toEqual('now-24h');
|
||||
expect(queryBarProps.dateRangeTo).toEqual('now');
|
||||
expect(queryBarProps.dateRangeFrom).toEqual('now/d');
|
||||
expect(queryBarProps.dateRangeTo).toEqual('now/d');
|
||||
expect(queryBarProps.filterQuery).toEqual({ query: 'here: query', language: 'kuery' });
|
||||
expect(queryBarProps.savedQuery).toEqual(undefined);
|
||||
expect(queryBarProps.filters).toHaveLength(1);
|
||||
|
|
Loading…
Reference in a new issue