Skip to content

Commit

Permalink
fix: change the way the original devfile content is stored
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Feb 12, 2025
1 parent f2e8000 commit 39401da
Show file tree
Hide file tree
Showing 34 changed files with 190 additions and 1,033 deletions.
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

0 comments on commit 39401da

Please sign in to comment.