Skip to content

Commit

Permalink
Merge branch 'main' into 135678-unified-field-list-sections-in-discov…
Browse files Browse the repository at this point in the history
…er-2
  • Loading branch information
jughosta authored Dec 1, 2022
2 parents 82f62a0 + 7e035f4 commit 6bacfb2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/plugins/data/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ export function getUiSettings(
defaultMessage: 'Time filter refresh interval',
}),
value: `{
"pause": false,
"value": 0
"pause": true,
"value": 60000
}`,
type: 'json',
description: i18n.translate('data.advancedSettings.timepicker.refreshIntervalDefaultsText', {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/discover/group1/_shared_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const expectedUrl =
baseUrl +
'/app/discover?_t=1453775307251#' +
'/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time' +
'/?_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time' +
":(from:'2015-09-19T06:31:44.000Z',to:'2015-09" +
"-23T18:31:44.000Z'))&_a=(columns:!(),filters:!(),index:'logstash-" +
"*',interval:auto,query:(language:kuery,query:'')" +
Expand All @@ -102,7 +102,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
baseUrl +
'/app/discover#' +
'/view/ab12e3c0-f231-11e6-9486-733b1ac9221a' +
'?_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A0)' +
'?_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A60000)' +
"%2Ctime%3A(from%3A'2015-09-19T06%3A31%3A44.000Z'%2C" +
"to%3A'2015-09-23T18%3A31%3A44.000Z'))";
await PageObjects.discover.loadSavedSearch('A Saved Search');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const getColor = (type: Props['type']): EuiBadgeProps['color'] => {
};

export const CspEvaluationBadge = ({ type }: Props) => (
<EuiBadge color={getColor(type)} style={{ width: BADGE_WIDTH, textAlign: 'center' }}>
<EuiBadge
color={getColor(type)}
style={{ width: BADGE_WIDTH, textAlign: 'center' }}
data-test-subj={`${type}_finding`}
>
{type === 'failed' ? (
<FormattedMessage id="xpack.csp.cspEvaluationBadge.failLabel" defaultMessage="Fail" />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ const DistributionBar: React.FC<Omit<Props, 'pageEnd' | 'pageStart'>> = ({
distributionOnClick={() => {
distributionOnClick(RULE_PASSED);
}}
data-test-subj="distribution_bar_passed"
/>
<DistributionBarPart
value={failed}
color={euiTheme.colors.danger}
distributionOnClick={() => {
distributionOnClick(RULE_FAILED);
}}
data-test-subj="distribution_bar_failed"
/>
</EuiFlexGroup>
);
Expand All @@ -142,12 +144,15 @@ const DistributionBarPart = ({
value,
color,
distributionOnClick,
...rest
}: {
value: number;
color: string;
distributionOnClick: () => void;
['data-test-subj']: string;
}) => (
<button
data-test-subj={rest['data-test-subj']}
onClick={distributionOnClick}
css={css`
flex: ${value};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export const useRefreshInterval = (

function initAutoRefresh() {
const interval = globalState?.refreshInterval ?? timefilter.getRefreshInterval();
const { value } = interval;
const { pause, value } = interval;

if (value === 0) {
if (pause === true || value === 0) {
// the auto refresher starts in an off state
// so switch it on and set the interval to 30s
timefilter.setRefreshInterval({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PageWrapper: FC<PageProps> = ({ deps }) => {

useEffect(() => {
const refreshInterval =
refreshValue === 0 && refreshPause === true
refreshValue === 0 || refreshPause === true
? { pause: false, value: DEFAULT_REFRESH_INTERVAL_MS }
: { pause: refreshPause, value: refreshValue };
timefilter.setRefreshInterval(refreshInterval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
},
};

const distributionBar = {
filterBy: async (type: 'passed' | 'failed') =>
testSubjects.click(type === 'failed' ? 'distribution_bar_failed' : 'distribution_bar_passed'),
};

const table = {
getElement: () => testSubjects.find('findings_table'),

Expand Down Expand Up @@ -76,6 +81,12 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
return rows.length;
},

getFindingsCount: async (type: 'passed' | 'failed') => {
const element = await table.getElement();
const items = await element.findAllByCssSelector(`span[data-test-subj="${type}_finding"]`);
return items.length;
},

getRowIndexForValue: async (columnName: string, value: string) => {
const values = await table.getColumnValues(columnName);
const rowIndex = values.indexOf(value);
Expand Down Expand Up @@ -160,5 +171,6 @@ export function FindingsPageProvider({ getService, getPageObjects }: FtrProvider
navigateToFindingsPage,
table,
index,
distributionBar,
};
}
17 changes: 16 additions & 1 deletion x-pack/test/cloud_security_posture_functional/pages/findings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const data = Array.from({ length: 2 }, (_, id) => {
return {
resource: { id, name: `Resource ${id}` },
result: { evaluation: 'passed' },
result: { evaluation: id === 0 ? 'passed' : 'failed' },
rule: {
name: `Rule ${id}`,
section: 'Kubelet',
Expand All @@ -34,10 +34,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
describe('Findings Page', () => {
let findings: typeof pageObjects.findings;
let table: typeof pageObjects.findings.table;
let distributionBar: typeof pageObjects.findings.distributionBar;

before(async () => {
findings = pageObjects.findings;
table = pageObjects.findings.table;
distributionBar = pageObjects.findings.distributionBar;

await findings.index.add(data);
await findings.navigateToFindingsPage();
Expand Down Expand Up @@ -108,5 +110,18 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await table.toggleColumnSortOrFail('Resource Name', 'desc');
});
});

describe('DistributionBar', () => {
(['passed', 'failed'] as const).forEach((type) => {
it(`filters by ${type} findings`, async () => {
await distributionBar.filterBy(type);

const items = data.filter(({ result }) => result.evaluation === type);
expect(await table.getFindingsCount(type)).to.eql(items.length);

await filterBar.removeFilter('result.evaluation');
});
});
});
});
}

0 comments on commit 6bacfb2

Please sign in to comment.