Skip to content

Commit

Permalink
Fix bug with dialog for pod deletion (#11307)
Browse files Browse the repository at this point in the history
* Fix bug with dialog for pod deletion

* Fix merge issues

* Remove deletion hook, as the test actually deletes the pod
  • Loading branch information
nwmac authored Jul 1, 2024
1 parent 0d9c05a commit 3e41a64
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 11 deletions.
12 changes: 9 additions & 3 deletions cypress/e2e/po/components/sortable-table.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export default class SortableTablePo extends ComponentPo {
.type(searchText);
}

resetFilter() {
return cy.get('[data-testid="search-box-filter-row"] input')
.focus()
.clear();
}

//
// sortable-table
//
Expand Down Expand Up @@ -167,12 +173,12 @@ export default class SortableTablePo extends ComponentPo {
* @param expected number of rows shown
* @returns
*/
checkRowCount(isEmpty: boolean, expected: number) {
checkRowCount(isEmpty: boolean, expected: number, hasFilter = false) {
return this.rowElements().should((el) => {
if (isEmpty) {
expect(el).to.have.length(expected);
expect(el).to.have.text('There are no rows to show.');
expect(el).to.have.attr('class', 'no-rows');
expect(el).to.have.text(hasFilter ? 'There are no rows which match your search query.' : 'There are no rows to show.');
expect(el).to.have.attr('class', hasFilter ? 'no-results' : 'no-rows');
} else {
expect(el).to.have.length(expected);
expect(el).to.have.attr('data-node-id');
Expand Down
8 changes: 8 additions & 0 deletions cypress/e2e/po/pages/explorer/workloads-pods.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import PagePo from '@/cypress/e2e/po/pages/page.po';
import PodsListPo from '@/cypress/e2e/po/lists/pods-list.po';
import BurgerMenuPo from '@/cypress/e2e/po/side-bars/burger-side-menu.po';
import ProductNavPo from '@/cypress/e2e/po/side-bars/product-side-nav.po';

import { WorkloadsCreatePageBasePo } from '@/cypress/e2e/po/pages/explorer/workloads/workloads.po';

export class WorkloadsPodsListPagePo extends PagePo {
private static createPath(clusterId: string) {
return `/c/${ clusterId }/explorer/pod`;
Expand Down Expand Up @@ -64,3 +67,8 @@ export class WorkLoadsPodDetailsPagePo extends PagePo {
WorkLoadsPodDetailsPagePo.url = WorkLoadsPodDetailsPagePo.createPath(podId, clusterId, namespaceId, queryParams);
}
}
export class WorkloadsPodsCreatePagePo extends WorkloadsCreatePageBasePo {
constructor(protected clusterId: string = 'local', workloadType = 'pod', queryParams?: Record<string, string>) {
super(clusterId, workloadType, queryParams);
}
}
4 changes: 4 additions & 0 deletions cypress/e2e/po/prompts/promptRemove.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class PromptRemove extends ComponentPo {
return this.self().getId('prompt-remove-confirm-button').click();
}

cancel() {
return this.self().get('.btn.role-secondary').click();
}

// Get the warning message
warning() {
return this.self().get('[warning] .text-warning');
Expand Down
57 changes: 56 additions & 1 deletion cypress/e2e/tests/pages/explorer/workloads/pods.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WorkloadsPodsListPagePo, WorkLoadsPodDetailsPagePo } from '@/cypress/e2e/po/pages/explorer/workloads-pods.po';
import { WorkloadsPodsListPagePo, WorkLoadsPodDetailsPagePo, WorkloadsPodsCreatePagePo } from '@/cypress/e2e/po/pages/explorer/workloads-pods.po';
import { createPodBlueprint, clonePodBlueprint } from '@/cypress/e2e/blueprints/explorer/workload-pods';
import PodPo from '@/cypress/e2e/po/components/workloads/pod.po';
import PromptRemove from '@/cypress/e2e/po/prompts/promptRemove.po';
import HomePagePo from '@/cypress/e2e/po/pages/home.po';
import { generatePodsDataSmall } from '@/cypress/e2e/blueprints/explorer/workloads/pods/pods-get';

Expand Down Expand Up @@ -241,6 +242,60 @@ describe('Pods', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, ()
});
});

describe('should delete pod', () => {
const podName = `test-pod-${ Date.now() }`;

beforeEach(() => {
workloadsPodPage.goTo();
});

it('dialog should open/close as expected', () => {
const podCreatePage = new WorkloadsPodsCreatePagePo('local');

podCreatePage.goTo();

podCreatePage.createWithUI(podName, 'nginx', 'default');

// Should be on the list view
const podsListPage = new WorkloadsPodsListPagePo('local');

// Filter the list to just show the newly created pod
podsListPage.list().resourceTable().sortableTable().filter(podName);
podsListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);

// Open action menu and delete for the first item
podsListPage.list().resourceTable().sortableTable().rowActionMenuOpen(podName)
.getMenuItem('Delete')
.click();

let dialog = new PromptRemove();

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

dialog.cancel();
dialog.checkNotExists();

podsListPage.list().resourceTable().sortableTable().checkRowCount(false, 1);

// Open action menu and delete for the first item
podsListPage.list().resourceTable().sortableTable().rowActionMenuOpen(podName)
.getMenuItem('Delete')
.click();

dialog = new PromptRemove();

dialog.checkExists();
dialog.checkVisible();
dialog.remove();
dialog.checkNotExists();

podsListPage.list().resourceTable().sortableTable().checkRowCount(true, 1, true);

podsListPage.list().resourceTable().sortableTable().resetFilter();
});
});

after(() => {
// delete namespace (this will also delete all pods in it)
cy.deleteRancherResource('v1', 'namespaces', nsName);
Expand Down
1 change: 1 addition & 0 deletions shell/components/PromptRemove.vue
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export default {
:value="toRemove"
:names="names"
:type="type"
:done-location="doneLocation"
@errors="e => error = e"
@done="done"
/>
Expand Down
22 changes: 15 additions & 7 deletions shell/promptRemove/pod.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export default {
type: {
type: String,
required: true
},
close: {
type: Function,
required: true
},
doneLocation: {
type: Object,
default: () => {}
}
},
Expand Down Expand Up @@ -69,23 +79,21 @@ export default {
methods: {
async remove(confirm) {
const parentComponent = this.$parent.$parent.$parent;
let goTo;
if (parentComponent.doneLocation) {
if (this.doneLocation) {
// doneLocation will recompute to undefined when delete request completes
goTo = { ...parentComponent.doneLocation };
goTo = { ...this.doneLocation };
}
try {
await Promise.all(this.value.map((resource) => this.removePod(resource)));
if ( goTo && !isEmpty(goTo) ) {
parentComponent.currentRouter.push(goTo);
this.value?.[0]?.currentRouter().push(goTo);
}
parentComponent.close();
this.close();
} catch (err) {
parentComponent.error = err;
this.$emit('errors', err);
confirm(false);
}
},
Expand Down

0 comments on commit 3e41a64

Please sign in to comment.