Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change the way the original devfile content is stored #1315

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .deps/EXCLUDED/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This file lists dependencies that do not need CQs or auto-detection does not wor

| Packages | Resolved CQs |
| --- | --- |
| `@devfile/[email protected]1733171449` | N/A |
| `@devfile/[email protected]1738342178` | N/A |
| `@fastify/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@fastify/cors/9.0.1) |
| `@fastify/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@fastify/swagger-ui/4.2.0) |
| `@hapi/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@hapi/hoek/10.0.1) |
Expand Down
4 changes: 2 additions & 2 deletions .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
| `[email protected]` | ISC | clearlydefined |
| `[email protected]` | ISC | clearlydefined |
| [`[email protected]`](https://github.com/fitzgen/glob-to-regexp.git) | BSD-2-Clause | clearlydefined |
| [`[email protected]`](git://github.com/isaacs/node-glob.git) | ISC | clearlydefined |
| [`[email protected]`](git://github.com/isaacs/node-glob.git) | ISC | #19366 |
| [`[email protected]`](https://github.com/jonschlinkert/global-modules) | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jonschlinkert/global-prefix) | MIT | clearlydefined |
| `[email protected]` | MIT | clearlydefined |
Expand Down Expand Up @@ -394,7 +394,7 @@
| [`[email protected]`](git+https://github.com/keyanzhang/identity-obj-proxy.git) | MIT | clearlydefined |
| [`[email protected]`](git+https://github.com/novemberborn/ignore-by-default.git) | ISC | clearlydefined |
| [`[email protected]`]([email protected]:kaelzhang/node-ignore.git) | MIT | #5907 |
| `[email protected]` | MIT | clearlydefined |
| `[email protected]` | MIT | #19299 |
| `[email protected]` | MIT | clearlydefined |
| `[email protected]` | MIT | clearlydefined |
| `[email protected]` | MIT | clearlydefined |
Expand Down
4 changes: 2 additions & 2 deletions .deps/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
| Packages | License | Resolved CQs |
| --- | --- | --- |
| [`@babel/[email protected]`](https://github.com/babel/babel.git) | MIT | #10718 |
| [`@devfile/[email protected]1733171449`](https://github.com/GIT_USER_ID/GIT_REPO_ID.git) | Apache-2.0 | N/A |
| [`@eclipse-che/che-devworkspace-generator@7.96.0-next-da9f364`](git+https://github.com/devfile/devworkspace-generator.git) | EPL-2.0 | ecd.che |
| [`@devfile/[email protected]1738342178`](https://github.com/GIT_USER_ID/GIT_REPO_ID.git) | Apache-2.0 | N/A |
| [`@eclipse-che/che-devworkspace-generator@7.99.0-next-1ccb963`](git+https://github.com/devfile/devworkspace-generator.git) | EPL-2.0 | ecd.che |
| [`@fastify/[email protected]`](git+https://github.com/fastify/accept-negotiator.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](git+https://github.com/fastify/ajv-compiler.git) | MIT | clearlydefined |
| [`@fastify/[email protected]`](https://github.com/fastify/busboy.git) | MIT | clearlydefined |
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:watch": "yarn test --watch"
},
"devDependencies": {
"@devfile/api": "2.3.0-1733171449",
"@devfile/api": "2.3.0-1738342178",
"@kubernetes/client-node": "^0.22.1",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^6.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/dashboard-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
],
"license": "EPL-2.0",
"dependencies": {
"@devfile/api": "2.3.0-1733171449",
"@eclipse-che/che-devworkspace-generator": "7.96.0-next-da9f364",
"@devfile/api": "2.3.0-1738342178",
"@eclipse-che/che-devworkspace-generator": "7.99.0-next-1ccb963",
"@fastify/cors": "^9.0.1",
"@fastify/error": "^3.4.1",
"@fastify/http-proxy": "^9.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"sanitize-html": "^2.11.0"
},
"devDependencies": {
"@devfile/api": "2.3.0-1733171449",
"@devfile/api": "2.3.0-1738342178",
"@eclipse-che/api": "^7.86.0",
"@kubernetes/client-node": "^0.22.1",
"@react-mock/state": "^0.1.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,140 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EditorTools DevWorkspace snapshot 1`] = `
<div
className="editorTools"
>
<div
className="pf-l-flex"
>
<div
className=""
>
<a
aria-disabled={false}
aria-label={null}
className="pf-c-button pf-m-link button"
data-ouia-component-id="OUIA-Generated-Button-link-4"
data-ouia-component-type="PF4/Button"
data-ouia-safe={true}
disabled={null}
href="https://console-url/k8s/ns/user-che/1.0.0~DevWorkspace/my-project"
role={null}
target="_blank"
type={null}
>
<span
className="pf-c-button__icon pf-m-start"
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="currentColor"
height="1em"
role="img"
style={
{
"verticalAlign": "-0.125em",
}
}
viewBox="0 0 448 512"
width="1em"
>
<path
d="M448 80v352c0 26.51-21.49 48-48 48H48c-26.51 0-48-21.49-48-48V80c0-26.51 21.49-48 48-48h352c26.51 0 48 21.49 48 48zm-88 16H248.029c-21.313 0-32.08 25.861-16.971 40.971l31.984 31.987L67.515 364.485c-4.686 4.686-4.686 12.284 0 16.971l31.029 31.029c4.687 4.686 12.285 4.686 16.971 0l195.526-195.526 31.988 31.991C358.058 263.977 384 253.425 384 231.979V120c0-13.255-10.745-24-24-24z"
/>
</svg>
</span>
Cluster console
</a>
</div>
<hr
className="pf-c-divider pf-m-vertical"
/>
<div
className=""
>
<button
onClick={[Function]}
>
Copy to clipboard
</button>
</div>
<hr
className="pf-c-divider pf-m-vertical"
/>
<div
className=""
>
<a
className="button"
download="my-project.workspace.yaml"
href="blob-url"
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="currentColor"
height="1em"
role="img"
style={
{
"verticalAlign": "-0.125em",
}
}
viewBox="0 0 512 512"
width="1em"
>
<path
d="M216 0h80c13.3 0 24 10.7 24 24v168h87.7c17.8 0 26.7 21.5 14.1 34.1L269.7 378.3c-7.5 7.5-19.8 7.5-27.3 0L90.1 226.1c-12.6-12.6-3.7-34.1 14.1-34.1H192V24c0-13.3 10.7-24 24-24zm296 376v112c0 13.3-10.7 24-24 24H24c-13.3 0-24-10.7-24-24V376c0-13.3 10.7-24 24-24h146.7l49 49c20.1 20.1 52.5 20.1 72.6 0l49-49H488c13.3 0 24 10.7 24 24zm-124 88c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20zm64 0c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20z"
/>
</svg>
Download
</a>
</div>
<hr
className="pf-c-divider pf-m-vertical"
/>
<div
className=""
>
<button
aria-disabled={false}
aria-label={null}
className="pf-c-button pf-m-link button"
data-ouia-component-id="OUIA-Generated-Button-link-5"
data-ouia-component-type="PF4/Button"
data-ouia-safe={true}
disabled={false}
onClick={[Function]}
role={null}
type="button"
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="currentColor"
height="1em"
role="img"
style={
{
"verticalAlign": "-0.125em",
}
}
viewBox="0 0 448 512"
width="1em"
>
<path
d="M0 180V56c0-13.3 10.7-24 24-24h124c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H64v84c0 6.6-5.4 12-12 12H12c-6.6 0-12-5.4-12-12zM288 44v40c0 6.6 5.4 12 12 12h84v84c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12V56c0-13.3-10.7-24-24-24H300c-6.6 0-12 5.4-12 12zm148 276h-40c-6.6 0-12 5.4-12 12v84h-84c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h124c13.3 0 24-10.7 24-24V332c0-6.6-5.4-12-12-12zM160 468v-40c0-6.6-5.4-12-12-12H64v-84c0-6.6-5.4-12-12-12H12c-6.6 0-12 5.4-12 12v124c0 13.3 10.7 24 24 24h124c6.6 0 12-5.4 12-12z"
/>
</svg>
Expand
</button>
</div>
</div>
</div>
`;

exports[`EditorTools Devfile snapshot 1`] = `
<div
className="editorTools"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
* Red Hat, Inc. - initial API and implementation
*/

import { ApplicationId } from '@eclipse-che/common';
import userEvent from '@testing-library/user-event';
import { dump } from 'js-yaml';
import React from 'react';
import { Provider } from 'react-redux';
import { Store } from 'redux';

import EditorTools from '@/components/EditorTools';
import getComponentRenderer, { screen } from '@/services/__mocks__/getComponentRenderer';
import devfileApi from '@/services/devfileApi';
import { MockStoreBuilder } from '@/store/__mocks__/mockStore';

import EditorTools from '..';
// mute console.error
console.error = jest.fn();

jest.mock('@/contexts/ToggleBars');

Expand Down Expand Up @@ -49,19 +50,8 @@ const mockOnExpand = jest.fn();
let store: Store;

describe('EditorTools', () => {
const clusterConsole = {
id: ApplicationId.CLUSTER_CONSOLE,
url: 'https://console-url',
icon: 'https://console-icon-url',
title: 'Cluster console',
};

beforeEach(() => {
store = new MockStoreBuilder()
.withClusterInfo({
applications: [clusterConsole],
})
.build();
store = new MockStoreBuilder().build();

jest.useFakeTimers();
});
Expand All @@ -72,26 +62,22 @@ describe('EditorTools', () => {
});

describe('Devfile', () => {
let devfile: devfileApi.Devfile;

beforeEach(() => {
devfile = {
schemaVersion: '2.1.0',
metadata: {
name: 'my-project',
namespace: 'user-che',
},
};
const name = 'my-project';
const devfileContent = dump({
schemaVersion: '2.1.0',
metadata: {
name,
},
});

test('snapshot', () => {
const snapshot = createSnapshot(devfile);
const snapshot = createSnapshot(devfileContent, name);
expect(snapshot.toJSON()).toMatchSnapshot();
});

test('expand and compress', async () => {
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
renderComponent(devfile);
renderComponent(devfileContent, name);

/* expand the editor */

Expand Down Expand Up @@ -120,7 +106,7 @@ describe('EditorTools', () => {
const mockCreateObjectURL = jest.fn().mockReturnValue('blob-url');
URL.createObjectURL = mockCreateObjectURL;

renderComponent(devfile);
renderComponent(devfileContent, name);

const copyButtonName = 'Copy to clipboard';
expect(screen.queryByRole('button', { name: copyButtonName })).toBeTruthy;
Expand All @@ -129,7 +115,7 @@ describe('EditorTools', () => {
await user.click(copyButton);

expect(mockClipboard).toHaveBeenCalledWith(
'schemaVersion: 2.1.0\nmetadata:\n name: my-project\n namespace: user-che\n',
'schemaVersion: 2.1.0\nmetadata:\n name: my-project\n',
);

/* 'Copy to clipboard' should be hidden for a while */
Expand All @@ -146,46 +132,16 @@ describe('EditorTools', () => {
expect(screen.queryByRole('button', { name: copyButtonNameAfter })).toBeFalsy;
});
});

describe('DevWorkspace', () => {
let devWorkspace: devfileApi.DevWorkspace;

beforeEach(() => {
devWorkspace = {
apiVersion: '1.0.0',
metadata: {
name: 'my-project',
namespace: 'user-che',
labels: {},
uid: '123',
},
kind: 'DevWorkspace',
spec: {
template: {},
started: true,
},
};
});

test('snapshot', () => {
const snapshot = createSnapshot(devWorkspace);
expect(snapshot.toJSON()).toMatchSnapshot();
});

test('Cluster Console', () => {
renderComponent(devWorkspace);

const clusterConsoleButton = screen.getByRole('link', { name: clusterConsole.title });

expect(clusterConsoleButton.textContent).toEqual(clusterConsole.title);
});
});
});

function getComponent(devfileOrDevWorkspace: devfileApi.Devfile | devfileApi.DevWorkspace) {
function getComponent(contentText: string, workspaceName: string) {
return (
<Provider store={store}>
<EditorTools devfileOrDevWorkspace={devfileOrDevWorkspace} handleExpand={mockOnExpand} />
<EditorTools
contentText={contentText}
workspaceName={workspaceName}
handleExpand={mockOnExpand}
/>
</Provider>
);
}
Loading
Loading