Skip to content

Commit

Permalink
Fix All Users and All Hosts page should reset the current page when s…
Browse files Browse the repository at this point in the history
…orting (#133111) (#133181)

* Fix All Users, and All Hosts page should reset the current page when sorting

* Add cypress tests

(cherry picked from commit 9d854de)

Co-authored-by: Pablo Machado <pablo.nevesmachado@elastic.co>
  • Loading branch information
kibanamachine and machadoum committed May 31, 2022
1 parent 1ba586f commit 2111fc4
Show file tree
Hide file tree
Showing 7 changed files with 8,248 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,98 +11,141 @@ import {
} from '../../screens/hosts/uncommon_processes';
import { FIRST_PAGE_SELECTOR, SECOND_PAGE_SELECTOR } from '../../screens/pagination';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';

import { waitsForEventsToBeLoaded } from '../../tasks/hosts/events';
import { openEvents, openUncommonProcesses } from '../../tasks/hosts/main';
import { waitForUncommonProcessesToBeLoaded } from '../../tasks/hosts/uncommon_processes';
import { login, visit } from '../../tasks/login';
import { goToFirstPage, goToSecondPage } from '../../tasks/pagination';
import { goToFirstPage, goToSecondPage, sortFirstColumn } from '../../tasks/pagination';
import { refreshPage } from '../../tasks/security_header';

import { HOSTS_PAGE_TAB_URLS } from '../../urls/navigation';
import { HOSTS_URL, USERS_URL, HOSTS_PAGE_TAB_URLS } from '../../urls/navigation';
import { ALL_HOSTS_TABLE } from '../../screens/hosts/all_hosts';
import { ALL_USERS_TABLE } from '../../screens/users/all_users';

describe('Pagination', () => {
before(() => {
esArchiverLoad('host_uncommon_processes');
login();
visit(HOSTS_PAGE_TAB_URLS.uncommonProcesses);
waitForUncommonProcessesToBeLoaded();
});
after(() => {
esArchiverUnload('host_uncommon_processes');
});

afterEach(() => {
goToFirstPage();
});
describe('Host uncommon processes table)', () => {
before(() => {
esArchiverLoad('host_uncommon_processes');
visit(HOSTS_PAGE_TAB_URLS.uncommonProcesses);
waitForUncommonProcessesToBeLoaded();
});
after(() => {
esArchiverUnload('host_uncommon_processes');
});

it('pagination updates results and page number', () => {
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');

cy.get(UNCOMMON_PROCESSES_TABLE)
.find(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.then((processNameFirstPage) => {
goToSecondPage();
waitForUncommonProcessesToBeLoaded();
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.should((processNameSecondPage) => {
expect(processNameFirstPage).not.to.eq(processNameSecondPage);
});
});
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('not.have.class', 'euiPaginationButton-isActive');
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(SECOND_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
});
afterEach(() => {
goToFirstPage();
});

it('pagination updates results and page number', () => {
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');

cy.get(UNCOMMON_PROCESSES_TABLE)
.find(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.then((processNameFirstPage) => {
goToSecondPage();
waitForUncommonProcessesToBeLoaded();
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.should((processNameSecondPage) => {
expect(processNameFirstPage).not.to.eq(processNameSecondPage);
});
});
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('not.have.class', 'euiPaginationButton-isActive');
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(SECOND_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
});

it('pagination keeps track of page results when tabs change', () => {
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
goToSecondPage();
waitForUncommonProcessesToBeLoaded();

it('pagination keeps track of page results when tabs change', () => {
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
goToSecondPage();
waitForUncommonProcessesToBeLoaded();

cy.get(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.then((expectedThirdPageResult) => {
openEvents();
waitsForEventsToBeLoaded();
cy.get(FIRST_PAGE_SELECTOR).should('have.class', 'euiPaginationButton-isActive');
openUncommonProcesses();
waitForUncommonProcessesToBeLoaded();
cy.get(SECOND_PAGE_SELECTOR).should('have.class', 'euiPaginationButton-isActive');
cy.get(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.should((actualThirdPageResult) => {
expect(expectedThirdPageResult).to.eq(actualThirdPageResult);
});
});
cy.get(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.then((expectedThirdPageResult) => {
openEvents();
waitsForEventsToBeLoaded();
cy.get(FIRST_PAGE_SELECTOR).should('have.class', 'euiPaginationButton-isActive');
openUncommonProcesses();
waitForUncommonProcessesToBeLoaded();
cy.get(SECOND_PAGE_SELECTOR).should('have.class', 'euiPaginationButton-isActive');
cy.get(PROCESS_NAME_FIELD)
.first()
.invoke('text')
.should((actualThirdPageResult) => {
expect(expectedThirdPageResult).to.eq(actualThirdPageResult);
});
});
});

it('pagination resets results and page number to first page when refresh is clicked', () => {
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
goToSecondPage();
waitForUncommonProcessesToBeLoaded();
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('not.have.class', 'euiPaginationButton-isActive');
refreshPage();
waitForUncommonProcessesToBeLoaded();
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
});
});

it('pagination resets results and page number to first page when refresh is clicked', () => {
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
goToSecondPage();
waitForUncommonProcessesToBeLoaded();
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('not.have.class', 'euiPaginationButton-isActive');
refreshPage();
waitForUncommonProcessesToBeLoaded();
cy.get(UNCOMMON_PROCESSES_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
describe('All users and all Hosts tables', () => {
before(() => {
esArchiverLoad('all_users');
});

after(() => {
esArchiverUnload('all_users');
});

it(`reset all Hosts pagination when sorting column`, () => {
visit(HOSTS_URL);
goToSecondPage();
cy.get(ALL_HOSTS_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('not.have.class', 'euiPaginationButton-isActive');

sortFirstColumn();

cy.get(ALL_HOSTS_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
});

it(`reset all users pagination when sorting column`, () => {
visit(USERS_URL);
goToSecondPage();
cy.get(ALL_USERS_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('not.have.class', 'euiPaginationButton-isActive');

sortFirstColumn();

cy.get(ALL_USERS_TABLE)
.find(FIRST_PAGE_SELECTOR)
.should('have.class', 'euiPaginationButton-isActive');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

export const FIRST_PAGE_SELECTOR = '[data-test-subj="pagination-button-0"]';
export const SECOND_PAGE_SELECTOR = '[data-test-subj="pagination-button-1"]';
export const SORT_BTN = '[data-test-subj="tableHeaderSortButton"]';
6 changes: 5 additions & 1 deletion x-pack/plugins/security_solution/cypress/tasks/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { FIRST_PAGE_SELECTOR, SECOND_PAGE_SELECTOR } from '../screens/pagination';
import { FIRST_PAGE_SELECTOR, SECOND_PAGE_SELECTOR, SORT_BTN } from '../screens/pagination';

export const goToFirstPage = () => {
cy.get(FIRST_PAGE_SELECTOR).last().click({ force: true });
Expand All @@ -14,3 +14,7 @@ export const goToFirstPage = () => {
export const goToSecondPage = () => {
cy.get(SECOND_PAGE_SELECTOR).last().click({ force: true });
};

export const sortFirstColumn = () => {
cy.get(SORT_BTN).first().click();
};
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const hostsReducer = reducerWithInitialState(initialHostsState)
...state[hostsType].queries[HostsTableType.hosts],
direction: sort.direction,
sortField: sort.field,
activePage: DEFAULT_TABLE_ACTIVE_PAGE,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const usersReducer = reducerWithInitialState(initialUsersState)
[tableType]: {
...state.page.queries[tableType],
sort,
activePage: DEFAULT_TABLE_ACTIVE_PAGE,
},
},
},
Expand Down
Loading

0 comments on commit 2111fc4

Please sign in to comment.