Skip to content

Commit

Permalink
[8.11] [Security Solution] Unskip rules table Serverless Cypress tests (
Browse files Browse the repository at this point in the history
#168306) (#168407)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Security Solution] Unskip rules table Serverless Cypress tests
(#168306)](#168306)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-10-09T20:29:22Z","message":"[Security
Solution] Unskip rules table Serverless Cypress tests
(#168306)\n\n**Addresses:**
https://github.com/elastic/kibana/issues/161540\r\n\r\n##
Summary\r\n\r\nThis PR unskips rules table Serverless Cypress
tests\r\n\r\n- `rules_table_auto_refresh.cy.ts`\r\n-
`rules_table_links.cy.ts`\r\n- `rules_table_persistent_state.cy.ts`\r\n-
`rules_table_selection.cy.ts`\r\n- `rules_table_sorting.cy.ts`\r\n\r\n##
Flaky test
runner\r\n\r\n\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3406\r\n150
runs
🟢","sha":"feb4222bf6207f71122fd40a96872b3b3e8a84dc","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","v8.11.0","v8.12.0"],"number":168306,"url":"https://github.com/elastic/kibana/pull/168306","mergeCommit":{"message":"[Security
Solution] Unskip rules table Serverless Cypress tests
(#168306)\n\n**Addresses:**
https://github.com/elastic/kibana/issues/161540\r\n\r\n##
Summary\r\n\r\nThis PR unskips rules table Serverless Cypress
tests\r\n\r\n- `rules_table_auto_refresh.cy.ts`\r\n-
`rules_table_links.cy.ts`\r\n- `rules_table_persistent_state.cy.ts`\r\n-
`rules_table_selection.cy.ts`\r\n- `rules_table_sorting.cy.ts`\r\n\r\n##
Flaky test
runner\r\n\r\n\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3406\r\n150
runs
🟢","sha":"feb4222bf6207f71122fd40a96872b3b3e8a84dc"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168306","number":168306,"mergeCommit":{"message":"[Security
Solution] Unskip rules table Serverless Cypress tests
(#168306)\n\n**Addresses:**
https://github.com/elastic/kibana/issues/161540\r\n\r\n##
Summary\r\n\r\nThis PR unskips rules table Serverless Cypress
tests\r\n\r\n- `rules_table_auto_refresh.cy.ts`\r\n-
`rules_table_links.cy.ts`\r\n- `rules_table_persistent_state.cy.ts`\r\n-
`rules_table_selection.cy.ts`\r\n- `rules_table_sorting.cy.ts`\r\n\r\n##
Flaky test
runner\r\n\r\n\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/3406\r\n150
runs 🟢","sha":"feb4222bf6207f71122fd40a96872b3b3e8a84dc"}}]}]
BACKPORT-->

Co-authored-by: Maxim Palenov <[email protected]>
  • Loading branch information
kibanamachine and maximpn authored Oct 9, 2023
1 parent 39a2019 commit ce4342e
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,137 +33,132 @@ import { getNewRule } from '../../../../objects/rule';

const RULES_TABLE_REFRESH_INTERVAL_MS = 60000;

// TODO: https://github.com/elastic/kibana/issues/161540
describe(
'Rules table: auto-refresh',
{ tags: ['@ess', '@serverless', '@brokenInServerless'] },
() => {
before(() => {
cleanKibana();
login();

setRulesTableAutoRefreshIntervalSetting({
enabled: true,
refreshInterval: RULES_TABLE_REFRESH_INTERVAL_MS,
});
createRule(getNewRule({ name: 'Test rule 1', rule_id: '1', enabled: false }));
describe('Rules table: auto-refresh', { tags: ['@ess', '@serverless'] }, () => {
before(() => {
cleanKibana();
login();

setRulesTableAutoRefreshIntervalSetting({
enabled: true,
refreshInterval: RULES_TABLE_REFRESH_INTERVAL_MS,
});
createRule(getNewRule({ name: 'Test rule 1', rule_id: '1', enabled: false }));
});

beforeEach(() => {
login();
});
beforeEach(() => {
login();
});

it('gets deactivated when any rule selected and activated after rules unselected', () => {
visitRulesManagementTable();
it('gets deactivated when any rule selected and activated after rules unselected', () => {
visitRulesManagementTable();

expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);

// check refresh settings if it's enabled before selecting
expectAutoRefreshIsEnabled();
// check refresh settings if it's enabled before selecting
expectAutoRefreshIsEnabled();

selectAllRules();
selectAllRules();

// auto refresh should be deactivated (which means disabled without an ability to enable it) after rules selected
expectAutoRefreshIsDeactivated();
// auto refresh should be deactivated (which means disabled without an ability to enable it) after rules selected
expectAutoRefreshIsDeactivated();

clearAllRuleSelection();
clearAllRuleSelection();

// after all rules unselected, auto refresh should be reset to its previous state
expectAutoRefreshIsEnabled();
});
// after all rules unselected, auto refresh should be reset to its previous state
expectAutoRefreshIsEnabled();
});

describe('when enabled', () => {
beforeEach(() => {
mockGlobalClock();
visitRulesManagementTable();
describe('when enabled', () => {
beforeEach(() => {
mockGlobalClock();
visitRulesManagementTable();

expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);
});
expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);
});

it('refreshes rules after refresh interval has passed', () => {
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('not.exist');
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS);
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('be.visible');
it('refreshes rules after refresh interval has passed', () => {
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('not.exist');
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS);
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('be.visible');

cy.contains(REFRESH_RULES_STATUS, 'Updated now');
});
cy.contains(REFRESH_RULES_STATUS, 'Updated now');
});

it('refreshes rules on window focus', () => {
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS / 2);
it('refreshes rules on window focus', () => {
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS / 2);

cy.window().trigger('blur');
cy.window().trigger('focus');
cy.window().trigger('blur');
cy.window().trigger('focus');

cy.contains(REFRESH_RULES_STATUS, 'Updated now');
});
cy.contains(REFRESH_RULES_STATUS, 'Updated now');
});
});

describe('when disabled', () => {
beforeEach(() => {
mockGlobalClock();
visitRulesManagementTable();
expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);
});
describe('when disabled', () => {
beforeEach(() => {
mockGlobalClock();
visitRulesManagementTable();
expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);
});

it('does NOT refresh rules after refresh interval has passed', () => {
disableAutoRefresh();
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen
it('does NOT refresh rules after refresh interval has passed', () => {
disableAutoRefresh();
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen

cy.contains(REFRESH_RULES_STATUS, 'Updated 2 minutes ago');
});
cy.contains(REFRESH_RULES_STATUS, 'Updated 2 minutes ago');
});

it('does NOT refresh rules on window focus', () => {
disableAutoRefresh();
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen
it('does NOT refresh rules on window focus', () => {
disableAutoRefresh();
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen

cy.window().trigger('blur');
cy.window().trigger('focus');
cy.window().trigger('blur');
cy.window().trigger('focus');

// We need to make sure window focus event doesn't cause refetching. Without some delay
// the following expectations always pass even. It happens since 'focus' event gets handled
// in an async way so the status text is updated with some delay.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000);
// We need to make sure window focus event doesn't cause refetching. Without some delay
// the following expectations always pass even. It happens since 'focus' event gets handled
// in an async way so the status text is updated with some delay.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000);

// By using a custom timeout make sure it doesn't wait too long due to global timeout configuration
// so the expected text appears after a refresh and the test passes while it shouldn't.
cy.contains(REFRESH_RULES_STATUS, 'Updated 2 minutes ago', { timeout: 10000 });
});
// By using a custom timeout make sure it doesn't wait too long due to global timeout configuration
// so the expected text appears after a refresh and the test passes while it shouldn't.
cy.contains(REFRESH_RULES_STATUS, 'Updated 2 minutes ago', { timeout: 10000 });
});

it('does NOT get enabled after rules were unselected', () => {
disableAutoRefresh();
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen
it('does NOT get enabled after rules were unselected', () => {
disableAutoRefresh();
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen

selectAllRules();
selectAllRules();

expectAutoRefreshIsDeactivated();
expectAutoRefreshIsDeactivated();

clearAllRuleSelection();
clearAllRuleSelection();

// after all rules unselected, auto refresh should still be disabled
expectAutoRefreshIsDisabled();
});
// after all rules unselected, auto refresh should still be disabled
expectAutoRefreshIsDisabled();
});
});

describe('when one rule is selected', () => {
it('does NOT refresh after refresh interval has passed', () => {
mockGlobalClock();
visitRulesManagementTable();
describe('when one rule is selected', () => {
it('does NOT refresh after refresh interval has passed', () => {
mockGlobalClock();
visitRulesManagementTable();

expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);
expectNumberOfRules(RULES_MANAGEMENT_TABLE, 1);

selectRulesByName(['Test rule 1']);
selectRulesByName(['Test rule 1']);

// mock 1 minute passing to make sure refresh is not conducted
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('not.exist');
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('not.exist');
// mock 1 minute passing to make sure refresh is not conducted
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('not.exist');
cy.tick(RULES_TABLE_REFRESH_INTERVAL_MS * 2); // Make sure enough time has passed
cy.get(RULES_TABLE_AUTOREFRESH_INDICATOR).should('not.exist');

// ensure rule is still selected
getRuleRow('Test rule 1').find(EUI_CHECKBOX).should('be.checked');
// ensure rule is still selected
getRuleRow('Test rule 1').find(EUI_CHECKBOX).should('be.checked');

cy.get(REFRESH_RULES_STATUS).should('have.not.text', 'Updated now');
});
cy.get(REFRESH_RULES_STATUS).should('have.not.text', 'Updated now');
});
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { login } from '../../../../tasks/login';
import { visit } from '../../../../tasks/navigation';
import { RULES_MANAGEMENT_URL } from '../../../../urls/rules_management';

// TODO: https://github.com/elastic/kibana/issues/161540
// Flaky in serverless tests
describe('Rules table: links', { tags: ['@ess', '@serverless', '@skipInServerless'] }, () => {
describe('Rules table: links', { tags: ['@ess', '@serverless'] }, () => {
before(() => {
cleanKibana();
});
Expand Down
Loading

0 comments on commit ce4342e

Please sign in to comment.