Skip to content

Commit

Permalink
Add toast support and assert existance of page element to make test u…
Browse files Browse the repository at this point in the history
…nflaky

Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Apr 2, 2024
1 parent 7c5b928 commit 79af313
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ import { useToastState } from '../../utils/toast-utils';
import { setCrossPageToast } from '../../utils/storage-utils';
import { SecurityPluginTopNavMenu } from '../../top-nav-menu';
import { DataSourceContext } from '../../app-router';
import { createDataSourceQuery } from '../../../../utils/datasource-utils';
import { createDataSourceQuery, getClusterInfoIfEnabled } from '../../../../utils/datasource-utils';

interface AuditLoggingEditSettingProps extends AppDependencies {
setting: 'general' | 'compliance';
}

export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) {
const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled;
const [editConfig, setEditConfig] = React.useState<AuditLoggingSettings>({});
const [toasts, addToast, removeToast] = useToastState();
const [invalidSettings, setInvalidSettings] = React.useState<string[]>([]);
Expand Down Expand Up @@ -132,9 +133,13 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) {
};

if (props.setting === 'general') {
addSuccessToast('General settings saved');
addSuccessToast(
`General settings saved ${getClusterInfoIfEnabled(dataSourceEnabled, dataSource)}`
);
} else {
addSuccessToast('Compliance settings saved');
addSuccessToast(
`Compliance settings saved ${getClusterInfoIfEnabled(dataSourceEnabled, dataSource)}`
);
}

window.location.href = buildHashUrl(ResourceType.auditLogging);
Expand All @@ -143,7 +148,11 @@ export function AuditLoggingEditSettings(props: AuditLoggingEditSettingProps) {
id: 'update-result',
color: 'danger',
iconType: 'alert',
title: 'Failed to update audit configuration due to ' + e?.message,
title:
`Failed to update audit configuration ${getClusterInfoIfEnabled(
dataSourceEnabled,
dataSource
)} due to ` + e?.message,
};

addToast(failureToast);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Audit logs edit', () => {
shallow(
<AuditLoggingEditSettings
coreStart={mockCoreStart as any}
navigation={{} as any}
depsStart={{}}
setting="general"
params={{} as any}
config={{} as any}
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Audit logs edit', () => {
shallow(
<AuditLoggingEditSettings
coreStart={mockCoreStart as any}
navigation={{} as any}
depsStart={{}}
setting="compliance"
params={{} as any}
config={{} as any}
Expand All @@ -116,7 +116,7 @@ describe('Audit logs edit', () => {
shallow(
<AuditLoggingEditSettings
coreStart={mockCoreStart as any}
navigation={{} as any}
depsStart={{}}
setting="compliance"
params={{} as any}
config={{} as any}
Expand All @@ -133,7 +133,7 @@ describe('Audit logs edit', () => {
const component = shallow(
<AuditLoggingEditSettings
coreStart={mockCoreStart as any}
navigation={{} as any}
depsStart={{}}
setting="compliance"
params={{} as any}
config={{} as any}
Expand All @@ -147,7 +147,7 @@ describe('Audit logs edit', () => {
const component = shallow(
<AuditLoggingEditSettings
coreStart={mockCoreStart as any}
navigation={{} as any}
depsStart={{}}
setting="compliance"
params={{} as any}
config={{} as any}
Expand All @@ -162,7 +162,7 @@ describe('Audit logs edit', () => {
const component = shallow(
<AuditLoggingEditSettings
coreStart={mockCoreStart as any}
navigation={{} as any}
depsStart={{}}
setting="general"
params={{} as any}
config={{} as any}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ describe('Multi-datasources enabled', () => {

it('Checks Audit Logs Tab', () => {
cy.visit('http://localhost:5601/app/security-dashboards-plugin#/auditLogging');
cy.get('[data-test-subj="general-settings"]').should('exist');

// Select remote cluster
cy.get('[data-test-subj="dataSourceSelectableContextMenuHeaderLink"]').click();
Expand Down

0 comments on commit 79af313

Please sign in to comment.