-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge notebooks-v2 into kind_logo_modification/#148 branch
Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>
- Loading branch information
Liav Weiss (EXT-Nokia)
committed
Jan 14, 2025
1 parent
d84621a
commit 1869d2d
Showing
11 changed files
with
276 additions
and
8 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
workspaces/frontend/src/__tests__/cypress/cypress/tests/e2e/workspacekind.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { mockWorkspacekindsValid, mockWorkspacekindsInValid } from '../mocked/workspacekinds.mock'; | ||
|
||
describe('Test buildKindLogoDictionary Functionality', () => { | ||
// Mock valid workspace kinds | ||
context('With Valid Data', () => { | ||
before(() => { | ||
// Mock the API response | ||
cy.intercept('GET', '/api/v1/workspacekinds', { | ||
statusCode: 200, | ||
body: mockWorkspacekindsValid, | ||
}); | ||
|
||
// Visit the page | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should fetch and populate kind logos', () => { | ||
// Check that the logos are rendered in the table | ||
cy.get('tbody tr').each(($row) => { | ||
cy.wrap($row).find('td[data-label="Kind"]').within(() => { | ||
cy.get('img') | ||
.should('exist') | ||
.then(($img) => { | ||
// Ensure the image is fully loaded | ||
cy.wrap($img[0]).should('have.prop', 'complete', true); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Mock invalid workspace kinds | ||
context('With Invalid Data', () => { | ||
before(() => { | ||
// Mock the API response for invalid workspace kinds | ||
cy.intercept('GET', '/api/v1/workspacekinds', { | ||
statusCode: 200, | ||
body: mockWorkspacekindsInValid, | ||
}); | ||
|
||
// Visit the page | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should fallback when logo URL is invalid', () => { | ||
const workspaceKinds = mockWorkspacekindsInValid.data; // Access mock data | ||
|
||
cy.get('tbody tr').each(($row, index) => { | ||
cy.wrap($row).find('td[data-label="Kind"]').within(() => { | ||
cy.get('img') | ||
.should('exist') | ||
.then(($img) => { | ||
// If the image src is invalid, it should not load | ||
expect($img[0].naturalWidth).to.equal(0); // If the image is invalid, naturalWidth should be 0 | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
76 changes: 76 additions & 0 deletions
76
workspaces/frontend/src/__tests__/cypress/cypress/tests/mocked/workspacekinds.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { WorkspaceKind } from '~/shared/types'; | ||
|
||
// Factory function to create a valid WorkspaceKind | ||
function createMockWorkspaceKind(overrides: Partial<WorkspaceKind> = {}): WorkspaceKind { | ||
return { | ||
name: 'jupyter-lab', | ||
displayName: 'JupyterLab Notebook', | ||
description: 'A Workspace which runs JupyterLab in a Pod', | ||
deprecated: false, | ||
deprecationMessage: '', | ||
hidden: false, | ||
icon: { | ||
url: 'https://jupyter.org/assets/favicons/apple-touch-icon-152x152.png', | ||
}, | ||
logo: { | ||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/38/Jupyter_logo.svg', | ||
}, | ||
podTemplate: { | ||
podMetadata: { | ||
labels: { myWorkspaceKindLabel: 'my-value' }, | ||
annotations: { myWorkspaceKindAnnotation: 'my-value' }, | ||
}, | ||
volumeMounts: { home: '/home/jovyan' }, | ||
options: { | ||
imageConfig: { | ||
default: 'jupyterlab_scipy_190', | ||
values: [ | ||
{ | ||
id: 'jupyterlab_scipy_180', | ||
displayName: 'jupyter-scipy:v1.8.0', | ||
labels: { pythonVersion: '3.11' }, | ||
hidden: true, | ||
redirect: { | ||
to: 'jupyterlab_scipy_190', | ||
message: { | ||
text: 'This update will change...', | ||
level: 'Info', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
podConfig: { | ||
default: 'tiny_cpu', | ||
values: [ | ||
{ | ||
id: 'tiny_cpu', | ||
displayName: 'Tiny CPU', | ||
description: 'Pod with 0.1 CPU, 128 Mb RAM', | ||
labels: { cpu: '100m', memory: '128Mi' }, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
...overrides, // Allows customization | ||
}; | ||
} | ||
|
||
// Generate valid mock data with "data" property | ||
export const mockWorkspacekindsValid = { | ||
data: [ | ||
createMockWorkspaceKind(), | ||
], | ||
}; | ||
|
||
// Generate invalid mock data with "data" property | ||
export const mockWorkspacekindsInValid = { | ||
data: [ | ||
createMockWorkspaceKind({ | ||
logo: { | ||
url: 'https://invalid-url.example.com/invalid-logo.svg', // Broken URL | ||
}, | ||
}), | ||
], | ||
}; |
20 changes: 20 additions & 0 deletions
20
workspaces/frontend/src/app/actions/WorkspacekindsActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { WorkspaceKind } from '~/shared/types'; | ||
|
||
type KindLogoDict = Record<string, string>; | ||
|
||
/** | ||
* Builds a dictionary of kind names to logos, and returns it. | ||
* @param {WorkspaceKind[]} workspaceKinds - The list of workspace kinds. | ||
* @returns {KindLogoDict} A dictionary with kind names as keys and logo URLs as values. | ||
*/ | ||
export function buildKindLogoDictionary(workspaceKinds: WorkspaceKind[] | []): KindLogoDict { | ||
const kindLogoDict: KindLogoDict = {}; | ||
|
||
for (const workspaceKind of workspaceKinds) { | ||
kindLogoDict[workspaceKind.name] = workspaceKind.logo.url; | ||
} | ||
|
||
return kindLogoDict; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
} from '~/shared/utilities/useFetchState'; | ||
import { WorkspaceKind } from '~/shared/types'; | ||
import { useNotebookAPI } from '~/app/hooks/useNotebookAPI'; | ||
|
||
const useWorkspacekinds = (): FetchState<WorkspaceKind[]> => { | ||
const { api, apiAvailable } = useNotebookAPI(); | ||
const call = React.useCallback<FetchStateCallbackPromise<WorkspaceKind[]>>( | ||
(opts) => { | ||
if (!apiAvailable) { | ||
return Promise.reject(new Error('API not yet available')); | ||
} | ||
return api.getWorkspacekinds(opts); | ||
}, | ||
[api, apiAvailable], | ||
); | ||
|
||
return useFetchState(call, []); | ||
}; | ||
|
||
export default useWorkspacekinds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters