Skip to content

Commit

Permalink
vai pagination tests - pods
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonas Berhe authored and Yonas Berhe committed Jun 21, 2024
1 parent 7287cbb commit e1fe2bc
Show file tree
Hide file tree
Showing 10 changed files with 577 additions and 77 deletions.
233 changes: 233 additions & 0 deletions cypress/e2e/blueprints/explorer/workloads/pods/pods-get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
// GET /v1/pods - small set of pods data
const podsGetResponseSmallSet = {
type: 'collection',
links: { self: 'https://yonasb29.qa.rancher.space/v1/pods' },
createTypes: { pod: 'https://yonasb29.qa.rancher.space/v1/pods' },
actions: {},
resourceType: 'pod',
revision: '123',
count: 3,
data: [
{
id: 'cattle-fleet-local-system/fleet-agent-0',
type: 'pod',
links: {
remove: 'https://yonasb29.qa.rancher.space/v1/pods/cattle-fleet-local-system/fleet-agent-0',
self: 'https://yonasb29.qa.rancher.space/v1/pods/cattle-fleet-local-system/fleet-agent-0',
update: 'https://yonasb29.qa.rancher.space/v1/pods/cattle-fleet-local-system/fleet-agent-0',
view: 'https://yonasb29.qa.rancher.space/api/v1/namespaces/cattle-fleet-local-system/pods/fleet-agent-0'
},
apiVersion: 'v1',
kind: 'Pod',
metadata: {
annotations: {},
creationTimestamp: '2024-06-14T15:50:07Z',
fields: [
'fleet-agent-0',
'2/2',
'Running',
'0',
'7h29m',
'10.42.2.15',
'ip-172-31-12-33.us-east-2.compute.internal',
'<none>',
'<none>'
],
generateName: 'fleet-agent-',
labels: {},
name: 'aaa-e2e-vai-test-pod-name',
namespace: 'cattle-fleet-local-system',
ownerReferences: [],
relationships: [],
resourceVersion: '7553',
state: {
error: false,
message: '',
name: 'running',
transitioning: false
},
uid: '76de6052-8eda-42bc-98d5-dd19c335e977'
},
spec: {
affinity: {
nodeAffinity: {
preferredDuringSchedulingIgnoredDuringExecution: [
{
preference: {
matchExpressions: [
{
key: 'fleet.cattle.io/agent',
operator: 'In',
values: [
'true'
]
}
]
},
weight: 1
}
]
}
},
containers: [],
dnsPolicy: 'ClusterFirst',
enableServiceLinks: true,
hostname: 'fleet-agent-0',
initContainers: [],
nodeName: 'ip-172-31-12-33.us-east-2.compute.internal',
nodeSelector: { 'kubernetes.io/os': 'linux' },
preemptionPolicy: 'PreemptLowerPriority',
priority: 0,
restartPolicy: 'Always',
schedulerName: 'default-scheduler',
securityContext: {
runAsGroup: 1000,
runAsNonRoot: true,
runAsUser: 1000
},
serviceAccount: 'fleet-agent',
serviceAccountName: 'fleet-agent',
subdomain: 'fleet-agent',
terminationGracePeriodSeconds: 30,
tolerations: [],
volumes: []
},
status: {}
},
{
id: 'kube-system/rke2-snapshot-controller-59cc9cd8f4-dr2nv',
type: 'pod',
links: {
remove: 'https://yonasb29.qa.rancher.space/v1/pods/kube-system/rke2-snapshot-controller-59cc9cd8f4-dr2nv',
self: 'https://yonasb29.qa.rancher.space/v1/pods/kube-system/rke2-snapshot-controller-59cc9cd8f4-dr2nv',
update: 'https://yonasb29.qa.rancher.space/v1/pods/kube-system/rke2-snapshot-controller-59cc9cd8f4-dr2nv',
view: 'https://yonasb29.qa.rancher.space/api/v1/namespaces/kube-system/pods/rke2-snapshot-controller-59cc9cd8f4-dr2nv'
},
apiVersion: 'v1',
kind: 'Pod',
metadata: {
annotations: {
'cni.projectcalico.org/containerID': '212cd9f120c58c007d065f7702a2f3f6c7f2f8e8850af7ed14f56ef577c61615',
'cni.projectcalico.org/podIP': '10.42.0.11/32',
'cni.projectcalico.org/podIPs': '10.42.0.11/32'
},
creationTimestamp: '2024-06-14T15:39:59Z',
fields: [
'rke2-snapshot-controller-59cc9cd8f4-dr2nv',
'1/1',
'Running',
'0',
'7h39m',
'10.42.0.11',
'ip-172-31-14-130.us-east-2.compute.internal',
'<none>',
'<none>'
],
generateName: 'rke2-snapshot-controller-59cc9cd8f4-',
labels: {},
name: 'rke2-snapshot-controller-59cc9cd8f4-dr2nv',
namespace: 'kube-system',
ownerReferences: [],
relationships: [],
resourceVersion: '1176',
state: {
error: false,
message: '',
name: 'running',
transitioning: false
},
uid: 'a2157217-0b62-4d95-adcd-686f79925d4d'
},
spec: {
containers: [],
dnsPolicy: 'ClusterFirst',
enableServiceLinks: true,
nodeName: 'ip-172-31-14-130.us-east-2.compute.internal',
nodeSelector: { 'kubernetes.io/os': 'linux' },
preemptionPolicy: 'PreemptLowerPriority',
priority: 0,
restartPolicy: 'Always',
schedulerName: 'default-scheduler',
securityContext: {},
serviceAccount: 'rke2-snapshot-controller',
serviceAccountName: 'rke2-snapshot-controller',
terminationGracePeriodSeconds: 30,
tolerations: [],
volumes: []
},
status: {}
},
{
id: 'kube-system/rke2-snapshot-validation-webhook-54c5989b65-87xqh',
type: 'pod',
links: {
remove: 'https://yonasb29.qa.rancher.space/v1/pods/kube-system/rke2-snapshot-validation-webhook-54c5989b65-87xqh',
self: 'https://yonasb29.qa.rancher.space/v1/pods/kube-system/rke2-snapshot-validation-webhook-54c5989b65-87xqh',
update: 'https://yonasb29.qa.rancher.space/v1/pods/kube-system/rke2-snapshot-validation-webhook-54c5989b65-87xqh',
view: 'https://yonasb29.qa.rancher.space/api/v1/namespaces/kube-system/pods/rke2-snapshot-validation-webhook-54c5989b65-87xqh'
},
apiVersion: 'v1',
kind: 'Pod',
metadata: {
annotations: {},
creationTimestamp: '2024-06-14T15:39:52Z',
fields: [
'rke2-snapshot-validation-webhook-54c5989b65-87xqh',
'1/1',
'Running',
'0',
'7h39m',
'10.42.0.9',
'ip-172-31-14-130.us-east-2.compute.internal',
'<none>',
'<none>'
],
generateName: 'rke2-snapshot-validation-webhook-54c5989b65-',
labels: {},
name: 'rke2-snapshot-validation-webhook-54c5989b65-87xqh',
namespace: 'kube-system',
ownerReferences: [],
relationships: [],
resourceVersion: '1138',
state: {
error: false,
message: '',
name: 'running',
transitioning: false
},
uid: '929106df-13d9-43fc-9c76-09ad0292aab1'
},
spec: {
containers: [],
dnsPolicy: 'ClusterFirst',
enableServiceLinks: true,
nodeName: 'ip-172-31-14-130.us-east-2.compute.internal',
nodeSelector: { 'kubernetes.io/os': 'linux' },
preemptionPolicy: 'PreemptLowerPriority',
priority: 0,
restartPolicy: 'Always',
schedulerName: 'default-scheduler',
securityContext: {},
serviceAccount: 'rke2-snapshot-validation-webhook',
serviceAccountName: 'rke2-snapshot-validation-webhook',
terminationGracePeriodSeconds: 30,
tolerations: [],
volumes: []
},
status: {}
}
]
};

function reply(statusCode: number, body: any) {
return (req) => {
req.reply({
statusCode,
body
});
};
}

export function generatePodsDataSmall(): Cypress.Chainable<Response> {
return cy.intercept('GET', '/v1/pods?*', reply(200, podsGetResponseSmallSet)).as('podsDataSmall');
}
27 changes: 27 additions & 0 deletions cypress/e2e/po/components/header-row.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ComponentPo from '@/cypress/e2e/po/components/component.po';

export default class HeaderRowPo extends ComponentPo {
column(index: number) {
return this.self().find('th').eq(index);
}

get(selector: string, options?: any) {
return this.self().get(selector, options);
}

within(selector: string, options?: any) {
return this.self().within(() => {
this.get(selector, options);
});
}

/**
* check table header sort order
* @param index
* @param direction up or down (i.e. DESC or ASC)
*/
checkSortOrder(index: number, direction: string) {
this.column(index).find('.sort').find('.icon-stack > i').should('have.length', 2)
.and('have.class', `icon-sort-${ direction }`);
}
}
8 changes: 7 additions & 1 deletion cypress/e2e/po/components/sortable-table.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CheckboxInputPo from '@/cypress/e2e/po/components/checkbox-input.po';
import ListRowPo from '@/cypress/e2e/po/components/list-row.po';
import PromptRemove from '@/cypress/e2e/po/prompts/promptRemove.po';
import PaginationPo from '@/cypress/e2e/po/components/pagination.po';
import HeaderRowPo from '@/cypress/e2e/po/components/header-row.po';

export default class SortableTablePo extends ComponentPo {
//
Expand Down Expand Up @@ -98,7 +99,12 @@ export default class SortableTablePo extends ComponentPo {
}

tableHeaderRow() {
return this.self().find('thead tr');
return new HeaderRowPo(this.self());
}

// sort
sort(index: number) {
return this.tableHeaderRow().column(index).find('.sort');
}

subRows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@admi
events.sortableTable().rowElements().should('have.length.gte', 2);
});

describe('pagination', { tags: ['@vai'] }, () => {
describe('List', { tags: ['@vai'] }, () => {
const events = new EventsPagePo('local');
const eventName = 'aaa-e2e-vai-test-event-name';

before('set up', () => {
// set user preferences: update resource filter
Expand Down Expand Up @@ -322,9 +323,26 @@ describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@admi
events.sortableTable().pagination().leftButton().isDisabled();
});

it('sorting changes the order of paginated events data', () => {
const eventName = 'aaa-e2e-vai-test-event-name';
it('filter events', () => {
// generate large set of events data
generateEventsDataLarge();
ClusterDashboardPagePo.navTo();
clusterDashboard.waitForPage(undefined, 'cluster-events');
EventsPagePo.navTo();
cy.wait('@eventsDataLarge');
events.waitForPage();

events.sortableTable().checkVisible();
events.sortableTable().checkLoadingIndicatorNotVisible();
events.sortableTable().checkRowCount(false, 100);

// filter by name
events.sortableTable().filter(eventName);
events.sortableTable().checkRowCount(false, 1);
events.sortableTable().rowElementWithName(eventName).scrollIntoView().should('be.visible');
});

it('sorting changes the order of paginated events data', () => {
// generate large set of events data
generateEventsDataLarge();
ClusterDashboardPagePo.navTo();
Expand All @@ -333,14 +351,17 @@ describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@admi
events.waitForPage();
cy.wait('@eventsDataLarge');

// check table is sorted by `last seen` in ASC order by default
events.sortableTable().tableHeaderRow().checkSortOrder(2, 'down');

// sort by name in ASC order
events.sortableTable().tableHeaderRow().contains('Name').click();
events.sortableTable().sort(11).click();

// event name should be visible on first page (sorted in ASC order)
events.sortableTable().rowElementWithName(eventName).scrollIntoView().should('be.visible');

// sort by name in DESC order
events.sortableTable().tableHeaderRow().contains('Name').click();
events.sortableTable().sort(11).click();

// event name should be NOT visible on first page (sorted in DESC order)
events.sortableTable().rowElementWithName(eventName).should('not.exist');
Expand All @@ -367,6 +388,7 @@ describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@admi
events.sortableTable().pagination().checkNotExists();
});
});

it('can view events table empty if no events', { tags: ['@vai'] }, () => {
const events = new EventsPagePo('local');

Expand All @@ -382,7 +404,7 @@ describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@admi
const expectedHeaders = ['Reason', 'Object', 'Message', 'Name', 'Date'];

clusterDashboard.eventsList().resourceTable().sortableTable().tableHeaderRow()
.find('.table-header-container .content')
.within('.table-header-container .content')
.each((el, i) => {
expect(el.text().trim()).to.eq(expectedHeaders[i]);
});
Expand All @@ -397,7 +419,7 @@ describe('Cluster Dashboard', { testIsolation: 'off', tags: ['@explorer', '@admi
'Subobject', 'Source', 'Message', 'First Seen', 'Count', 'Name', 'Namespace'];

events.eventslist().resourceTable().sortableTable().tableHeaderRow()
.find('.table-header-container .content')
.within('.table-header-container .content')
.each((el, i) => {
expect(el.text().trim()).to.eq(expectedFullHeaders[i]);
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/tests/pages/explorer/namespace-picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('Namespace picker', { testIsolation: 'off' }, () => {
const projId = resp.body.id.trim();

// create ns
cy.createNamespace(nsName, projId);
cy.createNamespaceInProject(nsName, projId);

// check ns picker
namespacePicker.toggle();
Expand Down
Loading

0 comments on commit e1fe2bc

Please sign in to comment.