Skip to content

Commit d52ef33

Browse files
author
Lingxi Chen
committed
added cypress test for wlm create
Signed-off-by: Lingxi Chen <[email protected]>
1 parent 7a4680d commit d52ef33

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

cypress/e2e/7_WLM_create.cy.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
describe('WLM Create Page', () => {
7+
const groupName = 'test_create_group_' + Date.now();
8+
9+
beforeEach(() => {
10+
cy.visit('/app/workload-management#/wlm-create');
11+
});
12+
13+
it('should render the create form layout', () => {
14+
// Confirm title and overview section exist
15+
cy.contains('h1', 'Create workload group').should('exist');
16+
cy.contains('h2', 'Overview').should('exist');
17+
18+
// Confirm presence of form field labels
19+
const labels = [
20+
'Name',
21+
'Description (Optional)',
22+
'Index wildcard',
23+
'Resiliency mode',
24+
'Reject queries when CPU usage exceeds',
25+
'Reject queries when memory usage exceeds'
26+
];
27+
28+
labels.forEach(label => {
29+
cy.contains('label', label).should('exist');
30+
});
31+
32+
// Confirm both radio options are visible
33+
cy.contains('label', 'Soft').should('exist');
34+
cy.contains('label', 'Enforced').should('exist');
35+
36+
// Confirm buttons exist
37+
cy.get('button').contains('Cancel').should('exist');
38+
cy.get('button').contains('Create workload group').should('exist');
39+
});
40+
41+
it('should validate CPU and memory input ranges using label', () => {
42+
cy.contains('label', 'Reject queries when CPU usage exceeds')
43+
.parentsUntil('.euiFormRow')
44+
.parent()
45+
.find('input[type="number"]')
46+
.as('cpuInput');
47+
48+
cy.get('@cpuInput').clear().type('150');
49+
cy.contains('Value must be between 0 and 100').should('exist');
50+
51+
cy.get('@cpuInput').clear().type('-10');
52+
cy.contains('Value must be between 0 and 100').should('exist');
53+
54+
cy.contains('label', 'Reject queries when memory usage exceeds')
55+
.parentsUntil('.euiFormRow')
56+
.parent()
57+
.find('input[type="number"]')
58+
.as('memInput');
59+
60+
cy.get('@memInput').clear().type('150');
61+
cy.contains('Value must be between 0 and 100').should('exist');
62+
63+
cy.get('@memInput').clear().type('-5');
64+
cy.contains('Value must be between 0 and 100').should('exist');
65+
});
66+
67+
it('should create workload group successfully with valid inputs', () => {
68+
const groupName = `test_group_${Date.now()}`;
69+
70+
// Fill in the "Name" input using label
71+
cy.contains('label', 'Name')
72+
.parentsUntil('.euiFormRow')
73+
.parent()
74+
.find('input[type="text"]')
75+
.type(groupName);
76+
77+
// Select "Soft" resiliency mode radio
78+
cy.contains('label', 'Soft').click();
79+
80+
// Fill in the CPU threshold
81+
cy.contains('label', 'Reject queries when CPU usage exceeds')
82+
.parentsUntil('.euiFormRow')
83+
.parent()
84+
.find('input[type="number"]')
85+
.first()
86+
.type('1');
87+
88+
// Fill in the Memory threshold
89+
cy.contains('label', 'Reject queries when memory usage exceeds')
90+
.parentsUntil('.euiFormRow')
91+
.parent()
92+
.find('input[type="number"]')
93+
.first()
94+
.type('1');
95+
96+
// Intercept request
97+
cy.intercept('PUT', '/api/_wlm/workload_group').as('createGroup');
98+
99+
// Submit form
100+
cy.get('button').contains('Create workload group').click();
101+
102+
// Confirm redirect and success toast
103+
cy.url().should('include', '/workloadManagement');
104+
cy.contains(groupName).should('exist');
105+
});
106+
});

0 commit comments

Comments
 (0)