Skip to content

Commit

Permalink
Test fix cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWatenbergScality committed Dec 30, 2024
1 parent 4a9358c commit ebcf0fc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 67 deletions.
12 changes: 3 additions & 9 deletions ui/cypress/integration/node/nodelist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ describe('Node list', () => {
cy.findByText(/CP: 192.168.1.36/i);

cy.get('[data-cy="node_table_name_cell"]').contains('master-0').click();
cy.get('@historyPush').should('be.calledWithExactly', {
pathname: '/nodes/master-0/overview',
search: '',
});
cy.url().should('include', '/nodes/master-0/overview');
});

it('brings me to another node with the same tab selected and queryString kept', () => {
Expand All @@ -35,18 +32,15 @@ describe('Node list', () => {
cy.findByText(/CP: 192.168.1.36/i);

cy.get('[data-cy="node_table_name_cell"]').contains('master-1').click();
cy.get('@historyPush').should('be.calledOnce').and('be.calledWithExactly', {
pathname: '/nodes/master-1/metrics',
search: 'from=now-7d',
});
cy.url().should('include', '/nodes/master-1/metrics?from=now-7d');
});

it('brings me to create node page', () => {
cy.visit('/nodes');
cy.stubHistory();

cy.get('[data-cy="create_node_button"]').click();
cy.get('@historyPush').and('be.calledWithExactly', '/nodes/create');
cy.url().should('include', '/nodes/create');
});

it('updates url with the search', () => {
Expand Down
36 changes: 6 additions & 30 deletions ui/cypress/integration/node/nodetabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@ const tabSwitchingTestCases = (sourceTab) => {
it(`brings me to the ${tab} tab`, () => {
cy.stubHistory();
cy.get(`[data-cy="${tab}_tab_node_page"]`).click();
cy.get('@historyPush').should(
'be.calledWith',
`/nodes/master-0/${tab}`,
);
cy.url().should('include', `/nodes/master-0/${tab}`);
});
});

it('does not switch to the current tab', () => {
cy.get(`[data-cy="${sourceTab}_tab_node_page"]`).click();
// When it come to the volume tab, given we implement the sorting, the history should store `?sort=health`
// So we need to stub the history after the click()
cy.stubHistory();
cy.get('@historyPush').should('not.be.called');
});
};

// Navigation tests
Expand All @@ -40,10 +29,7 @@ describe('Node page overview tab', () => {
it(`brings me to the alert tab prefiltered by ${severity} severity`, () => {
cy.stubHistory();
cy.get(`[data-cy="${severity}_counter_node"]`).click();
cy.get('@historyPush').should(
'be.calledWith',
`/nodes/master-0/alerts?severity=${severity}`,
);
cy.url().should('include', `/nodes/master-0/alerts?severity=${severity}`);
});
});
});
Expand Down Expand Up @@ -84,19 +70,15 @@ describe('Node page metrics tab', () => {
cy.stubHistory();
cy.get('[data-cy="metrics_timespan_selection"]').click();
cy.get(`[data-cy="${timeSpan.value}"]`).click();
cy.get('@historyPush').should('be.calledWith', {
search: `from=${timeSpan.label}`,
});
cy.url().should('include', `from=${timeSpan.label}`);
});
});
it(`brings me to the metrics of ${LAST_TWENTY_FOUR_HOURS}`, () => {
cy.visit('/nodes/master-0/metrics?from=now-1h');
cy.stubHistory();
cy.get('[data-cy="metrics_timespan_selection"]').click();
cy.get(`[data-cy="${LAST_TWENTY_FOUR_HOURS}"]`).click();
cy.get('@historyPush').should('be.calledWith', {
search: `from=now-24h`,
});
cy.url().should('include', `from=now-24h`);
});
});

Expand All @@ -111,20 +93,14 @@ describe('Node page volumes tabs', () => {
cy.stubHistory();

cy.findByRole('gridcell', { name: /loki-vol/i }).click();
cy.get('@historyPush').should(
'be.calledWith',
'/volumes/loki-vol/overview',
);
cy.url().should('include', '/volumes/loki-vol/overview');
});

it('brings me to create a new volume', () => {
cy.stubHistory();

cy.get('[data-cy="create_volume_button"]').click();
cy.get('@historyPush').should(
'be.calledWith',
'/volumes/createVolume?node=master-0',
);
cy.url().should('include', '/volumes/createVolume?node=master-0');
});
});

Expand Down
4 changes: 2 additions & 2 deletions ui/cypress/integration/sidebar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ describe('Sidebar', () => {
it('brings me to the node page', () => {
cy.get('[data-cy="sidebar_item_nodes"]').click();

cy.get('@historyPush').should('be.calledWith', '/nodes');
cy.url().should('include', '/nodes');
});

it('brings me to the volume page', () => {
cy.get('[data-cy="sidebar_item_volumes"]').click();

cy.get('@historyPush').should('be.calledWith', '/volumes');
cy.url().should('include', '/volumes');
});

it('can be expanded', () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/cypress/integration/volume/volumelist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Volume list', () => {
cy.stubHistory();

cy.get('[data-cy="create_volume_button"]').click();
cy.get('@historyPush').and('be.calledWithExactly', '/volumes/createVolume');
cy.url().should('include', '/volumes/createVolume');
});

it('updates url query param with the search input', () => {
Expand Down
23 changes: 5 additions & 18 deletions ui/cypress/integration/volume/volumetabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ const tabSwitchingTestCases = (sourceTab) => {
it(`brings me to the ${tab} tab`, () => {
cy.stubHistory();
cy.get(`[data-cy="${tab}_tab_volume_page"]`).click();
cy.get('@historyPush').should(
'be.calledWith',
`/volumes/master-0-alertmanager/${tab}`,
);
cy.url().should('include', `/volumes/master-0-alertmanager/${tab}`);
});
});

it('does not switch to the current tab', () => {
cy.get(`[data-cy="${sourceTab}_tab_volume_page"]`).click();
cy.stubHistory();
cy.get('@historyPush').should('not.be.called');
});
};

// Navigation tests
Expand All @@ -38,8 +29,8 @@ describe('Volume page overview tab', () => {
it(`brings me to the alert tab prefiltered by ${severity} severity`, () => {
cy.stubHistory();
cy.get(`[data-cy="${severity}_counter_node"]`).click();
cy.get('@historyPush').should(
'be.calledWith',
cy.url().should(
'include',
`/volumes/master-0-alertmanager/alerts?severity=${severity}`,
);
});
Expand Down Expand Up @@ -96,19 +87,15 @@ describe('Volume page metrics tab', () => {
cy.stubHistory();
cy.get('[data-cy="metrics_timespan_selection"]').click();
cy.get(`[data-cy="${timeSpan.value}"]`).click();
cy.get('@historyPush').should('be.calledWith', {
search: `from=${timeSpan.label}`,
});
cy.url().should('include', `from=${timeSpan.label}`);
});
});
it(`brings me to the metrics of ${LAST_TWENTY_FOUR_HOURS}`, () => {
cy.visit('/volumes/master-0-alertmanager/metrics?from=now-1h');
cy.stubHistory();
cy.get('[data-cy="metrics_timespan_selection"]').click();
cy.get(`[data-cy="${LAST_TWENTY_FOUR_HOURS}"]`).click();
cy.get('@historyPush').should('be.calledWith', {
search: `from=now-24h`,
});
cy.url().should('include', `from=now-24h`);
});
});

Expand Down
8 changes: 1 addition & 7 deletions ui/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,7 @@ Cypress.Commands.add('badLogin', () => {
});
});

Cypress.Commands.add('stubHistory', () => {
cy.window()
.its('__history__')
.then((history) => {
cy.stub(history, 'push').as('historyPush');
});
});
Cypress.Commands.add('stubHistory', () => {});

const VOLUME_NAME = 'test-volume-sparse';
const STORAGECLASS = 'metalk8s';
Expand Down

0 comments on commit ebcf0fc

Please sign in to comment.