Skip to content

Commit

Permalink
Add e2e test for resource search and namespace filter issue (#10932)
Browse files Browse the repository at this point in the history
* Add e2e test for resource search and namespace filter issue

* Fix lint issues
  • Loading branch information
nwmac authored May 7, 2024
1 parent 44dccd7 commit da47da7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cypress/e2e/po/dialog/ResourceSearchDialog.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ComponentPo from '@/cypress/e2e/po/components/component.po';

const CMD_K_KEY = {
key: 'k',
keyCode: 75,
which: 75,
code: 'KeyK',
location: 0,
altKey: false,
ctrlKey: false,
metaKey: true,
shiftKey: false,
repeat: false
};

export default class ResourceSearchDialog extends ComponentPo {
constructor() {
super('[data-modal="searchModal"]');
}

open() {
cy.keyboardControls(CMD_K_KEY, 1);
}

close() {
cy.get('body').click(10, 10); // Click outside of the search modal
}

searchBox() {
return this.self().get('input.search');
}

results() {
return this.self().get('.results li.child .label');
}
}
4 changes: 4 additions & 0 deletions cypress/e2e/po/pages/explorer/cluster-dashboard.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ export default class ClusterDashboardPagePo extends PagePo {
fullEventsLink() {
return cy.get('.events-table-link').contains('Full events list');
}

resourceSearchButton(): Cypress.Chainable {
return cy.get('[data-testid="header-resource-search"]');
}
}
65 changes: 65 additions & 0 deletions cypress/e2e/tests/pages/explorer/resource-search.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import ClusterDashboardPagePo from '@/cypress/e2e/po/pages/explorer/cluster-dashboard.po';
import ResourceSearchDialog from '@/cypress/e2e/po/dialog/ResourceSearchDialog.po';
import { NamespaceFilterPo } from '@/cypress/e2e/po/components/namespace-filter.po';
import { ConfigMapPagePo } from '@/cypress/e2e/po/pages/explorer/config-map.po';

const clusterDashboard = new ClusterDashboardPagePo('local');

describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@adminUser', '@standardUser'] }, () => {
before(() => {
cy.login();
HomePagePo.goTo();

ClusterDashboardPagePo.navTo();
});

it('can show resource search dialog', () => {
// Open the resource search
clusterDashboard.resourceSearchButton().click();

const dialog = new ResourceSearchDialog();

dialog.checkExists();
dialog.checkVisible();

dialog.searchBox().type('ConfigMap');

dialog.results().should('have.length', 1);
dialog.results().first().should('have.text', 'ConfigMaps');

dialog.close();

dialog.checkNotExists();
});

it('can show resource dialog when namespace chooser is open', () => {
const namespacePicker = new NamespaceFilterPo();

namespacePicker.toggle();
namespacePicker.clickOptionByLabel('Only User Namespaces');
namespacePicker.isChecked('Only User Namespaces');

// Namespace filter is still open
const dialog = new ResourceSearchDialog();

// Open the resource search
dialog.open();

dialog.checkExists();
dialog.checkVisible();

dialog.searchBox().type('ConfigMap');

dialog.results().should('have.length', 1);
dialog.results().first().should('have.text', 'ConfigMaps');

dialog.results().first().click();

const configMapPage = new ConfigMapPagePo('local');

configMapPage.waitForPage();

dialog.checkNotExists();
});
});
1 change: 1 addition & 0 deletions shell/components/nav/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ export default {
v-shortkey="{windows: ['ctrl', 'k'], mac: ['meta', 'k']}"
type="button"
class="btn header-btn role-tertiary"
data-testid="header-resource-search"
@shortkey="openSearch()"
@click="openSearch()"
>
Expand Down

0 comments on commit da47da7

Please sign in to comment.