Skip to content

Commit 5feeff6

Browse files
author
Yehudit Kerido
committed
Fix after rebase
Signed-off-by: Yehudit Kerido <[email protected]>
1 parent 0a3fbe9 commit 5feeff6

File tree

5 files changed

+198
-160
lines changed

5 files changed

+198
-160
lines changed

workspaces/frontend/src/__tests__/cypress/cypress/tests/e2e/Workspaces.cy.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
1-
import { WorkspaceState } from '~/shared/types';
21
import { home } from '~/__tests__/cypress/cypress/pages/home';
32
import {
43
mockWorkspaces,
54
mockWorkspacesByNS,
65
} from '~/__tests__/cypress/cypress/tests/mocked/workspace.mock';
6+
import type { Workspace } from '~/shared/types';
77
import { mockNamespaces } from '~/__mocks__/mockNamespaces';
88
import { mockBFFResponse } from '~/__mocks__/utils';
99

1010
// Helper function to validate the content of a single workspace row in the table
11-
const validateWorkspaceRow = (workspace: any, index: number) => {
11+
const validateWorkspaceRow = (workspace: Workspace, index: number) => {
1212
// Validate the workspace name
1313
cy.findByTestId(`workspace-row-${index}`)
1414
.find('[data-testid="workspace-name"]')
1515
.should('have.text', workspace.name);
1616

17-
// Map workspace state to the expected label
18-
const expectedLabel = WorkspaceState[workspace.status.state];
19-
20-
// Validate the state label and pod configuration
21-
cy.findByTestId(`workspace-row-${index}`)
22-
.find('[data-testid="state-label"]')
23-
.should('have.text', expectedLabel);
24-
2517
cy.findByTestId(`workspace-row-${index}`)
2618
.find('[data-testid="pod-config"]')
27-
.should('have.text', workspace.options.podConfig);
19+
.should('have.text', workspace.pod_template.pod_config.current);
2820
};
2921

3022
// Test suite for workspace-related tests
3123
describe('Workspaces tests', () => {
3224
beforeEach(() => {
3325
home.visit();
26+
27+
cy.intercept('GET', '/api/v1/namespaces', {
28+
body: mockBFFResponse(mockNamespaces),
29+
}).as('getNamespaces');
30+
3431
cy.intercept('GET', '/api/v1/workspaces', {
3532
body: mockBFFResponse(mockWorkspaces),
3633
}).as('getWorkspaces');
@@ -103,11 +100,18 @@ describe('Workspace by namespace functionality', () => {
103100
describe('Workspaces Component', () => {
104101
beforeEach(() => {
105102
// Mock the namespaces API response
103+
104+
cy.visit('/');
106105
cy.intercept('GET', '/api/v1/namespaces', {
107106
body: mockBFFResponse(mockNamespaces),
108107
}).as('getNamespaces');
109-
cy.visit('/');
110108
cy.wait('@getNamespaces');
109+
cy.intercept('GET', 'api/v1/workspaces', {
110+
body: mockBFFResponse(mockWorkspaces),
111+
}).as('getWorkspaces');
112+
cy.intercept('GET', 'api/v1/workspaces/kubeflow', {
113+
body: mockBFFResponse(mockWorkspacesByNS),
114+
});
111115
});
112116

113117
function openDeleteModal() {
@@ -122,6 +126,10 @@ describe('Workspaces Component', () => {
122126
() => cy.get('[aria-label="Close"]').click(),
123127
];
124128

129+
// Change namespace to "kubeflow"
130+
cy.findByTestId('namespace-toggle').click();
131+
cy.findByTestId('dropdown-item-kubeflow').click();
132+
125133
closeModalActions.forEach((closeAction) => {
126134
openDeleteModal();
127135
cy.findByTestId('delete-modal-input').type('Some Text');
@@ -138,6 +146,9 @@ describe('Workspaces Component', () => {
138146
});
139147

140148
it('should verify the delete modal verification mechanism', () => {
149+
// Change namespace to "kubeflow"
150+
cy.findByTestId('namespace-toggle').click();
151+
cy.findByTestId('dropdown-item-kubeflow').click();
141152
openDeleteModal();
142153
cy.findByTestId('delete-modal').within(() => {
143154
cy.get('strong')

workspaces/frontend/src/__tests__/cypress/cypress/tests/mocked/workspace.mock.ts

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Workspace } from '~/shared/types';
12
import { WorkspaceState } from '~/shared/types';
23

34
const generateMockWorkspace = (
@@ -8,60 +9,66 @@ const generateMockWorkspace = (
89
imageConfig: string,
910
podConfig: string,
1011
pvcName: string,
11-
) => {
12+
): Workspace => {
1213
const currentTime = Date.now();
13-
const lastActivity = currentTime - Math.floor(Math.random() * 1000000); // Random last activity time
14-
const lastUpdate = currentTime - Math.floor(Math.random() * 100000); // Random last update time
14+
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000); // Random last activity time
15+
const lastUpdateTime = currentTime - Math.floor(Math.random() * 100000); // Random last update time
1516

1617
return {
1718
name,
1819
namespace,
20+
workspace_kind: {
21+
name: 'jupyterlab',
22+
},
23+
defer_updates: paused,
1924
paused,
20-
deferUpdates: !!paused,
21-
kind: 'jupyter-lab',
22-
cpu: 3,
23-
ram: 500,
24-
podTemplate: {
25+
paused_time: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
26+
state,
27+
state_message:
28+
state === WorkspaceState.Running
29+
? 'Workspace is running smoothly.'
30+
: state === WorkspaceState.Paused
31+
? 'Workspace is paused.'
32+
: 'Workspace is operational.',
33+
pod_template: {
34+
pod_metadata: {
35+
labels: {},
36+
annotations: {},
37+
},
2538
volumes: {
26-
home: '/home',
39+
home: {
40+
pvc_name: `${pvcName}-home`,
41+
mount_path: '/home/jovyan',
42+
readOnly: false,
43+
},
2744
data: [
2845
{
29-
pvcName,
30-
mountPath: '/data',
31-
readOnly: paused, // Randomize based on paused state
46+
pvc_name: pvcName,
47+
mount_path: '/data/my-data',
48+
readOnly: paused, // Set based on the paused state
3249
},
3350
],
3451
},
35-
},
36-
options: {
37-
imageConfig,
38-
podConfig,
39-
},
40-
status: {
41-
activity: {
42-
lastActivity,
43-
lastUpdate,
52+
image_config: {
53+
current: imageConfig,
54+
desired: '',
55+
redirect_chain: [],
4456
},
45-
pauseTime: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
46-
pendingRestart: !!paused,
47-
podTemplateOptions: {
48-
imageConfig: {
49-
desired: imageConfig,
50-
redirectChain: [
51-
{
52-
source: 'base-image',
53-
target: `optimized-${Math.floor(Math.random() * 100)}`,
54-
},
55-
],
56-
},
57+
pod_config: {
58+
current: podConfig,
59+
desired: podConfig,
60+
redirect_chain: [],
61+
},
62+
},
63+
activity: {
64+
last_activity: lastActivityTime,
65+
last_update: lastUpdateTime,
66+
last_probe: {
67+
start_time_ms: lastUpdateTime - 1000, // Simulated probe timing
68+
end_time_ms: lastUpdateTime,
69+
result: 'default_result',
70+
message: 'default_message',
5771
},
58-
state,
59-
stateMessage:
60-
state === WorkspaceState.Running
61-
? 'Workspace is running smoothly.'
62-
: state === WorkspaceState.Paused
63-
? 'Workspace is paused.'
64-
: 'Workspace is operational.',
6572
},
6673
};
6774
};
@@ -74,7 +81,7 @@ const generateMockWorkspaces = (numWorkspaces: number, byNamespace = false) => {
7481
'jupyterlab_tensorflow_230',
7582
'jupyterlab_pytorch_120',
7683
];
77-
const namespaces = byNamespace ? ['kubeflow'] : ['kubeflow', 'system', 'user-example'];
84+
const namespaces = byNamespace ? ['kubeflow'] : ['kubeflow', 'system', 'user-example', 'default'];
7885

7986
for (let i = 1; i <= numWorkspaces; i++) {
8087
const state =

0 commit comments

Comments
 (0)