From 4216ae543065424eb3ea61580e0eca19753d10da Mon Sep 17 00:00:00 2001 From: mgiota Date: Mon, 20 Sep 2021 23:50:54 +0200 Subject: [PATCH 01/19] [RAC][Observability]: test cases for alerts pagination functional tests --- .../apps/observability/alerts/index.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index 856d7e60996ec..e1848282cc93c 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -199,6 +199,40 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); }); }); + + describe('Pagination', () => { + describe('Page size selector', () => { + // less than 10 + it('Does not render page size selector', async () => {}); + + it('Renders page size selector', async () => {}); + + it('Page size selector works', async () => {}); + }); + + describe('Pagination controls', () => { + // less than 10 + it('Does not render pagination controls', async () => {}); + + it('Renders previous page button', async () => {}); + + it('Previous page button works', async () => {}); + + it('Previous page button is disabled', async () => {}); + + it('Renders next page button', async () => {}); + + it('Next page button works', async () => {}); + + it('Next page button is disabled', async () => {}); + + it('Page button works', async () => {}); + }); + + it('Table scrolls when page size is large', async () => {}); + + it('Table does not scroll when page size is small', async () => {}); + }); }); }); }; From d0e547fa08b207afe9954b8a865951ad9e389bdb Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 00:45:00 +0200 Subject: [PATCH 02/19] page size selector tests --- .../services/observability/alerts.ts | 12 +++++++++++ .../apps/observability/alerts/index.ts | 20 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts.ts b/x-pack/test/functional/services/observability/alerts.ts index 435da8ad94037..a2b879588ebc6 100644 --- a/x-pack/test/functional/services/observability/alerts.ts +++ b/x-pack/test/functional/services/observability/alerts.ts @@ -19,6 +19,11 @@ const DATE_WITH_DATA = { const ALERTS_FLYOUT_SELECTOR = 'alertsFlyout'; const COPY_TO_CLIPBOARD_BUTTON_SELECTOR = 'copy-to-clipboard'; const ALERTS_TABLE_CONTAINER_SELECTOR = 'events-viewer-panel'; +const ALERTS_ROWS_PER_PAGE_SELECTOR = 'tablePaginationPopoverButton'; +const ALERTS_PAGINATION_BUTTON_PREVIOUS = 'pagination-button-previous'; +const ALERTS_PAGINATION_BUTTON_NEXT = 'pagination-button-next'; +const ALERTS_PAGINATION_BUTTON_ONE = 'pagination-button-0'; +const ALERTS_PAGINATION_BUTTON_TWO = 'pagination-button-1'; const ACTION_COLUMN_INDEX = 1; @@ -156,6 +161,7 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP await actionsOverflowButton.click(); }; + // Workflow status const setWorkflowStatusForRow = async (rowIndex: number, workflowStatus: WorkflowStatus) => { await openActionsMenuForRow(rowIndex); @@ -177,6 +183,11 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP await buttonGroupButton.click(); }; + // Pagination + const getPageSizeSelector = async () => { + return await testSubjects.find(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + return { getQueryBar, clearQueryBar, @@ -201,5 +212,6 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP setWorkflowStatusFilter, submitQuery, typeInQueryBar, + getPageSizeSelector, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index e1848282cc93c..e06228194d427 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -18,6 +18,8 @@ const ACTIVE_ALERTS_CELL_COUNT = 48; const RECOVERED_ALERTS_CELL_COUNT = 24; const TOTAL_ALERTS_CELL_COUNT = 72; +const OPEN_ALERTS_ROWS_COUNT = 12; + export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); @@ -203,9 +205,23 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe('Pagination', () => { describe('Page size selector', () => { // less than 10 - it('Does not render page size selector', async () => {}); + it('Does not render page size selector', async () => { + await observability.alerts.setWorkflowStatusFilter('closed'); + + await retry.try(async () => { + const pageSizeSelector = await observability.alerts.getPageSizeSelector(); + expect(pageSizeSelector).to.be.empty(); + }); + }); + + it('Renders page size selector', async () => { + await retry.try(async () => { + const pageSizeSelector = await observability.alerts.getPageSizeSelector(); + expect(pageSizeSelector).to.not.be.empty(); + }); + }); - it('Renders page size selector', async () => {}); + it('Default rows per page selector is 50', async () => {}); it('Page size selector works', async () => {}); }); From 654632a4280d3f3a02dc2cc6e32b55a127dd754e Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 00:45:55 +0200 Subject: [PATCH 03/19] create OPEN_ALERTS_ROWS_COUNT in workdlow status tests --- .../apps/observability/alerts/workflow_status.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts b/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts index d491e239c6035..6dcfe08f7a6d2 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts @@ -8,6 +8,8 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../ftr_provider_context'; +const OPEN_ALERTS_ROWS_COUNT = 12; + export default ({ getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); @@ -29,7 +31,7 @@ export default ({ getService }: FtrProviderContext) => { it('is filtered to only show "open" alerts by default', async () => { await retry.try(async () => { const tableRows = await observability.alerts.getTableCellsInRows(); - expect(tableRows.length).to.be(12); + expect(tableRows.length).to.be(OPEN_ALERTS_ROWS_COUNT); }); }); From 5dd681982974584f84954b7adc0cfa8d00a43b1d Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 10:10:23 +0200 Subject: [PATCH 04/19] add tests to check if page selector is rendered or not --- .../services/observability/alerts.ts | 10 ++++++++ .../apps/observability/alerts/index.ts | 24 +++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts.ts b/x-pack/test/functional/services/observability/alerts.ts index a2b879588ebc6..18e70dc733e31 100644 --- a/x-pack/test/functional/services/observability/alerts.ts +++ b/x-pack/test/functional/services/observability/alerts.ts @@ -188,6 +188,14 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP return await testSubjects.find(ALERTS_ROWS_PER_PAGE_SELECTOR); }; + const getPageSizeSelectorOrFail = async () => { + return await testSubjects.existOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + + const missingPageSizeSelectorOrFail = async () => { + return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + return { getQueryBar, clearQueryBar, @@ -213,5 +221,7 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP submitQuery, typeInQueryBar, getPageSizeSelector, + getPageSizeSelectorOrFail, + missingPageSizeSelectorOrFail, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index e06228194d427..3f9befff73a2c 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -18,7 +18,7 @@ const ACTIVE_ALERTS_CELL_COUNT = 48; const RECOVERED_ALERTS_CELL_COUNT = 24; const TOTAL_ALERTS_CELL_COUNT = 72; -const OPEN_ALERTS_ROWS_COUNT = 12; +const ROWS_COUNT_TO_HIDE_PAGE_SELECTOR = 10; export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); @@ -204,21 +204,19 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe('Pagination', () => { describe('Page size selector', () => { - // less than 10 - it('Does not render page size selector', async () => { + it('Does not render page size selector when there are less than 10 alerts', async () => { + // archiver has 3 closed alerts, so filter for the closed ones await observability.alerts.setWorkflowStatusFilter('closed'); - - await retry.try(async () => { - const pageSizeSelector = await observability.alerts.getPageSizeSelector(); - expect(pageSizeSelector).to.be.empty(); - }); + const visibleAlerts = await observability.alerts.getTableCellsInRows(); + expect(visibleAlerts.length).to.be.lessThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); + await observability.alerts.missingPageSizeSelectorOrFail(); }); - it('Renders page size selector', async () => { - await retry.try(async () => { - const pageSizeSelector = await observability.alerts.getPageSizeSelector(); - expect(pageSizeSelector).to.not.be.empty(); - }); + it('Renders page size selector when there are more than 10 alerts', async () => { + await observability.alerts.setWorkflowStatusFilter('open'); + const visibleAlerts = await observability.alerts.getTableCellsInRows(); + expect(visibleAlerts.length).to.be.greaterThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); + await observability.alerts.getPageSizeSelectorOrFail(); }); it('Default rows per page selector is 50', async () => {}); From e88c5f4052ebcd8f579a6060109315413c305612 Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 12:01:04 +0200 Subject: [PATCH 05/19] reorganize tests to visible and non visible pagination controls --- .../services/observability/alerts.ts | 25 +++++++ .../apps/observability/alerts/index.ts | 65 ++++++++++++------- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts.ts b/x-pack/test/functional/services/observability/alerts.ts index 18e70dc733e31..f3e6765dc2a1e 100644 --- a/x-pack/test/functional/services/observability/alerts.ts +++ b/x-pack/test/functional/services/observability/alerts.ts @@ -196,6 +196,26 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); }; + const getPrevPaginationButton = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_PREVIOUS); + }; + + const getPrevPaginationButtonOrFail = async () => { + return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_PREVIOUS); + }; + + const missingPrevPaginationButtonOrFail = async () => { + return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + + const getNextPaginationButton = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT); + }; + + const getNextPaginationButtonOrFail = async () => { + return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_NEXT); + }; + return { getQueryBar, clearQueryBar, @@ -223,5 +243,10 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP getPageSizeSelector, getPageSizeSelectorOrFail, missingPageSizeSelectorOrFail, + getPrevPaginationButton, + getPrevPaginationButtonOrFail, + missingPrevPaginationButtonOrFail, + getNextPaginationButton, + getNextPaginationButtonOrFail, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index 3f9befff73a2c..c335f1cffb765 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -203,49 +203,70 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); describe('Pagination', () => { - describe('Page size selector', () => { - it('Does not render page size selector when there are less than 10 alerts', async () => { - // archiver has 3 closed alerts, so filter for the closed ones + describe(`When less than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { + before(async () => { + // current archiver has 3 closed alerts await observability.alerts.setWorkflowStatusFilter('closed'); const visibleAlerts = await observability.alerts.getTableCellsInRows(); + // make sure visible alerts are less than 10 expect(visibleAlerts.length).to.be.lessThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); + }); + + after(async () => { + await observability.alerts.setWorkflowStatusFilter('open'); + }); + + it('Does not render page size selector', async () => { await observability.alerts.missingPageSizeSelectorOrFail(); }); - it('Renders page size selector when there are more than 10 alerts', async () => { + it('Does not render pagination controls', async () => { + await observability.alerts.missingPrevPaginationButtonOrFail(); + }); + }); + + describe(`When more than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { + before(async () => { + // current archiver has 12 open alerts await observability.alerts.setWorkflowStatusFilter('open'); const visibleAlerts = await observability.alerts.getTableCellsInRows(); + // make sure visible alerts are more than 10 expect(visibleAlerts.length).to.be.greaterThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); - await observability.alerts.getPageSizeSelectorOrFail(); }); - it('Default rows per page selector is 50', async () => {}); - - it('Page size selector works', async () => {}); - }); + describe('Page size selector', () => { + it('Renders page size selector', async () => { + await observability.alerts.getPageSizeSelectorOrFail(); + }); - describe('Pagination controls', () => { - // less than 10 - it('Does not render pagination controls', async () => {}); + it('Default rows per page selector is 50', async () => {}); - it('Renders previous page button', async () => {}); + it('Page size selector works', async () => {}); + }); - it('Previous page button works', async () => {}); + describe('Pagination controls', () => { + it('Renders previous page button', async () => { + await observability.alerts.getPrevPaginationButtonOrFail(); + }); - it('Previous page button is disabled', async () => {}); + it('Previous page button works', async () => {}); - it('Renders next page button', async () => {}); + it('Previous page button is disabled', async () => {}); - it('Next page button works', async () => {}); + it('Renders next page button', async () => { + await observability.alerts.getNextPaginationButtonOrFail(); + }); - it('Next page button is disabled', async () => {}); + it('Next page button works', async () => {}); - it('Page button works', async () => {}); - }); + it('Next page button is disabled', async () => {}); - it('Table scrolls when page size is large', async () => {}); + it('Page button works', async () => {}); + }); - it('Table does not scroll when page size is small', async () => {}); + it('Table scrolls when page size is large', async () => {}); + it('Table does not scroll when page size is small', async () => {}); + }); }); }); }); From 0cf77557f3b39e258efd201c2534fb3e35771e40 Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 13:43:45 +0200 Subject: [PATCH 06/19] default rows per page test --- .../apps/observability/alerts/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index c335f1cffb765..8c5fe0db1ddbc 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -19,6 +19,7 @@ const RECOVERED_ALERTS_CELL_COUNT = 24; const TOTAL_ALERTS_CELL_COUNT = 72; const ROWS_COUNT_TO_HIDE_PAGE_SELECTOR = 10; +const DEFAULT_ROWS_PER_PAGE = 50; export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); @@ -239,7 +240,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await observability.alerts.getPageSizeSelectorOrFail(); }); - it('Default rows per page selector is 50', async () => {}); + it('Default rows per page selector is 50', async () => { + await retry.try(async () => { + const defaultAlertsPerPage = await ( + await observability.alerts.getPageSizeSelector() + ).getVisibleText(); + expect(defaultAlertsPerPage).to.contain(DEFAULT_ROWS_PER_PAGE); + }); + }); it('Page size selector works', async () => {}); }); From a41b62d79c30e562fb4a892fae01d907fdc20d79 Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 14:56:21 +0200 Subject: [PATCH 07/19] page size selector tests --- .../services/observability/alerts.ts | 18 ++++++++++++++++++ .../apps/observability/alerts/index.ts | 9 ++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/x-pack/test/functional/services/observability/alerts.ts b/x-pack/test/functional/services/observability/alerts.ts index f3e6765dc2a1e..7ffbd7c1963b6 100644 --- a/x-pack/test/functional/services/observability/alerts.ts +++ b/x-pack/test/functional/services/observability/alerts.ts @@ -22,6 +22,9 @@ const ALERTS_TABLE_CONTAINER_SELECTOR = 'events-viewer-panel'; const ALERTS_ROWS_PER_PAGE_SELECTOR = 'tablePaginationPopoverButton'; const ALERTS_PAGINATION_BUTTON_PREVIOUS = 'pagination-button-previous'; const ALERTS_PAGINATION_BUTTON_NEXT = 'pagination-button-next'; +const ALERTS_PAGINATION_TEN_ROWS = 'tablePagination-10-rows'; +const ALERTS_PAGINATION_TWENTY_FIVE_ROWS = 'tablePagination-25-rows'; +const ALERTS_PAGINATION_FIFTY_ROWS = 'tablePagination-50-rows'; const ALERTS_PAGINATION_BUTTON_ONE = 'pagination-button-0'; const ALERTS_PAGINATION_BUTTON_TWO = 'pagination-button-1'; @@ -196,6 +199,18 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); }; + const getTenRowsPageSelector = async () => { + return await testSubjects.find(ALERTS_PAGINATION_TEN_ROWS); + }; + + const getTwentyFiveRowsPageSelector = async () => { + return await testSubjects.find(ALERTS_PAGINATION_TWENTY_FIVE_ROWS); + }; + + const getFiftyRowsPageSelector = async () => { + return await testSubjects.find(ALERTS_PAGINATION_FIFTY_ROWS); + }; + const getPrevPaginationButton = async () => { return await testSubjects.find(ALERTS_PAGINATION_BUTTON_PREVIOUS); }; @@ -243,6 +258,9 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP getPageSizeSelector, getPageSizeSelectorOrFail, missingPageSizeSelectorOrFail, + getTenRowsPageSelector, + getTwentyFiveRowsPageSelector, + getFiftyRowsPageSelector, getPrevPaginationButton, getPrevPaginationButtonOrFail, missingPrevPaginationButtonOrFail, diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index 8c5fe0db1ddbc..a1702e5d74a9e 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -249,7 +249,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); }); - it('Page size selector works', async () => {}); + it('Page size selector works', async () => { + await retry.try(async () => { + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTenRowsPageSelector()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + expect(tableRows.length).to.be(10); + }); + }); }); describe('Pagination controls', () => { From b7c8dacc303643e9a5490721386b51bcd60f52e8 Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 15:03:03 +0200 Subject: [PATCH 08/19] more page selector tests --- .../apps/observability/alerts/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index a1702e5d74a9e..87858aae7fbfe 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -249,12 +249,21 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); }); - it('Page size selector works', async () => { + it('10 rows per page selector works', async () => { await retry.try(async () => { await (await observability.alerts.getPageSizeSelector()).click(); await (await observability.alerts.getTenRowsPageSelector()).click(); const tableRows = await observability.alerts.getTableCellsInRows(); - expect(tableRows.length).to.be(10); + expect(tableRows.length).to.not.be.greaterThan(10); // with current archiver data it is going to be 10. Shall we check against equality to.be(10) instead? + }); + }); + + it('25 rows per page selector works', async () => { + await retry.try(async () => { + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTwentyFiveRowsPageSelector()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + expect(tableRows.length).to.not.be.greaterThan(25); }); }); }); From 0e2e9f13562e24cf51e769b7bfc7616ae89ca545 Mon Sep 17 00:00:00 2001 From: mgiota Date: Tue, 21 Sep 2021 23:45:30 +0200 Subject: [PATCH 09/19] write tests for pagination controls --- .../services/observability/alerts.ts | 12 +++- .../apps/observability/alerts/index.ts | 57 ++++++++++++++++--- .../with_rac_write.config.ts | 4 +- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts.ts b/x-pack/test/functional/services/observability/alerts.ts index 7ffbd7c1963b6..f08ec3001033f 100644 --- a/x-pack/test/functional/services/observability/alerts.ts +++ b/x-pack/test/functional/services/observability/alerts.ts @@ -224,13 +224,21 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP }; const getNextPaginationButton = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT); + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT, 20000); }; const getNextPaginationButtonOrFail = async () => { return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_NEXT); }; + const getPaginationButtonOne = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_ONE); + }; + + const getPaginationButtonTwo = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_TWO); + }; + return { getQueryBar, clearQueryBar, @@ -266,5 +274,7 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP missingPrevPaginationButtonOrFail, getNextPaginationButton, getNextPaginationButtonOrFail, + getPaginationButtonOne, + getPaginationButtonTwo, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index 87858aae7fbfe..b8cafc3e057f5 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -269,23 +269,66 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); describe('Pagination controls', () => { + before(async () => { + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTenRowsPageSelector()).click(); + }); + beforeEach(async () => { + // write a helper to move to first page + await (await observability.alerts.getPaginationButtonOne()).click(); + }); + it('Renders previous page button', async () => { await observability.alerts.getPrevPaginationButtonOrFail(); }); - it('Previous page button works', async () => {}); - - it('Previous page button is disabled', async () => {}); - it('Renders next page button', async () => { await observability.alerts.getNextPaginationButtonOrFail(); }); - it('Next page button works', async () => {}); + it('Previous page button is disabled', async () => { + const prevButtonDisabledValue = await ( + await observability.alerts.getPrevPaginationButton() + ).getAttribute('disabled'); + expect(prevButtonDisabledValue).to.be('true'); + }); - it('Next page button is disabled', async () => {}); + // While running the test I inspected the elements on the page + // and although the disabled attribute was not there at all for some reason getAttribute('disabled') = 'true' + // timing issue? + it.skip('Next page button is enabled', async () => { + // TODO create a function goToSecondPage + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTenRowsPageSelector()).click(); + const nextButtonDisabledValue = await ( + await observability.alerts.getPrevPaginationButton() + ).getAttribute('disabled'); + expect(nextButtonDisabledValue).to.be(null); + }); - it('Page button works', async () => {}); + it('Next page button works', async () => { + await (await observability.alerts.getNextPaginationButton()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + expect(tableRows.length).to.be(2); // don't hardcode this value, calculate open alerts/perRow + }); + + it('Previous page button works', async () => { + await (await observability.alerts.getPaginationButtonTwo()).click(); + await (await observability.alerts.getPrevPaginationButton()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + + expect(tableRows.length).to.be(10); // don't hardcode this value, calculate open alerts/perRow + }); + + it('Next page button is disabled', async () => { + // TODO: write a helper to move to last page + await (await observability.alerts.getPaginationButtonTwo()).click(); + // TODO: write a helper isButtonDisabled + const nextButtonDisabledValue = await ( + await observability.alerts.getNextPaginationButton() + ).getAttribute('disabled'); + expect(nextButtonDisabledValue).to.be('true'); + }); }); it('Table scrolls when page size is large', async () => {}); diff --git a/x-pack/test/observability_functional/with_rac_write.config.ts b/x-pack/test/observability_functional/with_rac_write.config.ts index 89a0da7857333..6363fdac84ad0 100644 --- a/x-pack/test/observability_functional/with_rac_write.config.ts +++ b/x-pack/test/observability_functional/with_rac_write.config.ts @@ -11,7 +11,9 @@ import { CA_CERT_PATH } from '@kbn/dev-utils'; import { FtrConfigProviderContext } from '@kbn/test'; export default async function ({ readConfigFile }: FtrConfigProviderContext) { - const xpackFunctionalConfig = await readConfigFile(require.resolve('../functional/config.js')); + const xpackFunctionalConfig = await readConfigFile( + require.resolve('../functional/config.firefox.js') + ); const servers = { ...xpackFunctionalConfig.get('servers'), From 429f4388713c68ccb494059dd088092e126597fc Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 22 Sep 2021 11:42:03 +0200 Subject: [PATCH 10/19] move pagination tests to a new file --- .../apps/observability/alerts/index.ts | 133 -------------- .../apps/observability/alerts/pagination.ts | 163 ++++++++++++++++++ .../apps/observability/index.ts | 1 + 3 files changed, 164 insertions(+), 133 deletions(-) create mode 100644 x-pack/test/observability_functional/apps/observability/alerts/pagination.ts diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index b8cafc3e057f5..e9eefded4ee92 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -202,139 +202,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); }); }); - - describe('Pagination', () => { - describe(`When less than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { - before(async () => { - // current archiver has 3 closed alerts - await observability.alerts.setWorkflowStatusFilter('closed'); - const visibleAlerts = await observability.alerts.getTableCellsInRows(); - // make sure visible alerts are less than 10 - expect(visibleAlerts.length).to.be.lessThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); - }); - - after(async () => { - await observability.alerts.setWorkflowStatusFilter('open'); - }); - - it('Does not render page size selector', async () => { - await observability.alerts.missingPageSizeSelectorOrFail(); - }); - - it('Does not render pagination controls', async () => { - await observability.alerts.missingPrevPaginationButtonOrFail(); - }); - }); - - describe(`When more than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { - before(async () => { - // current archiver has 12 open alerts - await observability.alerts.setWorkflowStatusFilter('open'); - const visibleAlerts = await observability.alerts.getTableCellsInRows(); - // make sure visible alerts are more than 10 - expect(visibleAlerts.length).to.be.greaterThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); - }); - - describe('Page size selector', () => { - it('Renders page size selector', async () => { - await observability.alerts.getPageSizeSelectorOrFail(); - }); - - it('Default rows per page selector is 50', async () => { - await retry.try(async () => { - const defaultAlertsPerPage = await ( - await observability.alerts.getPageSizeSelector() - ).getVisibleText(); - expect(defaultAlertsPerPage).to.contain(DEFAULT_ROWS_PER_PAGE); - }); - }); - - it('10 rows per page selector works', async () => { - await retry.try(async () => { - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTenRowsPageSelector()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); - expect(tableRows.length).to.not.be.greaterThan(10); // with current archiver data it is going to be 10. Shall we check against equality to.be(10) instead? - }); - }); - - it('25 rows per page selector works', async () => { - await retry.try(async () => { - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTwentyFiveRowsPageSelector()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); - expect(tableRows.length).to.not.be.greaterThan(25); - }); - }); - }); - - describe('Pagination controls', () => { - before(async () => { - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTenRowsPageSelector()).click(); - }); - beforeEach(async () => { - // write a helper to move to first page - await (await observability.alerts.getPaginationButtonOne()).click(); - }); - - it('Renders previous page button', async () => { - await observability.alerts.getPrevPaginationButtonOrFail(); - }); - - it('Renders next page button', async () => { - await observability.alerts.getNextPaginationButtonOrFail(); - }); - - it('Previous page button is disabled', async () => { - const prevButtonDisabledValue = await ( - await observability.alerts.getPrevPaginationButton() - ).getAttribute('disabled'); - expect(prevButtonDisabledValue).to.be('true'); - }); - - // While running the test I inspected the elements on the page - // and although the disabled attribute was not there at all for some reason getAttribute('disabled') = 'true' - // timing issue? - it.skip('Next page button is enabled', async () => { - // TODO create a function goToSecondPage - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTenRowsPageSelector()).click(); - const nextButtonDisabledValue = await ( - await observability.alerts.getPrevPaginationButton() - ).getAttribute('disabled'); - expect(nextButtonDisabledValue).to.be(null); - }); - - it('Next page button works', async () => { - await (await observability.alerts.getNextPaginationButton()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); - expect(tableRows.length).to.be(2); // don't hardcode this value, calculate open alerts/perRow - }); - - it('Previous page button works', async () => { - await (await observability.alerts.getPaginationButtonTwo()).click(); - await (await observability.alerts.getPrevPaginationButton()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); - - expect(tableRows.length).to.be(10); // don't hardcode this value, calculate open alerts/perRow - }); - - it('Next page button is disabled', async () => { - // TODO: write a helper to move to last page - await (await observability.alerts.getPaginationButtonTwo()).click(); - // TODO: write a helper isButtonDisabled - const nextButtonDisabledValue = await ( - await observability.alerts.getNextPaginationButton() - ).getAttribute('disabled'); - expect(nextButtonDisabledValue).to.be('true'); - }); - }); - - it('Table scrolls when page size is large', async () => {}); - it('Table does not scroll when page size is small', async () => {}); - }); - }); }); }); }; diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts new file mode 100644 index 0000000000000..b44db39baed6c --- /dev/null +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -0,0 +1,163 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../../ftr_provider_context'; + +const ROWS_COUNT_TO_HIDE_PAGE_SELECTOR = 10; +const DEFAULT_ROWS_PER_PAGE = 50; + +export default ({ getPageObjects, getService }: FtrProviderContext) => { + const esArchiver = getService('esArchiver'); + + describe('Alerts table pagination', function () { + this.tags('includeFirefox'); + + const retry = getService('retry'); + const observability = getService('observability'); + + before(async () => { + await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts'); + await observability.alerts.navigateToTimeWithData(); + }); + + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/observability/alerts'); + }); + + describe(`When less than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { + before(async () => { + // current archiver has 3 closed alerts + await observability.alerts.setWorkflowStatusFilter('closed'); + const visibleAlerts = await observability.alerts.getTableCellsInRows(); + // make sure visible alerts are less than 10 + expect(visibleAlerts.length).to.be.lessThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); + }); + + after(async () => { + await observability.alerts.setWorkflowStatusFilter('open'); + }); + + it('Does not render page size selector', async () => { + await observability.alerts.missingPageSizeSelectorOrFail(); + }); + + it('Does not render pagination controls', async () => { + await observability.alerts.missingPrevPaginationButtonOrFail(); + }); + }); + + describe(`When more than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { + before(async () => { + // current archiver has 12 open alerts + await observability.alerts.setWorkflowStatusFilter('open'); + const visibleAlerts = await observability.alerts.getTableCellsInRows(); + // make sure visible alerts are more than 10 + expect(visibleAlerts.length).to.be.greaterThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); + }); + + describe('Page size selector', () => { + it('Renders page size selector', async () => { + await observability.alerts.getPageSizeSelectorOrFail(); + }); + + it('Default rows per page selector is 50', async () => { + await retry.try(async () => { + const defaultAlertsPerPage = await ( + await observability.alerts.getPageSizeSelector() + ).getVisibleText(); + expect(defaultAlertsPerPage).to.contain(DEFAULT_ROWS_PER_PAGE); + }); + }); + + it('10 rows per page selector works', async () => { + await retry.try(async () => { + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTenRowsPageSelector()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + expect(tableRows.length).to.not.be.greaterThan(10); // with current archiver data it is going to be 10. Shall we check against equality to.be(10) instead? + }); + }); + + it('25 rows per page selector works', async () => { + await retry.try(async () => { + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTwentyFiveRowsPageSelector()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + expect(tableRows.length).to.not.be.greaterThan(25); + }); + }); + }); + + describe('Pagination controls', () => { + before(async () => { + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTenRowsPageSelector()).click(); + }); + beforeEach(async () => { + // write a helper to move to first page + await (await observability.alerts.getPaginationButtonOne()).click(); + }); + + it('Renders previous page button', async () => { + await observability.alerts.getPrevPaginationButtonOrFail(); + }); + + it('Renders next page button', async () => { + await observability.alerts.getNextPaginationButtonOrFail(); + }); + + it('Previous page button is disabled', async () => { + const prevButtonDisabledValue = await ( + await observability.alerts.getPrevPaginationButton() + ).getAttribute('disabled'); + expect(prevButtonDisabledValue).to.be('true'); + }); + + // While running the test I inspected the elements on the page + // and although the disabled attribute was not there at all for some reason getAttribute('disabled') = 'true' + // timing issue? + it.skip('Next page button is enabled', async () => { + // TODO create a function goToSecondPage + await (await observability.alerts.getPageSizeSelector()).click(); + await (await observability.alerts.getTenRowsPageSelector()).click(); + const nextButtonDisabledValue = await ( + await observability.alerts.getPrevPaginationButton() + ).getAttribute('disabled'); + expect(nextButtonDisabledValue).to.be(null); + }); + + it('Next page button works', async () => { + await (await observability.alerts.getNextPaginationButton()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + expect(tableRows.length).to.be(2); // don't hardcode this value, calculate open alerts/perRow + }); + + it('Previous page button works', async () => { + await (await observability.alerts.getPaginationButtonTwo()).click(); + await (await observability.alerts.getPrevPaginationButton()).click(); + const tableRows = await observability.alerts.getTableCellsInRows(); + + expect(tableRows.length).to.be(10); // don't hardcode this value, calculate open alerts/perRow + }); + + it('Next page button is disabled', async () => { + // TODO: write a helper to move to last page + await (await observability.alerts.getPaginationButtonTwo()).click(); + // TODO: write a helper isButtonDisabled + const nextButtonDisabledValue = await ( + await observability.alerts.getNextPaginationButton() + ).getAttribute('disabled'); + expect(nextButtonDisabledValue).to.be('true'); + }); + }); + + it('Table scrolls when page size is large', async () => {}); + it('Table does not scroll when page size is small', async () => {}); + }); + }); +}; diff --git a/x-pack/test/observability_functional/apps/observability/index.ts b/x-pack/test/observability_functional/apps/observability/index.ts index b823e1ee0869b..019fb0994715e 100644 --- a/x-pack/test/observability_functional/apps/observability/index.ts +++ b/x-pack/test/observability_functional/apps/observability/index.ts @@ -13,5 +13,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./feature_controls')); loadTestFile(require.resolve('./alerts')); loadTestFile(require.resolve('./alerts/workflow_status')); + loadTestFile(require.resolve('./alerts/pagination')); }); } From c59c15fb657e480b12c5bca54644e156717e84b9 Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 23 Sep 2021 09:10:08 +0200 Subject: [PATCH 11/19] remove unused variables --- .../apps/observability/alerts/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index e9eefded4ee92..856d7e60996ec 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -18,9 +18,6 @@ const ACTIVE_ALERTS_CELL_COUNT = 48; const RECOVERED_ALERTS_CELL_COUNT = 24; const TOTAL_ALERTS_CELL_COUNT = 72; -const ROWS_COUNT_TO_HIDE_PAGE_SELECTOR = 10; -const DEFAULT_ROWS_PER_PAGE = 50; - export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); From 2f60aad04dfebae3c7c7e570fdfcc1efbe83a5c1 Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 23 Sep 2021 10:50:39 +0200 Subject: [PATCH 12/19] reorganize observability alerts service --- .../{alerts.ts => alerts/common.ts} | 84 ++--------------- .../services/observability/alerts/index.ts | 21 +++++ .../observability/alerts/pagination.ts | 89 +++++++++++++++++++ .../apps/observability/alerts/index.ts | 57 ++++++------ .../apps/observability/alerts/pagination.ts | 68 +++++++------- 5 files changed, 179 insertions(+), 140 deletions(-) rename x-pack/test/functional/services/observability/{alerts.ts => alerts/common.ts} (68%) create mode 100644 x-pack/test/functional/services/observability/alerts/index.ts create mode 100644 x-pack/test/functional/services/observability/alerts/pagination.ts diff --git a/x-pack/test/functional/services/observability/alerts.ts b/x-pack/test/functional/services/observability/alerts/common.ts similarity index 68% rename from x-pack/test/functional/services/observability/alerts.ts rename to x-pack/test/functional/services/observability/alerts/common.ts index f08ec3001033f..7098fdec2a9d4 100644 --- a/x-pack/test/functional/services/observability/alerts.ts +++ b/x-pack/test/functional/services/observability/alerts/common.ts @@ -7,8 +7,8 @@ import querystring from 'querystring'; import { chunk } from 'lodash'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { WebElementWrapper } from '../../../../../test/functional/services/lib/web_element_wrapper'; +import { FtrProviderContext } from '../../../ftr_provider_context'; +import { WebElementWrapper } from '../../../../../../test/functional/services/lib/web_element_wrapper'; // Based on the x-pack/test/functional/es_archives/observability/alerts archive. const DATE_WITH_DATA = { @@ -19,20 +19,14 @@ const DATE_WITH_DATA = { const ALERTS_FLYOUT_SELECTOR = 'alertsFlyout'; const COPY_TO_CLIPBOARD_BUTTON_SELECTOR = 'copy-to-clipboard'; const ALERTS_TABLE_CONTAINER_SELECTOR = 'events-viewer-panel'; -const ALERTS_ROWS_PER_PAGE_SELECTOR = 'tablePaginationPopoverButton'; -const ALERTS_PAGINATION_BUTTON_PREVIOUS = 'pagination-button-previous'; -const ALERTS_PAGINATION_BUTTON_NEXT = 'pagination-button-next'; -const ALERTS_PAGINATION_TEN_ROWS = 'tablePagination-10-rows'; -const ALERTS_PAGINATION_TWENTY_FIVE_ROWS = 'tablePagination-25-rows'; -const ALERTS_PAGINATION_FIFTY_ROWS = 'tablePagination-50-rows'; -const ALERTS_PAGINATION_BUTTON_ONE = 'pagination-button-0'; -const ALERTS_PAGINATION_BUTTON_TWO = 'pagination-button-1'; - const ACTION_COLUMN_INDEX = 1; type WorkflowStatus = 'open' | 'acknowledged' | 'closed'; -export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrProviderContext) { +export function ObservabilityAlertsCommonProvider({ + getPageObjects, + getService, +}: FtrProviderContext) { const testSubjects = getService('testSubjects'); const flyoutService = getService('flyout'); const pageObjects = getPageObjects(['common']); @@ -186,59 +180,6 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP await buttonGroupButton.click(); }; - // Pagination - const getPageSizeSelector = async () => { - return await testSubjects.find(ALERTS_ROWS_PER_PAGE_SELECTOR); - }; - - const getPageSizeSelectorOrFail = async () => { - return await testSubjects.existOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); - }; - - const missingPageSizeSelectorOrFail = async () => { - return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); - }; - - const getTenRowsPageSelector = async () => { - return await testSubjects.find(ALERTS_PAGINATION_TEN_ROWS); - }; - - const getTwentyFiveRowsPageSelector = async () => { - return await testSubjects.find(ALERTS_PAGINATION_TWENTY_FIVE_ROWS); - }; - - const getFiftyRowsPageSelector = async () => { - return await testSubjects.find(ALERTS_PAGINATION_FIFTY_ROWS); - }; - - const getPrevPaginationButton = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_PREVIOUS); - }; - - const getPrevPaginationButtonOrFail = async () => { - return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_PREVIOUS); - }; - - const missingPrevPaginationButtonOrFail = async () => { - return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); - }; - - const getNextPaginationButton = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT, 20000); - }; - - const getNextPaginationButtonOrFail = async () => { - return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_NEXT); - }; - - const getPaginationButtonOne = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_ONE); - }; - - const getPaginationButtonTwo = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_TWO); - }; - return { getQueryBar, clearQueryBar, @@ -263,18 +204,5 @@ export function ObservabilityAlertsProvider({ getPageObjects, getService }: FtrP setWorkflowStatusFilter, submitQuery, typeInQueryBar, - getPageSizeSelector, - getPageSizeSelectorOrFail, - missingPageSizeSelectorOrFail, - getTenRowsPageSelector, - getTwentyFiveRowsPageSelector, - getFiftyRowsPageSelector, - getPrevPaginationButton, - getPrevPaginationButtonOrFail, - missingPrevPaginationButtonOrFail, - getNextPaginationButton, - getNextPaginationButtonOrFail, - getPaginationButtonOne, - getPaginationButtonTwo, }; } diff --git a/x-pack/test/functional/services/observability/alerts/index.ts b/x-pack/test/functional/services/observability/alerts/index.ts new file mode 100644 index 0000000000000..f373b0d75c543 --- /dev/null +++ b/x-pack/test/functional/services/observability/alerts/index.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { ObservabilityAlertsPaginationProvider } from './pagination'; +import { ObservabilityAlertsCommonProvider } from './common'; + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export function ObservabilityAlertsProvider(context: FtrProviderContext) { + const common = ObservabilityAlertsCommonProvider(context); + const pagination = ObservabilityAlertsPaginationProvider(context); + + return { + common, + pagination, + }; +} diff --git a/x-pack/test/functional/services/observability/alerts/pagination.ts b/x-pack/test/functional/services/observability/alerts/pagination.ts new file mode 100644 index 0000000000000..3e28efd0b89b9 --- /dev/null +++ b/x-pack/test/functional/services/observability/alerts/pagination.ts @@ -0,0 +1,89 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +const ALERTS_ROWS_PER_PAGE_SELECTOR = 'tablePaginationPopoverButton'; +const ALERTS_PAGINATION_BUTTON_PREVIOUS = 'pagination-button-previous'; +const ALERTS_PAGINATION_BUTTON_NEXT = 'pagination-button-next'; +const ALERTS_PAGINATION_TEN_ROWS = 'tablePagination-10-rows'; +const ALERTS_PAGINATION_TWENTY_FIVE_ROWS = 'tablePagination-25-rows'; +const ALERTS_PAGINATION_FIFTY_ROWS = 'tablePagination-50-rows'; +const ALERTS_PAGINATION_BUTTON_ONE = 'pagination-button-0'; +const ALERTS_PAGINATION_BUTTON_TWO = 'pagination-button-1'; + +export function ObservabilityAlertsPaginationProvider({ getService }: FtrProviderContext) { + const testSubjects = getService('testSubjects'); + + const getPageSizeSelector = async () => { + return await testSubjects.find(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + + const getPageSizeSelectorOrFail = async () => { + return await testSubjects.existOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + + const missingPageSizeSelectorOrFail = async () => { + return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + + const getTenRowsPageSelector = async () => { + return await testSubjects.find(ALERTS_PAGINATION_TEN_ROWS); + }; + + const getTwentyFiveRowsPageSelector = async () => { + return await testSubjects.find(ALERTS_PAGINATION_TWENTY_FIVE_ROWS); + }; + + const getFiftyRowsPageSelector = async () => { + return await testSubjects.find(ALERTS_PAGINATION_FIFTY_ROWS); + }; + + const getPrevPaginationButton = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_PREVIOUS); + }; + + const getPrevPaginationButtonOrFail = async () => { + return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_PREVIOUS); + }; + + const missingPrevPaginationButtonOrFail = async () => { + return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + }; + + const getNextPaginationButton = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT, 20000); + }; + + const getNextPaginationButtonOrFail = async () => { + return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_NEXT); + }; + + const getPaginationButtonOne = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_ONE); + }; + + const getPaginationButtonTwo = async () => { + return await testSubjects.find(ALERTS_PAGINATION_BUTTON_TWO); + }; + + return { + getPageSizeSelector, + getPageSizeSelectorOrFail, + missingPageSizeSelectorOrFail, + getTenRowsPageSelector, + getTwentyFiveRowsPageSelector, + getFiftyRowsPageSelector, + getPrevPaginationButton, + getPrevPaginationButtonOrFail, + missingPrevPaginationButtonOrFail, + getNextPaginationButton, + getNextPaginationButtonOrFail, + getPaginationButtonOne, + getPaginationButtonTwo, + }; +} diff --git a/x-pack/test/observability_functional/apps/observability/alerts/index.ts b/x-pack/test/observability_functional/apps/observability/alerts/index.ts index 856d7e60996ec..14019472eb2ca 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/index.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/index.ts @@ -31,7 +31,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts'); - await observability.alerts.navigateToTimeWithData(); + await observability.alerts.common.navigateToTimeWithData(); }); after(async () => { @@ -40,50 +40,50 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe('Alerts table', () => { it('Renders the table', async () => { - await observability.alerts.getTableOrFail(); + await observability.alerts.common.getTableOrFail(); }); it('Renders the correct number of cells', async () => { await retry.try(async () => { - const cells = await observability.alerts.getTableCells(); + const cells = await observability.alerts.common.getTableCells(); expect(cells.length).to.be(TOTAL_ALERTS_CELL_COUNT); }); }); describe('Filtering', () => { afterEach(async () => { - await observability.alerts.clearQueryBar(); + await observability.alerts.common.clearQueryBar(); }); after(async () => { // NOTE: We do this as the query bar takes the place of the datepicker when it is in focus, so we'll reset // back to default. - await observability.alerts.submitQuery(''); + await observability.alerts.common.submitQuery(''); }); it('Autocompletion works', async () => { - await observability.alerts.typeInQueryBar('kibana.alert.s'); + await observability.alerts.common.typeInQueryBar('kibana.alert.s'); await testSubjects.existOrFail('autocompleteSuggestion-field-kibana.alert.start-'); await testSubjects.existOrFail('autocompleteSuggestion-field-kibana.alert.status-'); }); it('Applies filters correctly', async () => { - await observability.alerts.submitQuery('kibana.alert.status: recovered'); + await observability.alerts.common.submitQuery('kibana.alert.status: recovered'); await retry.try(async () => { - const cells = await observability.alerts.getTableCells(); + const cells = await observability.alerts.common.getTableCells(); expect(cells.length).to.be(RECOVERED_ALERTS_CELL_COUNT); }); }); it('Displays a no data state when filters produce zero results', async () => { - await observability.alerts.submitQuery('kibana.alert.consumer: uptime'); - await observability.alerts.getNoDataStateOrFail(); + await observability.alerts.common.submitQuery('kibana.alert.consumer: uptime'); + await observability.alerts.common.getNoDataStateOrFail(); }); }); describe('Date selection', () => { after(async () => { - await observability.alerts.navigateToTimeWithData(); + await observability.alerts.common.navigateToTimeWithData(); }); it('Correctly applies date picker selections', async () => { @@ -91,7 +91,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { await (await testSubjects.find('superDatePickerToggleQuickMenuButton')).click(); // We shouldn't expect any data for the last 15 minutes await (await testSubjects.find('superDatePickerCommonlyUsed_Last_15 minutes')).click(); - await observability.alerts.getNoDataStateOrFail(); + await observability.alerts.common.getNoDataStateOrFail(); await pageObjects.common.waitUntilUrlIncludes('rangeFrom=now-15m&rangeTo=now'); }); }); @@ -99,37 +99,38 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe('Flyout', () => { it('Can be opened', async () => { - await observability.alerts.openAlertsFlyout(); - await observability.alerts.getAlertsFlyoutOrFail(); + await observability.alerts.common.openAlertsFlyout(); + await observability.alerts.common.getAlertsFlyoutOrFail(); }); it('Can be closed', async () => { - await observability.alerts.closeAlertsFlyout(); + await observability.alerts.common.closeAlertsFlyout(); await testSubjects.missingOrFail('alertsFlyout'); }); describe('When open', async () => { before(async () => { - await observability.alerts.openAlertsFlyout(); + await observability.alerts.common.openAlertsFlyout(); }); after(async () => { - await observability.alerts.closeAlertsFlyout(); + await observability.alerts.common.closeAlertsFlyout(); }); it('Displays the correct title', async () => { await retry.try(async () => { const titleText = await ( - await observability.alerts.getAlertsFlyoutTitle() + await observability.alerts.common.getAlertsFlyoutTitle() ).getVisibleText(); expect(titleText).to.contain('Log threshold'); }); }); it('Displays the correct content', async () => { - const flyoutTitles = await observability.alerts.getAlertsFlyoutDescriptionListTitles(); + const flyoutTitles = + await observability.alerts.common.getAlertsFlyoutDescriptionListTitles(); const flyoutDescriptions = - await observability.alerts.getAlertsFlyoutDescriptionListDescriptions(); + await observability.alerts.common.getAlertsFlyoutDescriptionListDescriptions(); const expectedTitles = [ 'Status', @@ -158,7 +159,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); it('Displays a View in App button', async () => { - await observability.alerts.getAlertsFlyoutViewInAppButtonOrFail(); + await observability.alerts.common.getAlertsFlyoutViewInAppButtonOrFail(); }); }); }); @@ -166,35 +167,35 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe('Cell actions', () => { beforeEach(async () => { await retry.try(async () => { - const cells = await observability.alerts.getTableCells(); + const cells = await observability.alerts.common.getTableCells(); const alertStatusCell = cells[2]; await alertStatusCell.moveMouseTo(); await retry.waitFor( 'cell actions visible', - async () => await observability.alerts.copyToClipboardButtonExists() + async () => await observability.alerts.common.copyToClipboardButtonExists() ); }); }); afterEach(async () => { - await observability.alerts.clearQueryBar(); + await observability.alerts.common.clearQueryBar(); }); it('Copy button works', async () => { // NOTE: We don't have access to the clipboard in a headless environment, // so we'll just check the button is clickable in the functional tests. - await (await observability.alerts.getCopyToClipboardButton()).click(); + await (await observability.alerts.common.getCopyToClipboardButton()).click(); }); it('Filter for value works', async () => { - await (await observability.alerts.getFilterForValueButton()).click(); + await (await observability.alerts.common.getFilterForValueButton()).click(); const queryBarValue = await ( - await observability.alerts.getQueryBar() + await observability.alerts.common.getQueryBar() ).getAttribute('value'); expect(queryBarValue).to.be('kibana.alert.status: "active"'); // Wait for request await retry.try(async () => { - const cells = await observability.alerts.getTableCells(); + const cells = await observability.alerts.common.getTableCells(); expect(cells.length).to.be(ACTIVE_ALERTS_CELL_COUNT); }); }); diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts index b44db39baed6c..c68cde8dfc829 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -11,10 +11,10 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; const ROWS_COUNT_TO_HIDE_PAGE_SELECTOR = 10; const DEFAULT_ROWS_PER_PAGE = 50; -export default ({ getPageObjects, getService }: FtrProviderContext) => { +export default ({ getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); - describe('Alerts table pagination', function () { + describe('Observability alerts pagination', function () { this.tags('includeFirefox'); const retry = getService('retry'); @@ -22,7 +22,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts'); - await observability.alerts.navigateToTimeWithData(); + await observability.alerts.common.navigateToTimeWithData(); }); after(async () => { @@ -32,43 +32,43 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe(`When less than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { before(async () => { // current archiver has 3 closed alerts - await observability.alerts.setWorkflowStatusFilter('closed'); - const visibleAlerts = await observability.alerts.getTableCellsInRows(); + await observability.alerts.common.setWorkflowStatusFilter('closed'); + const visibleAlerts = await observability.alerts.common.getTableCellsInRows(); // make sure visible alerts are less than 10 expect(visibleAlerts.length).to.be.lessThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); }); after(async () => { - await observability.alerts.setWorkflowStatusFilter('open'); + await observability.alerts.common.setWorkflowStatusFilter('open'); }); it('Does not render page size selector', async () => { - await observability.alerts.missingPageSizeSelectorOrFail(); + await observability.alerts.pagination.missingPageSizeSelectorOrFail(); }); it('Does not render pagination controls', async () => { - await observability.alerts.missingPrevPaginationButtonOrFail(); + await observability.alerts.pagination.missingPrevPaginationButtonOrFail(); }); }); describe(`When more than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { before(async () => { // current archiver has 12 open alerts - await observability.alerts.setWorkflowStatusFilter('open'); - const visibleAlerts = await observability.alerts.getTableCellsInRows(); + await observability.alerts.common.setWorkflowStatusFilter('open'); + const visibleAlerts = await observability.alerts.common.getTableCellsInRows(); // make sure visible alerts are more than 10 expect(visibleAlerts.length).to.be.greaterThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); }); describe('Page size selector', () => { it('Renders page size selector', async () => { - await observability.alerts.getPageSizeSelectorOrFail(); + await observability.alerts.pagination.getPageSizeSelectorOrFail(); }); it('Default rows per page selector is 50', async () => { await retry.try(async () => { const defaultAlertsPerPage = await ( - await observability.alerts.getPageSizeSelector() + await observability.alerts.pagination.getPageSizeSelector() ).getVisibleText(); expect(defaultAlertsPerPage).to.contain(DEFAULT_ROWS_PER_PAGE); }); @@ -76,18 +76,18 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { it('10 rows per page selector works', async () => { await retry.try(async () => { - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTenRowsPageSelector()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); + await (await observability.alerts.pagination.getPageSizeSelector()).click(); + await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.not.be.greaterThan(10); // with current archiver data it is going to be 10. Shall we check against equality to.be(10) instead? }); }); it('25 rows per page selector works', async () => { await retry.try(async () => { - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTwentyFiveRowsPageSelector()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); + await (await observability.alerts.pagination.getPageSizeSelector()).click(); + await (await observability.alerts.pagination.getTwentyFiveRowsPageSelector()).click(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.not.be.greaterThan(25); }); }); @@ -95,25 +95,25 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { describe('Pagination controls', () => { before(async () => { - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTenRowsPageSelector()).click(); + await (await observability.alerts.pagination.getPageSizeSelector()).click(); + await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); }); beforeEach(async () => { // write a helper to move to first page - await (await observability.alerts.getPaginationButtonOne()).click(); + await (await observability.alerts.pagination.getPaginationButtonOne()).click(); }); it('Renders previous page button', async () => { - await observability.alerts.getPrevPaginationButtonOrFail(); + await observability.alerts.pagination.getPrevPaginationButtonOrFail(); }); it('Renders next page button', async () => { - await observability.alerts.getNextPaginationButtonOrFail(); + await observability.alerts.pagination.getNextPaginationButtonOrFail(); }); it('Previous page button is disabled', async () => { const prevButtonDisabledValue = await ( - await observability.alerts.getPrevPaginationButton() + await observability.alerts.pagination.getPrevPaginationButton() ).getAttribute('disabled'); expect(prevButtonDisabledValue).to.be('true'); }); @@ -123,34 +123,34 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { // timing issue? it.skip('Next page button is enabled', async () => { // TODO create a function goToSecondPage - await (await observability.alerts.getPageSizeSelector()).click(); - await (await observability.alerts.getTenRowsPageSelector()).click(); + await (await observability.alerts.pagination.getPageSizeSelector()).click(); + await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); const nextButtonDisabledValue = await ( - await observability.alerts.getPrevPaginationButton() + await observability.alerts.pagination.getPrevPaginationButton() ).getAttribute('disabled'); expect(nextButtonDisabledValue).to.be(null); }); it('Next page button works', async () => { - await (await observability.alerts.getNextPaginationButton()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); + await (await observability.alerts.pagination.getNextPaginationButton()).click(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(2); // don't hardcode this value, calculate open alerts/perRow }); it('Previous page button works', async () => { - await (await observability.alerts.getPaginationButtonTwo()).click(); - await (await observability.alerts.getPrevPaginationButton()).click(); - const tableRows = await observability.alerts.getTableCellsInRows(); + await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); + await (await observability.alerts.pagination.getPrevPaginationButton()).click(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(10); // don't hardcode this value, calculate open alerts/perRow }); it('Next page button is disabled', async () => { // TODO: write a helper to move to last page - await (await observability.alerts.getPaginationButtonTwo()).click(); + await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); // TODO: write a helper isButtonDisabled const nextButtonDisabledValue = await ( - await observability.alerts.getNextPaginationButton() + await observability.alerts.pagination.getNextPaginationButton() ).getAttribute('disabled'); expect(nextButtonDisabledValue).to.be('true'); }); From 51e9a93e32cccbe306c332a52f0d6caa5f75d9f1 Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 23 Sep 2021 12:42:04 +0200 Subject: [PATCH 13/19] undo configuration change --- x-pack/test/observability_functional/with_rac_write.config.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/test/observability_functional/with_rac_write.config.ts b/x-pack/test/observability_functional/with_rac_write.config.ts index 6363fdac84ad0..89a0da7857333 100644 --- a/x-pack/test/observability_functional/with_rac_write.config.ts +++ b/x-pack/test/observability_functional/with_rac_write.config.ts @@ -11,9 +11,7 @@ import { CA_CERT_PATH } from '@kbn/dev-utils'; import { FtrConfigProviderContext } from '@kbn/test'; export default async function ({ readConfigFile }: FtrConfigProviderContext) { - const xpackFunctionalConfig = await readConfigFile( - require.resolve('../functional/config.firefox.js') - ); + const xpackFunctionalConfig = await readConfigFile(require.resolve('../functional/config.js')); const servers = { ...xpackFunctionalConfig.get('servers'), From c14a59e437695c477d0e8c26b52f8e1462d49d58 Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 23 Sep 2021 13:05:02 +0200 Subject: [PATCH 14/19] fix workflow status tests after refactoring --- .../observability/alerts/workflow_status.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts b/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts index 6dcfe08f7a6d2..a68636b8cb0c0 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/workflow_status.ts @@ -21,7 +21,7 @@ export default ({ getService }: FtrProviderContext) => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts'); - await observability.alerts.navigateToTimeWithData(); + await observability.alerts.common.navigateToTimeWithData(); }); after(async () => { @@ -30,61 +30,61 @@ export default ({ getService }: FtrProviderContext) => { it('is filtered to only show "open" alerts by default', async () => { await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(OPEN_ALERTS_ROWS_COUNT); }); }); it('can be set to "acknowledged" using the row menu', async () => { - await observability.alerts.setWorkflowStatusForRow(0, 'acknowledged'); + await observability.alerts.common.setWorkflowStatusForRow(0, 'acknowledged'); await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(11); }); }); it('can be filtered to only show "acknowledged" alerts using the filter button', async () => { - await observability.alerts.setWorkflowStatusFilter('acknowledged'); + await observability.alerts.common.setWorkflowStatusFilter('acknowledged'); await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(3); }); }); it('can be set to "closed" using the row menu', async () => { - await observability.alerts.setWorkflowStatusForRow(0, 'closed'); + await observability.alerts.common.setWorkflowStatusForRow(0, 'closed'); await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(2); }); }); it('can be filtered to only show "closed" alerts using the filter button', async () => { - await observability.alerts.setWorkflowStatusFilter('closed'); + await observability.alerts.common.setWorkflowStatusFilter('closed'); await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(4); }); }); it('can be set to "open" using the row menu', async () => { - await observability.alerts.setWorkflowStatusForRow(0, 'open'); + await observability.alerts.common.setWorkflowStatusForRow(0, 'open'); await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(3); }); }); it('can be filtered to only show "open" alerts using the filter button', async () => { - await observability.alerts.setWorkflowStatusFilter('open'); + await observability.alerts.common.setWorkflowStatusFilter('open'); await retry.try(async () => { - const tableRows = await observability.alerts.getTableCellsInRows(); + const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(12); }); }); From 3cd5672eda1f857bd1977433b5435cbc5e84ad49 Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 23 Sep 2021 13:59:05 +0200 Subject: [PATCH 15/19] clean up --- .../observability/alerts/pagination.ts | 40 ++++++++++---- .../apps/observability/alerts/pagination.ts | 53 +++++-------------- 2 files changed, 43 insertions(+), 50 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts/pagination.ts b/x-pack/test/functional/services/observability/alerts/pagination.ts index 3e28efd0b89b9..b403ef7b02d68 100644 --- a/x-pack/test/functional/services/observability/alerts/pagination.ts +++ b/x-pack/test/functional/services/observability/alerts/pagination.ts @@ -43,23 +43,23 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide return await testSubjects.find(ALERTS_PAGINATION_FIFTY_ROWS); }; - const getPrevPaginationButton = async () => { + const getPrevPageButton = async () => { return await testSubjects.find(ALERTS_PAGINATION_BUTTON_PREVIOUS); }; - const getPrevPaginationButtonOrFail = async () => { + const getPrevPageButtonOrFail = async () => { return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_PREVIOUS); }; - const missingPrevPaginationButtonOrFail = async () => { + const missingPrevPageButtonOrFail = async () => { return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); }; - const getNextPaginationButton = async () => { + const getNextPageButton = async () => { return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT, 20000); }; - const getNextPaginationButtonOrFail = async () => { + const getNextPageButtonOrFail = async () => { return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_NEXT); }; @@ -71,6 +71,22 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide return await testSubjects.find(ALERTS_PAGINATION_BUTTON_TWO); }; + const goToNextPage = async () => { + return await (await getNextPageButton()).click(); + }; + + const goToPrevPage = async () => { + return await (await getPrevPageButton()).click(); + }; + + const goToFirstPage = async () => { + await (await getPaginationButtonOne()).click(); + }; + + const getPrevButtonDisabledValue = async () => { + return await (await getPrevPageButton()).getAttribute('disabled'); + }; + return { getPageSizeSelector, getPageSizeSelectorOrFail, @@ -78,12 +94,16 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide getTenRowsPageSelector, getTwentyFiveRowsPageSelector, getFiftyRowsPageSelector, - getPrevPaginationButton, - getPrevPaginationButtonOrFail, - missingPrevPaginationButtonOrFail, - getNextPaginationButton, - getNextPaginationButtonOrFail, + getPrevPageButton, + getPrevPageButtonOrFail, + missingPrevPageButtonOrFail, + getNextPageButton, + getNextPageButtonOrFail, getPaginationButtonOne, getPaginationButtonTwo, + goToNextPage, + goToPrevPage, + goToFirstPage, + getPrevButtonDisabledValue, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts index c68cde8dfc829..a4703d9fd5b73 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -33,9 +33,6 @@ export default ({ getService }: FtrProviderContext) => { before(async () => { // current archiver has 3 closed alerts await observability.alerts.common.setWorkflowStatusFilter('closed'); - const visibleAlerts = await observability.alerts.common.getTableCellsInRows(); - // make sure visible alerts are less than 10 - expect(visibleAlerts.length).to.be.lessThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); }); after(async () => { @@ -47,7 +44,7 @@ export default ({ getService }: FtrProviderContext) => { }); it('Does not render pagination controls', async () => { - await observability.alerts.pagination.missingPrevPaginationButtonOrFail(); + await observability.alerts.pagination.missingPrevPageButtonOrFail(); }); }); @@ -55,9 +52,6 @@ export default ({ getService }: FtrProviderContext) => { before(async () => { // current archiver has 12 open alerts await observability.alerts.common.setWorkflowStatusFilter('open'); - const visibleAlerts = await observability.alerts.common.getTableCellsInRows(); - // make sure visible alerts are more than 10 - expect(visibleAlerts.length).to.be.greaterThan(ROWS_COUNT_TO_HIDE_PAGE_SELECTOR); }); describe('Page size selector', () => { @@ -79,7 +73,7 @@ export default ({ getService }: FtrProviderContext) => { await (await observability.alerts.pagination.getPageSizeSelector()).click(); await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); const tableRows = await observability.alerts.common.getTableCellsInRows(); - expect(tableRows.length).to.not.be.greaterThan(10); // with current archiver data it is going to be 10. Shall we check against equality to.be(10) instead? + expect(tableRows.length).to.not.be.greaterThan(10); }); }); @@ -99,65 +93,44 @@ export default ({ getService }: FtrProviderContext) => { await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); }); beforeEach(async () => { - // write a helper to move to first page - await (await observability.alerts.pagination.getPaginationButtonOne()).click(); + await observability.alerts.pagination.goToFirstPage(); }); it('Renders previous page button', async () => { - await observability.alerts.pagination.getPrevPaginationButtonOrFail(); + await observability.alerts.pagination.getPrevPageButtonOrFail(); }); it('Renders next page button', async () => { - await observability.alerts.pagination.getNextPaginationButtonOrFail(); + await observability.alerts.pagination.getNextPageButtonOrFail(); }); it('Previous page button is disabled', async () => { - const prevButtonDisabledValue = await ( - await observability.alerts.pagination.getPrevPaginationButton() - ).getAttribute('disabled'); + const prevButtonDisabledValue = + await observability.alerts.pagination.getPrevButtonDisabledValue(); expect(prevButtonDisabledValue).to.be('true'); }); - // While running the test I inspected the elements on the page - // and although the disabled attribute was not there at all for some reason getAttribute('disabled') = 'true' - // timing issue? - it.skip('Next page button is enabled', async () => { - // TODO create a function goToSecondPage - await (await observability.alerts.pagination.getPageSizeSelector()).click(); - await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); - const nextButtonDisabledValue = await ( - await observability.alerts.pagination.getPrevPaginationButton() - ).getAttribute('disabled'); - expect(nextButtonDisabledValue).to.be(null); - }); - it('Next page button works', async () => { - await (await observability.alerts.pagination.getNextPaginationButton()).click(); + await observability.alerts.pagination.goToNextPage(); const tableRows = await observability.alerts.common.getTableCellsInRows(); - expect(tableRows.length).to.be(2); // don't hardcode this value, calculate open alerts/perRow + expect(tableRows.length).to.be(2); }); it('Previous page button works', async () => { await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); - await (await observability.alerts.pagination.getPrevPaginationButton()).click(); + await observability.alerts.pagination.goToPrevPage(); const tableRows = await observability.alerts.common.getTableCellsInRows(); - expect(tableRows.length).to.be(10); // don't hardcode this value, calculate open alerts/perRow + expect(tableRows.length).to.be(10); }); it('Next page button is disabled', async () => { - // TODO: write a helper to move to last page await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); - // TODO: write a helper isButtonDisabled - const nextButtonDisabledValue = await ( - await observability.alerts.pagination.getNextPaginationButton() - ).getAttribute('disabled'); + const nextButtonDisabledValue = + await observability.alerts.pagination.getPrevButtonDisabledValue(); expect(nextButtonDisabledValue).to.be('true'); }); }); - - it('Table scrolls when page size is large', async () => {}); - it('Table does not scroll when page size is small', async () => {}); }); }); }; From 6aa828b5db72dd42bc3faadeaf3a035762009172 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 29 Sep 2021 11:28:33 +0200 Subject: [PATCH 16/19] pr review comments --- .../observability/alerts/pagination.ts | 47 ++++++++++--------- .../apps/observability/alerts/pagination.ts | 2 +- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts/pagination.ts b/x-pack/test/functional/services/observability/alerts/pagination.ts index b403ef7b02d68..4d2bbefb60632 100644 --- a/x-pack/test/functional/services/observability/alerts/pagination.ts +++ b/x-pack/test/functional/services/observability/alerts/pagination.ts @@ -7,68 +7,68 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; -const ALERTS_ROWS_PER_PAGE_SELECTOR = 'tablePaginationPopoverButton'; -const ALERTS_PAGINATION_BUTTON_PREVIOUS = 'pagination-button-previous'; -const ALERTS_PAGINATION_BUTTON_NEXT = 'pagination-button-next'; -const ALERTS_PAGINATION_TEN_ROWS = 'tablePagination-10-rows'; -const ALERTS_PAGINATION_TWENTY_FIVE_ROWS = 'tablePagination-25-rows'; -const ALERTS_PAGINATION_FIFTY_ROWS = 'tablePagination-50-rows'; -const ALERTS_PAGINATION_BUTTON_ONE = 'pagination-button-0'; -const ALERTS_PAGINATION_BUTTON_TWO = 'pagination-button-1'; +const ROWS_PER_PAGE_SELECTOR = 'tablePaginationPopoverButton'; +const PREV_BUTTON_SELECTOR = 'pagination-button-previous'; +const NEXT_BUTTON_SELECTOR = 'pagination-button-next'; +const TEN_ROWS_SELECTOR = 'tablePagination-10-rows'; +const TWENTY_FIVE_ROWS_SELECTOR = 'tablePagination-25-rows'; +const FIFTY_ROWS_SELECTOR = 'tablePagination-50-rows'; +const BUTTON_ONE_SELECTOR = 'pagination-button-0'; +const BUTTON_TWO_SELECTOR = 'pagination-button-1'; export function ObservabilityAlertsPaginationProvider({ getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); const getPageSizeSelector = async () => { - return await testSubjects.find(ALERTS_ROWS_PER_PAGE_SELECTOR); + return await testSubjects.find(ROWS_PER_PAGE_SELECTOR); }; const getPageSizeSelectorOrFail = async () => { - return await testSubjects.existOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + return await testSubjects.existOrFail(ROWS_PER_PAGE_SELECTOR); }; const missingPageSizeSelectorOrFail = async () => { - return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + return await testSubjects.missingOrFail(ROWS_PER_PAGE_SELECTOR); }; const getTenRowsPageSelector = async () => { - return await testSubjects.find(ALERTS_PAGINATION_TEN_ROWS); + return await testSubjects.find(TEN_ROWS_SELECTOR); }; const getTwentyFiveRowsPageSelector = async () => { - return await testSubjects.find(ALERTS_PAGINATION_TWENTY_FIVE_ROWS); + return await testSubjects.find(TWENTY_FIVE_ROWS_SELECTOR); }; const getFiftyRowsPageSelector = async () => { - return await testSubjects.find(ALERTS_PAGINATION_FIFTY_ROWS); + return await testSubjects.find(FIFTY_ROWS_SELECTOR); }; const getPrevPageButton = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_PREVIOUS); + return await testSubjects.find(PREV_BUTTON_SELECTOR); }; const getPrevPageButtonOrFail = async () => { - return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_PREVIOUS); + return await testSubjects.existOrFail(PREV_BUTTON_SELECTOR); }; const missingPrevPageButtonOrFail = async () => { - return await testSubjects.missingOrFail(ALERTS_ROWS_PER_PAGE_SELECTOR); + return await testSubjects.missingOrFail(PREV_BUTTON_SELECTOR); }; const getNextPageButton = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_NEXT, 20000); + return await testSubjects.find(NEXT_BUTTON_SELECTOR, 20000); }; const getNextPageButtonOrFail = async () => { - return await testSubjects.existOrFail(ALERTS_PAGINATION_BUTTON_NEXT); + return await testSubjects.existOrFail(NEXT_BUTTON_SELECTOR); }; const getPaginationButtonOne = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_ONE); + return await testSubjects.find(BUTTON_ONE_SELECTOR); }; const getPaginationButtonTwo = async () => { - return await testSubjects.find(ALERTS_PAGINATION_BUTTON_TWO); + return await testSubjects.find(BUTTON_TWO_SELECTOR); }; const goToNextPage = async () => { @@ -87,6 +87,10 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide return await (await getPrevPageButton()).getAttribute('disabled'); }; + const getNextButtonDisabledValue = async () => { + return await (await getNextPageButton()).getAttribute('disabled'); + }; + return { getPageSizeSelector, getPageSizeSelectorOrFail, @@ -105,5 +109,6 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide goToPrevPage, goToFirstPage, getPrevButtonDisabledValue, + getNextButtonDisabledValue, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts index a4703d9fd5b73..c4b56bc89c3f5 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -127,7 +127,7 @@ export default ({ getService }: FtrProviderContext) => { it('Next page button is disabled', async () => { await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); const nextButtonDisabledValue = - await observability.alerts.pagination.getPrevButtonDisabledValue(); + await observability.alerts.pagination.getNextButtonDisabledValue(); expect(nextButtonDisabledValue).to.be('true'); }); }); From 0b0bcd597416095f8198c867eb80f0c81750306f Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 29 Sep 2021 11:58:21 +0200 Subject: [PATCH 17/19] change variable name --- .../apps/observability/alerts/pagination.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts index c4b56bc89c3f5..f3471dab40622 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../ftr_provider_context'; -const ROWS_COUNT_TO_HIDE_PAGE_SELECTOR = 10; +const ROWS_NEEDED_FOR_PAGINATION = 10; const DEFAULT_ROWS_PER_PAGE = 50; export default ({ getService }: FtrProviderContext) => { @@ -29,7 +29,7 @@ export default ({ getService }: FtrProviderContext) => { await esArchiver.unload('x-pack/test/functional/es_archives/observability/alerts'); }); - describe(`When less than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { + describe(`When less than ${ROWS_NEEDED_FOR_PAGINATION} alerts are found`, () => { before(async () => { // current archiver has 3 closed alerts await observability.alerts.common.setWorkflowStatusFilter('closed'); @@ -48,7 +48,7 @@ export default ({ getService }: FtrProviderContext) => { }); }); - describe(`When more than ${ROWS_COUNT_TO_HIDE_PAGE_SELECTOR} alerts are visible in the screen`, () => { + describe(`When ${ROWS_NEEDED_FOR_PAGINATION} alerts are found`, () => { before(async () => { // current archiver has 12 open alerts await observability.alerts.common.setWorkflowStatusFilter('open'); From af8275f47c5ac7076751a31a8a9af8afdddf5b96 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 29 Sep 2021 13:42:23 +0200 Subject: [PATCH 18/19] rewording pagination tests --- .../apps/observability/alerts/pagination.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts index f3471dab40622..0f7ead9af1b98 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -59,7 +59,7 @@ export default ({ getService }: FtrProviderContext) => { await observability.alerts.pagination.getPageSizeSelectorOrFail(); }); - it('Default rows per page selector is 50', async () => { + it('Default rows per page is 50', async () => { await retry.try(async () => { const defaultAlertsPerPage = await ( await observability.alerts.pagination.getPageSizeSelector() @@ -68,7 +68,7 @@ export default ({ getService }: FtrProviderContext) => { }); }); - it('10 rows per page selector works', async () => { + it('Shows up to 10 rows per page', async () => { await retry.try(async () => { await (await observability.alerts.pagination.getPageSizeSelector()).click(); await (await observability.alerts.pagination.getTenRowsPageSelector()).click(); @@ -77,7 +77,7 @@ export default ({ getService }: FtrProviderContext) => { }); }); - it('25 rows per page selector works', async () => { + it('Shows up to 25 rows per page', async () => { await retry.try(async () => { await (await observability.alerts.pagination.getPageSizeSelector()).click(); await (await observability.alerts.pagination.getTwentyFiveRowsPageSelector()).click(); @@ -110,13 +110,13 @@ export default ({ getService }: FtrProviderContext) => { expect(prevButtonDisabledValue).to.be('true'); }); - it('Next page button works', async () => { + it('Goes to next page', async () => { await observability.alerts.pagination.goToNextPage(); const tableRows = await observability.alerts.common.getTableCellsInRows(); expect(tableRows.length).to.be(2); }); - it('Previous page button works', async () => { + it('Goes to previous page', async () => { await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); await observability.alerts.pagination.goToPrevPage(); const tableRows = await observability.alerts.common.getTableCellsInRows(); From 8fabfb016a574affaec9a47993411382932f308a Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 29 Sep 2021 19:28:20 +0200 Subject: [PATCH 19/19] delete redundant test --- .../functional/services/observability/alerts/pagination.ts | 7 +------ .../apps/observability/alerts/pagination.ts | 7 ------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/x-pack/test/functional/services/observability/alerts/pagination.ts b/x-pack/test/functional/services/observability/alerts/pagination.ts index 4d2bbefb60632..6bffcf3596e2d 100644 --- a/x-pack/test/functional/services/observability/alerts/pagination.ts +++ b/x-pack/test/functional/services/observability/alerts/pagination.ts @@ -56,7 +56,7 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide }; const getNextPageButton = async () => { - return await testSubjects.find(NEXT_BUTTON_SELECTOR, 20000); + return await testSubjects.find(NEXT_BUTTON_SELECTOR); }; const getNextPageButtonOrFail = async () => { @@ -87,10 +87,6 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide return await (await getPrevPageButton()).getAttribute('disabled'); }; - const getNextButtonDisabledValue = async () => { - return await (await getNextPageButton()).getAttribute('disabled'); - }; - return { getPageSizeSelector, getPageSizeSelectorOrFail, @@ -109,6 +105,5 @@ export function ObservabilityAlertsPaginationProvider({ getService }: FtrProvide goToPrevPage, goToFirstPage, getPrevButtonDisabledValue, - getNextButtonDisabledValue, }; } diff --git a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts index 0f7ead9af1b98..5cefe8fd42c8a 100644 --- a/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts +++ b/x-pack/test/observability_functional/apps/observability/alerts/pagination.ts @@ -123,13 +123,6 @@ export default ({ getService }: FtrProviderContext) => { expect(tableRows.length).to.be(10); }); - - it('Next page button is disabled', async () => { - await (await observability.alerts.pagination.getPaginationButtonTwo()).click(); - const nextButtonDisabledValue = - await observability.alerts.pagination.getNextButtonDisabledValue(); - expect(nextButtonDisabledValue).to.be('true'); - }); }); }); });