forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba9cb6c
commit 04b21de
Showing
10 changed files
with
26,003 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Drawer from '../components/drawer/Drawer'; | ||
|
||
describe('Drawer', () => { | ||
it('should render Drawer', () => { | ||
render( | ||
<Drawer | ||
calmInstance={undefined} | ||
title={undefined} | ||
isConDescActive={true} | ||
isNodeDescActive={true} | ||
/> | ||
); | ||
expect(screen.getByText('No file selected')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render Drawer', () => { | ||
render( | ||
<Drawer | ||
calmInstance={undefined} | ||
title={undefined} | ||
isConDescActive={false} | ||
isNodeDescActive={false} | ||
/> | ||
); | ||
expect(screen.getByText('No file selected')).toBeInTheDocument(); | ||
expect(screen.getByRole('checkbox', { name: 'drawer-toggle' })).not.toBeChecked(); | ||
}); | ||
}); |
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,56 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import Navbar from '../components/navbar/Navbar'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('Navbar', () => { | ||
const handleUploadMock = vi.fn(); | ||
const toggleConnectionDescMock = vi.fn(); | ||
const toggleNodeDescMock = vi.fn(); | ||
|
||
const setup = () => { | ||
return render( | ||
<Navbar | ||
handleUpload={handleUploadMock} | ||
toggleConnectionDesc={toggleConnectionDescMock} | ||
toggleNodeDesc={toggleNodeDescMock} | ||
isGraphRendered={true} | ||
/> | ||
); | ||
}; | ||
|
||
it('should render Navbar', async () => { | ||
setup(); | ||
expect(screen.getByRole('checkbox', { name: 'connection-description' })).not.toBeChecked(); | ||
}); | ||
|
||
it('should call toggleConnectionDesc on checkbox click', async () => { | ||
const user = userEvent.setup(); | ||
setup(); | ||
const checkbox = screen.getByRole('checkbox', { name: 'connection-description' }); | ||
await user.click(checkbox); | ||
await waitFor(() => { | ||
expect(toggleConnectionDescMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
it('should call toggleNodeDesc on checkbox click', async () => { | ||
const user = userEvent.setup(); | ||
setup(); | ||
const checkbox = screen.getByRole('checkbox', { name: 'node-description' }); | ||
await user.click(checkbox); | ||
await waitFor(() => { | ||
expect(toggleNodeDescMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
it('should call handleUpload on file input change', async () => { | ||
const user = userEvent.setup(); | ||
setup(); | ||
const file = new File(['example content'], 'example.txt', { type: 'text/plain' }); | ||
const input = screen.getByLabelText('Architecture'); | ||
await user.upload(input, file); | ||
await waitFor(() => { | ||
expect(handleUploadMock).toHaveBeenCalledWith(file); | ||
}); | ||
}); | ||
}); |
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,49 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import Sidebar from '../components/sidebar/Sidebar'; | ||
import { Node, Edge } from '../components/cytoscape-renderer/CytoscapeRenderer'; | ||
|
||
describe('Sidebar Component', () => { | ||
const mockCloseSidebar = vi.fn(); | ||
|
||
const mockNodeData: Node['data'] = { | ||
id: 'node-1', | ||
label: 'Node 1', | ||
type: 'type-1', | ||
description: 'Mock Node', | ||
}; | ||
|
||
const mockEdgeData: Edge['data'] = { | ||
id: 'edge-1', | ||
label: 'Edge 1', | ||
source: 'node-1', | ||
target: 'node-2', | ||
}; | ||
|
||
it('should render node details correctly', () => { | ||
render(<Sidebar selectedData={mockNodeData} closeSidebar={mockCloseSidebar} />); | ||
|
||
expect(screen.getByText('Node Details')).toBeInTheDocument(); | ||
expect(screen.getByText('unique-id: node-1')).toBeInTheDocument(); | ||
expect(screen.getByText('name: Node 1')).toBeInTheDocument(); | ||
expect(screen.getByText('node-type: type-1')).toBeInTheDocument(); | ||
expect(screen.getByText('description: Mock Node')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render edge details correctly', () => { | ||
render(<Sidebar selectedData={mockEdgeData} closeSidebar={mockCloseSidebar} />); | ||
|
||
expect(screen.getByText('Edge Details')).toBeInTheDocument(); | ||
expect(screen.getByText('unique-id: edge-1')).toBeInTheDocument(); | ||
expect(screen.getByText('description: Edge 1')).toBeInTheDocument(); | ||
expect(screen.getByText('source: node-1')).toBeInTheDocument(); | ||
expect(screen.getByText('target: node-2')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call closeSidebar when close button is clicked', () => { | ||
render(<Sidebar selectedData={mockNodeData} closeSidebar={mockCloseSidebar} />); | ||
|
||
fireEvent.click(screen.getByRole('button', { name: 'close-sidebar' })); | ||
expect(mockCloseSidebar).toHaveBeenCalled(); | ||
}); | ||
}); |
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,8 @@ | ||
import '@testing-library/jest-dom/vitest'; | ||
import { afterEach } from 'vitest'; | ||
import { cleanup } from '@testing-library/react'; | ||
|
||
// runs a clean after each test case (e.g. clearing jsdom) | ||
afterEach(() => { | ||
cleanup(); | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
environmentMatchGlobs: [['./src/**/*.tsx', 'jsdom']], | ||
setupFiles: ['./src/tests/vitest.setup.ts'], | ||
}, | ||
}); |
Oops, something went wrong.