Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

describe('WLM Main Page', () => {
beforeEach(() => {
cy.visit('/app/workload-management#/workloadManagement');
cy.get('.euiBasicTable .euiTableRow').should('have.length.greaterThan', 0);
});

it('should display the WLM page with the workload group table', () => {
cy.contains('Workload groups').should('be.visible');
cy.get('.euiBasicTable').should('exist');
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
});

it('should filter workload groups with the search bar', () => {
cy.get('.euiFieldSearch').type('DEFAULT_QUERY_GROUP');
cy.get('.euiTableRow').should('have.length.at.least', 1);
cy.get('.euiFieldSearch').clear();
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
});

it('should refresh stats on clicking the refresh button', () => {
return cy.get('.euiTableRow').then(() => {
cy.get('button').contains('Refresh').click();

cy.get('.euiTableRow', { timeout: 10000 }).should(($newRows) => {
expect($newRows.length).to.be.greaterThan(0);
});
});
});

it('should display the WLM main page with workload group table and summary stats', () => {
// Confirm table exists
cy.get('.euiBasicTable').should('be.visible');
cy.get('.euiTableRow').should('have.length.greaterThan', 0);

// Confirm stat cards exist
const titles = ['Total workload groups', 'Total groups exceeding limits'];

titles.forEach((title) => {
cy.contains(title).should('be.visible');
});
});

it('should filter workload groups by name in search', () => {
cy.get('.euiFieldSearch').type('DEFAULT_WORKLOAD_GROUP');
cy.get('.euiTableRow').should('contain.text', 'DEFAULT_WORKLOAD_GROUP');

cy.get('.euiFieldSearch').clear().type('nonexistent_group_12345');
cy.get('.euiTableRow').should('contain.text', 'No items found');
});

it('should route to workload group detail page when clicking a group name', () => {
cy.get('.euiTableRow')
.first()
.within(() => {
cy.get('a').first().click({ force: true });
});

cy.contains('Workload group name', { timeout: 10000 }).should('exist');
});

it('should route to the Create Workload Group page when clicking the Create button', () => {
// Click the "Create workload group" button
cy.contains('Create workload group').click();

// Confirm we are on the create page
cy.url().should('include', '/wlm-create');

// Validate that the form elements exist
cy.contains('Resiliency mode').should('be.visible');
cy.get('[data-testid="indexInput"]').should('exist');
cy.get('button').contains('+ Add another rule').should('exist');
cy.get('input[data-testid="cpu-threshold-input"]').should('exist');
cy.get('input[data-testid="memory-threshold-input"]').should('exist');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

describe('WLM Details Page', () => {
const groupName = `test_group_${Date.now()}`;

before(() => {
Cypress.env('groupName', groupName);

// Clean up existing non-default groups
cy.request({
method: 'GET',
url: '/api/_wlm/workload_group',
headers: { 'osd-xsrf': 'true' },
}).then((res) => {
const groups = res.body?.workload_groups ?? [];
groups.forEach((g) => {
if (g.name !== 'DEFAUL_WORKLOAD_GROUP') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be DEFAULT

cy.request({
method: 'DELETE',
url: `/api/_wlm/workload_group/${g.name}`,
headers: { 'osd-xsrf': 'true' },
failOnStatusCode: false,
});
}
});
});

cy.request({
method: 'PUT',
url: '/api/_wlm/workload_group',
headers: { 'osd-xsrf': 'true' },
body: {
name: groupName,
resiliency_mode: 'soft',
resource_limits: {
cpu: 0.01,
memory: 0.01,
},
},
});
});

beforeEach(() => {
cy.visit(`/app/workload-management#/wlm-details?name=${groupName}`);
// Wait until rows render
cy.get('.euiBasicTable .euiTableRow').should('have.length.greaterThan', 0);
});

it('should display workload group summary panel', () => {
cy.contains('Workload group name').should('exist');
cy.contains('Resiliency mode').should('exist');
cy.contains('CPU usage limit').should('exist');
cy.contains('Memory usage limit').should('exist');
cy.contains(groupName).should('exist');
});

it('should switch between tabs', () => {
// Switch to Settings tab
cy.get('[data-testid="wlm-tab-settings"]').click();
cy.contains('Workload group settings').should('exist');

// Switch to Resources tab
cy.get('[data-testid="wlm-tab-resources"]').click();
cy.contains('Node ID').should('exist');
});

it('should display node resource usage table', () => {
cy.contains('Node ID').should('exist');
cy.get('.euiTableRow').should('have.length.greaterThan', 0);
});

it('should show delete modal', () => {
cy.contains('Delete').click();
cy.contains('Delete workload group').should('exist');
});

it('should delete the workload group successfully', () => {
cy.contains('Delete').click(); // opens modal
cy.get('input[placeholder="delete"]').type('delete');
cy.get('.euiModalFooter button').contains('Delete').click();

// Confirm redirected back to WLM main page
cy.url().should('include', '/workloadManagement');

// Confirm toast appears
cy.contains(`Deleted workload group "${groupName}"`).should('exist');
});
});

describe('WLM Details – DEFAULT_WORKLOAD_GROUP', () => {
it('should disable settings tab for DEFAULT_WORKLOAD_GROUP', () => {
cy.visit('/app/workload-management#/wlm-details?name=DEFAULT_WORKLOAD_GROUP');
cy.get('[data-testid="wlm-tab-settings"]').click();
cy.contains('Settings are not available for the DEFAULT_WORKLOAD_GROUP').should('exist');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

describe('WLM Create Page', () => {
beforeEach(() => {
cy.visit('/app/workload-management#/wlm-create');
});

it('renders the full create form with required fields', () => {
cy.contains('h1', 'Create workload group').should('exist');
cy.contains('h2', 'Overview').should('exist');

// Form labels and fields
[
'Name',
'Description – Optional',
'Resiliency mode',
'Index wildcard',
'Reject queries when CPU usage exceeds',
'Reject queries when memory usage exceeds',
].forEach((label) => {
cy.contains(label).should('exist');
});

cy.contains('Soft').should('exist');
cy.contains('Enforced').should('exist');
cy.contains('+ Add another rule').should('exist');
cy.get('button').contains('Create workload group').should('exist');
});

it('shows validation errors for CPU and memory thresholds', () => {
cy.get('[data-testid="cpu-threshold-input"]').clear().type('150');
cy.contains('Value must be between 0 and 100').should('exist');

cy.get('[data-testid="cpu-threshold-input"]').clear().type('-10');
cy.contains('Value must be between 0 and 100').should('exist');

cy.get('[data-testid="memory-threshold-input"]').clear().type('101');
cy.contains('Value must be between 0 and 100').should('exist');

cy.get('[data-testid="memory-threshold-input"]').clear().type('-1');
cy.contains('Value must be between 0 and 100').should('exist');
});

it('creates a workload group successfully with valid inputs', () => {
const groupName = `wlm_test_${Date.now()}`;

cy.get('[data-testid="name-input"]').type(groupName);
cy.contains('Soft').click();
cy.get('[data-testid="indexInput"]').type('test-index');
cy.get('[data-testid="cpu-threshold-input"]').type('10');
cy.get('[data-testid="memory-threshold-input"]').type('20');

cy.intercept('PUT', '/api/_wlm/workload_group').as('createRequest');
cy.get('button').contains('Create workload group').click();

cy.url().should('include', '/workloadManagement');
cy.contains(groupName).should('exist');
});

it('adds and deletes a rule block', () => {
cy.contains('+ Add another rule').click();
cy.get('[data-testid="indexInput"]').should('have.length', 2);

cy.get('[aria-label="Delete rule"]').first().click();
cy.get('[data-testid="indexInput"]').should('have.length', 1);
});

it('navigates back to main page on Cancel', () => {
cy.get('button').contains('Cancel').click();
cy.url().should('include', '/workloadManagement');
});
});
3 changes: 3 additions & 0 deletions site/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ const plugins = {
'2_query_details.cy.js',
'3_configurations.cy.js',
'4_group_details.cy.js',
'6_WLM_main.cy.js',
'7_WLM_details.cy.js',
'8_WLM_create.cy.js',
],
},
},
Expand Down