-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Oleksii Kurinnyi <[email protected]>
- Loading branch information
Showing
35 changed files
with
1,211 additions
and
652 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
packages/dashboard-frontend/src/components/DevfileViewer/__mocks__/index.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,30 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { Props } from '@/components/DevfileViewer'; | ||
|
||
export class DevfileViewer extends React.PureComponent<Props> { | ||
public render(): React.ReactNode { | ||
const { isActive, isExpanded, value } = this.props; | ||
|
||
return ( | ||
<div> | ||
Mock Devfile Viewer | ||
<span data-testid="devfile-viewer-is-active">{isActive.toString()}</span> | ||
<span data-testid="devfile-viewer-is-expanded">{isExpanded.toString()}</span> | ||
<span data-testid="devfile-viewer-value">{value}</span> | ||
</div> | ||
); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
packages/dashboard-frontend/src/components/EditorTools/__mocks__/index.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,28 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
// mock for the EditorTools component | ||
import React from 'react'; | ||
|
||
import { Props } from '@/components/EditorTools'; | ||
|
||
export default class EditorTools extends React.PureComponent<Props> { | ||
public render(): React.ReactNode { | ||
const { handleExpand } = this.props; | ||
return ( | ||
<div> | ||
Mock Editor Tools | ||
<button onClick={() => handleExpand(true)}>Expand Editor</button> | ||
</div> | ||
); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...d/src/pages/WorkspaceDetails/DevfileEditorTab/__tests__/__snapshots__/index.spec.tsx.snap
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,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DevfileEditorTab component snapshot 1`] = ` | ||
[ | ||
<br />, | ||
<div | ||
className="pf-c-content editorTab" | ||
> | ||
<div> | ||
Mock Editor Tools | ||
<button | ||
onClick={[Function]} | ||
> | ||
Expand Editor | ||
</button> | ||
</div> | ||
<div> | ||
Mock Devfile Viewer | ||
<span | ||
data-testid="devfile-viewer-is-active" | ||
> | ||
true | ||
</span> | ||
<span | ||
data-testid="devfile-viewer-is-expanded" | ||
> | ||
false | ||
</span> | ||
<span | ||
data-testid="devfile-viewer-value" | ||
> | ||
schemaVersion: 2.2.0 | ||
metadata: | ||
name: wksp | ||
namespace: '' | ||
components: [] | ||
</span> | ||
</div> | ||
</div>, | ||
] | ||
`; |
139 changes: 139 additions & 0 deletions
139
...s/dashboard-frontend/src/pages/WorkspaceDetails/DevfileEditorTab/__tests__/index.spec.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,139 @@ | ||
/* | ||
* Copyright (c) 2018-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
|
||
import userEvent from '@testing-library/user-event'; | ||
import { dump } from 'js-yaml'; | ||
import { cloneDeep } from 'lodash'; | ||
import React from 'react'; | ||
|
||
import { DevfileEditorTab, prepareDevfile } from '@/pages/WorkspaceDetails/DevfileEditorTab'; | ||
import getComponentRenderer, { screen } from '@/services/__mocks__/getComponentRenderer'; | ||
import devfileApi from '@/services/devfileApi'; | ||
import { constructWorkspace, Workspace } from '@/services/workspace-adapter'; | ||
import { | ||
DEVWORKSPACE_DEVFILE, | ||
DEVWORKSPACE_METADATA_ANNOTATION, | ||
} from '@/services/workspace-client/devworkspace/devWorkspaceClient'; | ||
import { DevWorkspaceBuilder } from '@/store/__mocks__/devWorkspaceBuilder'; | ||
|
||
jest.mock('@/components/EditorTools'); | ||
jest.mock('@/components/DevfileViewer'); | ||
|
||
const { createSnapshot, renderComponent } = getComponentRenderer(getComponent); | ||
|
||
describe('DevfileEditorTab', () => { | ||
let workspace: Workspace; | ||
|
||
beforeEach(() => { | ||
const devWorkspace = new DevWorkspaceBuilder().withName('wksp').build(); | ||
workspace = constructWorkspace(devWorkspace); | ||
}); | ||
|
||
describe('component', () => { | ||
test('snapshot', () => { | ||
const snapshot = createSnapshot(true, workspace); | ||
expect(snapshot.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
test('expanded state', () => { | ||
renderComponent(true, workspace); | ||
|
||
const buttonExpand = screen.getByRole('button', { name: 'Expand Editor' }); | ||
userEvent.click(buttonExpand); | ||
|
||
const isExpanded = screen.getByTestId('devfile-viewer-is-expanded'); | ||
expect(isExpanded).toHaveTextContent('true'); | ||
}); | ||
}); | ||
|
||
describe('prepareDevfile', () => { | ||
describe('devWorkspace with the DEVWORKSPACE_DEVFILE annotation', () => { | ||
test('devfile without DEVWORKSPACE_METADATA_ANNOTATION', () => { | ||
const expectedDevfile = { | ||
schemaVersion: '2.1.0', | ||
metadata: { | ||
name: 'wksp', | ||
namespace: 'user-che', | ||
tags: ['tag1', 'tag2'], | ||
}, | ||
} as devfileApi.Devfile; | ||
const devWorkspace = new DevWorkspaceBuilder() | ||
.withName('wksp') | ||
.withNamespace('user-che') | ||
.withMetadata({ | ||
annotations: { | ||
[DEVWORKSPACE_DEVFILE]: dump(expectedDevfile), | ||
}, | ||
}) | ||
.build(); | ||
const workspace = constructWorkspace(devWorkspace); | ||
|
||
const devfile = prepareDevfile(workspace); | ||
expect(devfile).toEqual(expectedDevfile); | ||
}); | ||
|
||
test('devfile with DEVWORKSPACE_METADATA_ANNOTATION', () => { | ||
const origDevfile = { | ||
schemaVersion: '2.1.0', | ||
metadata: { | ||
name: 'wksp', | ||
namespace: 'user-che', | ||
tags: ['tag1', 'tag2'], | ||
}, | ||
attributes: { | ||
[DEVWORKSPACE_METADATA_ANNOTATION]: dump({ url: 'devfile-source-location' }), | ||
}, | ||
} as devfileApi.Devfile; | ||
const devWorkspace = new DevWorkspaceBuilder() | ||
.withName('wksp') | ||
.withNamespace('user-che') | ||
.withMetadata({ | ||
annotations: { | ||
[DEVWORKSPACE_DEVFILE]: dump(origDevfile), | ||
}, | ||
}) | ||
.build(); | ||
const workspace = constructWorkspace(devWorkspace); | ||
|
||
const devfile = prepareDevfile(workspace); | ||
|
||
const expectedDevfile = cloneDeep(origDevfile); | ||
delete expectedDevfile.attributes; | ||
|
||
expect(devfile).toEqual(expectedDevfile); | ||
}); | ||
}); | ||
|
||
test('devWorkspace without DEVWORKSPACE_DEVFILE annotation', () => { | ||
const expectedDevfile = { | ||
schemaVersion: '2.2.0', | ||
metadata: { | ||
name: 'wksp', | ||
namespace: 'user-che', | ||
}, | ||
components: [], | ||
} as devfileApi.Devfile; | ||
const devWorkspace = new DevWorkspaceBuilder() | ||
.withName('wksp') | ||
.withNamespace('user-che') | ||
.build(); | ||
const workspace = constructWorkspace(devWorkspace); | ||
|
||
const devfile = prepareDevfile(workspace); | ||
expect(devfile).toEqual(expectedDevfile); | ||
}); | ||
}); | ||
}); | ||
|
||
function getComponent(isActive: boolean, workspace: Workspace) { | ||
return <DevfileEditorTab isActive={isActive} workspace={workspace} />; | ||
} |
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
28 changes: 0 additions & 28 deletions
28
...ages/dashboard-frontend/src/pages/WorkspaceDetails/DevworkspaceEditorTab/index.module.css
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.