Skip to content

Commit

Permalink
Fix data-test-subj values
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Jul 10, 2023
1 parent 9dee22f commit bbd6894
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,46 @@ describe('Policy Details', () => {

describe('Malware Protection card', () => {
it('user should be able to see related rules', () => {
cy.getByTestSubj('malwareProtectionsForm').contains('related detection rules').click();
cy.getByTestSubj('endpointPolicyForm-malware').contains('related detection rules').click();

cy.url().should('contain', 'app/security/rules/management');
});

it('changing protection level should enable or disable user notification', () => {
cy.getByTestSubj('malwareProtectionSwitch').click();
cy.getByTestSubj('malwareProtectionSwitch').should('have.attr', 'aria-checked', 'true');
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').click();
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').should(
'have.attr',
'aria-checked',
'true'
);

// Default: Prevent + Notify user enabled
cy.getByTestSubj('malwareProtectionMode_prevent').find('input').should('be.checked');
cy.getByTestSubj('malwareUserNotificationCheckbox').should('be.checked');
cy.getByTestSubj('endpointPolicyForm-malware-protectionLevel-preventRadio')
.find('input')
.should('be.checked');
cy.getByTestSubj('endpointPolicyForm-malware-notifyUser-checkbox').should('be.checked');

// Changing to Detect -> Notify user disabled
cy.getByTestSubj('malwareProtectionMode_detect').find('label').click();
cy.getByTestSubj('malwareUserNotificationCheckbox').should('not.be.checked');
cy.getByTestSubj('endpointPolicyForm-malware-protectionLevel-detectRadio')
.find('label')
.click();
cy.getByTestSubj('endpointPolicyForm-malware-notifyUser-checkbox').should('not.be.checked');

// Changing back to Prevent -> Notify user enabled
cy.getByTestSubj('malwareProtectionMode_prevent').find('label').click();
cy.getByTestSubj('malwareUserNotificationCheckbox').should('be.checked');
cy.getByTestSubj('endpointPolicyForm-malware-protectionLevel-preventRadio')
.find('label')
.click();
cy.getByTestSubj('endpointPolicyForm-malware-notifyUser-checkbox').should('be.checked');
});

it('disabling protection should disable notification in yaml for every OS', () => {
// Enable malware protection and user notification
cy.getByTestSubj('malwareProtectionSwitch').click();
cy.getByTestSubj('malwareProtectionSwitch').should('have.attr', 'aria-checked', 'true');
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').click();
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').should(
'have.attr',
'aria-checked',
'true'
);
savePolicyForm();

yieldPolicyConfig().then((policyConfig) => {
Expand All @@ -78,8 +92,12 @@ describe('Policy Details', () => {
});

// disable malware protection
cy.getByTestSubj('malwareProtectionSwitch').click();
cy.getByTestSubj('malwareProtectionSwitch').should('have.attr', 'aria-checked', 'false');
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').click();
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').should(
'have.attr',
'aria-checked',
'false'
);
savePolicyForm();

yieldPolicyConfig().then((policyConfig) => {
Expand All @@ -96,11 +114,12 @@ describe('Policy Details', () => {
expect(policyConfig.windows.malware.mode).to.equal(ProtectionModes.off);
});

cy.getByTestSubj('malwareProtectionsForm').should('contain.text', 'Linux');
cy.getByTestSubj('malwareProtectionsForm').should('contain.text', 'Windows');
cy.getByTestSubj('malwareProtectionsForm').should('contain.text', 'Mac');
cy.getByTestSubj('endpointPolicyForm-malware-osValues').should(
'contain.text',
'Linux, Windows, Mac'
);

cy.getByTestSubj('malwareProtectionSwitch').click();
cy.getByTestSubj('endpointPolicyForm-malware-enableDisableSwitch').click();
savePolicyForm();

yieldPolicyConfig().then((policyConfig) => {
Expand All @@ -113,26 +132,38 @@ describe('Policy Details', () => {

describe('Ransomware Protection card', () => {
it('user should be able to see related rules', () => {
cy.getByTestSubj('ransomwareProtectionsForm').contains('related detection rules').click();
cy.getByTestSubj('endpointPolicyForm-ransomware').contains('related detection rules').click();

cy.url().should('contain', 'app/security/rules/management');
});

it('changing protection level should enable or disable user notification', () => {
cy.getByTestSubj('ransomwareProtectionSwitch').click();
cy.getByTestSubj('ransomwareProtectionSwitch').should('have.attr', 'aria-checked', 'true');
cy.getByTestSubj('endpointPolicyForm-ransomware-enableDisableSwitch').click();
cy.getByTestSubj('endpointPolicyForm-ransomware-enableDisableSwitch').should(
'have.attr',
'aria-checked',
'true'
);

// Default: Prevent + Notify user enabled
cy.getByTestSubj('ransomwareProtectionMode_prevent').find('input').should('be.checked');
cy.getByTestSubj('ransomwareUserNotificationCheckbox').should('be.checked');
cy.getByTestSubj('endpointPolicyForm-ransomware-protectionLevel-preventRadio')
.find('input')
.should('be.checked');
cy.getByTestSubj('endpointPolicyForm-ransomware-notifyUser-checkbox').should('be.checked');

// Changing to Detect -> Notify user disabled
cy.getByTestSubj('ransomwareProtectionMode_detect').find('label').click();
cy.getByTestSubj('ransomwareUserNotificationCheckbox').should('not.be.checked');
cy.getByTestSubj('`endpointPolicyForm-ransomware-protectionLevel-detectRadio')
.find('label')
.click();
cy.getByTestSubj('endpointPolicyForm-ransomware-notifyUser-checkbox').should(
'not.be.checked'
);

// Changing back to Prevent -> Notify user enabled
cy.getByTestSubj('ransomwareProtectionMode_prevent').find('label').click();
cy.getByTestSubj('ransomwareUserNotificationCheckbox').should('be.checked');
cy.getByTestSubj('endpointPolicyForm-ransomware-protectionLevel-preventRadio')
.find('label')
.click();
cy.getByTestSubj('endpointPolicyForm-ransomware-notifyUser-checkbox').should('be.checked');
});
});

Expand All @@ -143,9 +174,9 @@ describe('Policy Details', () => {
'linux.advanced.capture_env_vars',
];

cy.getByTestSubj('advancedPolicyButton').click();
cy.getByTestSubj('endpointPolicyForm-advancedSection-showButton').click();

cy.getByTestSubj('advancedPolicyPanel')
cy.getByTestSubj('endpointPolicyForm-advancedSection-settings')
.children()
.each(($child) => {
const settingName = $child.find('label').text();
Expand All @@ -167,8 +198,8 @@ describe('Policy Details', () => {
});

// Set agent.connection_delay entry for every OS
cy.getByTestSubj('advancedPolicyButton').click();
cy.getByTestSubj('advancedPolicyPanel')
cy.getByTestSubj('endpointPolicyForm-advancedSection-showButton').click();
cy.getByTestSubj('endpointPolicyForm-advancedSection-settings')
.children()
.each(($child) => {
const settingName = $child.find('label').text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const AdvancedSection = memo<AdvancedSectionProps>(
title={calloutTitle}
color="warning"
iconType="warning"
data-test-subj="policyAdvancedSettingsWarning"
data-test-subj={getTestId('warning')}
>
<p>{warningMessage}</p>
</EuiCallOut>
Expand All @@ -174,7 +174,7 @@ export const AdvancedSection = memo<AdvancedSectionProps>(
</h4>
</EuiText>

<EuiPanel data-test-subj="advancedPolicyPanel" paddingSize="s">
<EuiPanel data-test-subj={getTestId('settings')} paddingSize="s">
{AdvancedPolicySchema.map(
(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const BehaviourProtectionCard = memo<BehaviourProtectionCardProps>(
protection={protection}
protectionLabel={protectionLabel}
osList={BEHAVIOUR_OS_VALUES}
data-test-subj={getTestId()}
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const MalwareProtectionsCard = React.memo<MalwareProtectionsProps>(
policy={policy}
onChange={onChange}
mode={mode}
data-test-subj={getTestId('enableDisableSwitch')}
/>
}
>
Expand All @@ -107,14 +108,20 @@ export const MalwareProtectionsCard = React.memo<MalwareProtectionsProps>(
/>
<EuiSpacer size="m" />

<EnableDisableBlocklist policy={policy} onChange={onChange} mode={mode} />
<EnableDisableBlocklist
policy={policy}
onChange={onChange}
mode={mode}
data-test-subj={getTestId('enableDisableBlocklist')}
/>

<NotifyUserOption
policy={policy}
onChange={onChange}
mode={mode}
protection={protection}
osList={MALWARE_OS_VALUES}
data-test-subj={getTestId('notifyUser')}
/>
<EuiSpacer size="m" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const MemoryProtectionCard = memo<MemoryProtectionCardProps>(
protection={protection}
protectionLabel={protectionLabel}
osList={MEMORY_PROTECTION_OS_VALUES}
data-test-subj={getTestId('enableDisableSwitch')}
/>
}
>
Expand All @@ -79,6 +80,7 @@ export const MemoryProtectionCard = memo<MemoryProtectionCardProps>(
mode={mode}
protection={protection}
osList={MEMORY_PROTECTION_OS_VALUES}
data-test-subj={getTestId('protectionLevel')}
/>

<NotifyUserOption
Expand All @@ -87,6 +89,7 @@ export const MemoryProtectionCard = memo<MemoryProtectionCardProps>(
mode={mode}
protection={protection}
osList={MEMORY_PROTECTION_OS_VALUES}
data-test-subj={getTestId('notifyUser')}
/>

<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const RansomwareProtectionCard = React.memo<RansomwareProtectionCardProps
protection={protection}
protectionLabel={protectionLabel}
osList={RANSOMEWARE_OS_VALUES}
data-test-subj={getTestId('enableDisableSwitch')}
/>
}
>
Expand All @@ -77,6 +78,7 @@ export const RansomwareProtectionCard = React.memo<RansomwareProtectionCardProps
onChange={onChange}
policy={policy}
mode={mode}
data-test-subj={getTestId('protectionLevel')}
/>

<NotifyUserOption
Expand All @@ -85,6 +87,7 @@ export const RansomwareProtectionCard = React.memo<RansomwareProtectionCardProps
mode={mode}
protection={protection}
osList={RANSOMEWARE_OS_VALUES}
data-test-subj={getTestId('notifyUser')}
/>
<EuiSpacer size="m" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiText,
EuiTextArea,
} from '@elastic/eui';
import { useTestIdGenerator } from '../../../../../hooks/use_test_id_generator';
import { getEmptyValue } from '../../../../../../common/components/empty_value';
import { useLicense } from '../../../../../../common/hooks/use_license';
import { SettingCardHeader } from './setting_card';
Expand Down Expand Up @@ -60,8 +61,16 @@ interface NotifyUserOptionProps extends PolicyFormComponentCommonProps {
}

export const NotifyUserOption = React.memo(
({ policy, onChange, mode, protection, osList }: NotifyUserOptionProps) => {
({
policy,
onChange,
mode,
protection,
osList,
'data-test-subj': dataTestSubj,
}: NotifyUserOptionProps) => {
const isPlatinumPlus = useLicense().isPlatinumPlus();
const getTestId = useTestIdGenerator(dataTestSubj);

const isEditMode = mode === 'edit';
const selected = policy.windows[protection].mode;
Expand Down Expand Up @@ -149,7 +158,7 @@ export const NotifyUserOption = React.memo(
}

return (
<>
<div data-test-subj={getTestId()}>
<EuiSpacer size="m" />
<SettingCardHeader>
<FormattedMessage
Expand All @@ -158,13 +167,16 @@ export const NotifyUserOption = React.memo(
/>
</SettingCardHeader>

<SupportedVersionForProtectionNotice protection={protection} />
<SupportedVersionForProtectionNotice
protection={protection}
data-test-subj={getTestId('supportedVersion')}
/>

<EuiSpacer size="s" />

{isEditMode ? (
<EuiCheckbox
data-test-subj={`${protection}UserNotificationCheckbox`}
data-test-subj={getTestId('checkbox')}
id={`${protection}UserNotificationCheckbox}`}
onChange={handleUserNotificationCheckbox}
checked={userNotificationSelected}
Expand All @@ -185,10 +197,10 @@ export const NotifyUserOption = React.memo(
<h4>{CUSTOMIZE_NOTIFICATION_MESSAGE_LABEL}</h4>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false} data-test-subj={`${protection}TooltipIcon`}>
<EuiFlexItem grow={false} data-test-subj={getTestId('tooltipIconContainer')}>
<EuiIconTip
position="right"
data-test-subj={`${protection}Tooltip`}
data-test-subj={getTestId('tooltip')}
content={
<>
<FormattedMessage
Expand Down Expand Up @@ -224,7 +236,7 @@ export const NotifyUserOption = React.memo(
onChange={handleCustomUserNotification}
fullWidth={true}
disabled={!isEditMode}
data-test-subj={`${protection}UserNotificationCustomMessage`}
data-test-subj={getTestId('customMessage')}
/>
</>
) : (
Expand All @@ -237,14 +249,20 @@ export const NotifyUserOption = React.memo(
<>{userNotificationMessage || getEmptyValue()}</>
</>
))}
</>
</div>
);
}
);
NotifyUserOption.displayName = 'NotifyUserOption';

export const SupportedVersionForProtectionNotice = React.memo(
({ protection }: { protection: string }) => {
({
protection,
'data-test-subj': dataTestSubj,
}: {
protection: string;
'data-test-subj'?: string;
}) => {
const version = useMemo(() => {
return {
malware: '7.11+',
Expand All @@ -259,7 +277,7 @@ export const SupportedVersionForProtectionNotice = React.memo(
}

return (
<EuiText color="subdued" size="xs" data-test-subj="policySupportedVersions">
<EuiText color="subdued" size="xs" data-test-subj={dataTestSubj}>
<i>
<FormattedMessage
id="xpack.securitySolution.endpoint.policyDetails.supportedVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ProtectionSettingCardSwitch = React.memo(
onChange,
policy,
mode,
'data-test-subj': dataTestSubj,
}: ProtectionSettingCardSwitchProps) => {
const isPlatinumPlus = useLicense().isPlatinumPlus();
const isEditMode = mode === 'edit';
Expand Down Expand Up @@ -130,7 +131,7 @@ export const ProtectionSettingCardSwitch = React.memo(
checked={selected !== ProtectionModes.off}
onChange={handleSwitchChange}
disabled={!isEditMode}
data-test-subj={`${protection}ProtectionSwitch`}
data-test-subj={dataTestSubj}
/>
);
}
Expand Down
Loading

0 comments on commit bbd6894

Please sign in to comment.