-
Notifications
You must be signed in to change notification settings - Fork 0
test: extra frontend/unit tests #239
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4d7838c
test: extra frontend/unit tests
HardMax71 7e49b16
fix: quicker frontend/unit + consistency in imports (all use aliases …
HardMax71 b3ff7e8
fix: quicker frontend/unit + consistency in imports (all use aliases …
HardMax71 53b8e97
fix: extracted common objs to test utils
HardMax71 1052288
fix: extra unit tests
HardMax71 741b599
fix: extra unit tests
HardMax71 c59afbc
fix: detected issues
HardMax71 bcd655e
fix: detected issues
HardMax71 bc82be3
fix: detected issues
HardMax71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,72 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { render } from '@testing-library/svelte'; | ||
| import EventTypeIcon from '$components/EventTypeIcon.svelte'; | ||
|
|
||
| describe('EventTypeIcon', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('known event types', () => { | ||
| it.each([ | ||
| 'execution.requested', | ||
| 'execution_requested', | ||
| 'execution.started', | ||
| 'execution_started', | ||
| 'execution.completed', | ||
| 'execution_completed', | ||
| 'execution.failed', | ||
| 'execution_failed', | ||
| 'execution.timeout', | ||
| 'execution_timeout', | ||
| 'pod.created', | ||
| 'pod_created', | ||
| 'pod.running', | ||
| 'pod_running', | ||
| 'pod.succeeded', | ||
| 'pod_succeeded', | ||
| 'pod.failed', | ||
| 'pod_failed', | ||
| 'pod.terminated', | ||
| 'pod_terminated', | ||
| ])('renders SVG for "%s"', (eventType) => { | ||
| const { container } = render(EventTypeIcon, { props: { eventType } }); | ||
| const svg = container.querySelector('svg'); | ||
| expect(svg).toBeInTheDocument(); | ||
| expect(svg?.classList.contains('lucide-help-circle')).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('unknown event type', () => { | ||
| it('renders fallback icon for unknown type', () => { | ||
| const { container } = render(EventTypeIcon, { props: { eventType: 'unknown.event' } }); | ||
| expect(container.querySelector('svg')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders a different icon than known types', () => { | ||
| const { container: unknownContainer } = render(EventTypeIcon, { | ||
| props: { eventType: 'unknown.event' }, | ||
| }); | ||
| const { container: knownContainer } = render(EventTypeIcon, { | ||
| props: { eventType: 'execution.started' }, | ||
| }); | ||
| expect(unknownContainer.querySelector('svg')?.innerHTML).not.toBe( | ||
| knownContainer.querySelector('svg')?.innerHTML | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('size prop', () => { | ||
| it.each([ | ||
| { size: undefined, expected: '20', desc: 'defaults to 20' }, | ||
| { size: 32, expected: '32', desc: 'passes custom size' }, | ||
| ])('$desc', ({ size, expected }) => { | ||
| const { container } = render(EventTypeIcon, { | ||
| props: { eventType: 'execution.started', ...(size ? { size } : {}) }, | ||
| }); | ||
| const svg = container.querySelector('svg'); | ||
| expect(svg).toHaveAttribute('width', expected); | ||
| expect(svg).toHaveAttribute('height', expected); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,96 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { render, screen, fireEvent } from '@testing-library/svelte'; | ||
| import { user } from '$test/test-utils'; | ||
| import ModalWrapper from './ModalWrapper.svelte'; | ||
|
|
||
| describe('Modal', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
HardMax71 marked this conversation as resolved.
|
||
|
|
||
| describe('open/closed', () => { | ||
| it.each([ | ||
| { open: true, visible: true }, | ||
| { open: false, visible: false }, | ||
| ])('content visible=$visible when open=$open', ({ open, visible }) => { | ||
| render(ModalWrapper, { props: { open } }); | ||
| if (visible) { | ||
| expect(screen.getByTestId('modal-body')).toBeInTheDocument(); | ||
| } else { | ||
| expect(screen.queryByTestId('modal-body')).not.toBeInTheDocument(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('accessibility', () => { | ||
| it('has correct dialog a11y attributes', () => { | ||
| render(ModalWrapper, { props: { open: true } }); | ||
| const dialog = screen.getByRole('dialog'); | ||
| expect(dialog).toHaveAttribute('aria-modal', 'true'); | ||
| expect(dialog).toHaveAttribute('aria-labelledby', 'modal-title'); | ||
| expect(screen.getByText('Test Modal')).toHaveAttribute('id', 'modal-title'); | ||
| expect(screen.getByRole('button', { name: 'Close modal' })).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('close interactions', () => { | ||
| it('fires onClose when X button clicked', async () => { | ||
| const onClose = vi.fn(); | ||
| render(ModalWrapper, { props: { open: true, onClose } }); | ||
| await user.click(screen.getByRole('button', { name: 'Close modal' })); | ||
| expect(onClose).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it('fires onClose on Escape keydown', async () => { | ||
| const onClose = vi.fn(); | ||
| render(ModalWrapper, { props: { open: true, onClose } }); | ||
| await fireEvent.keyDown(window, { key: 'Escape' }); | ||
| expect(onClose).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('fires onClose on backdrop click', async () => { | ||
| const onClose = vi.fn(); | ||
| render(ModalWrapper, { props: { open: true, onClose } }); | ||
| await fireEvent.click(screen.getByRole('dialog')); | ||
| expect(onClose).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it('does not fire onClose when clicking body content', async () => { | ||
| const onClose = vi.fn(); | ||
| render(ModalWrapper, { props: { open: true, onClose } }); | ||
| await user.click(screen.getByTestId('modal-body')); | ||
| expect(onClose).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('size classes', () => { | ||
| it.each([ | ||
| { size: 'sm' as const, expectedClass: 'max-w-md' }, | ||
| { size: 'md' as const, expectedClass: 'max-w-2xl' }, | ||
| { size: 'lg' as const, expectedClass: 'max-w-4xl' }, | ||
| { size: 'xl' as const, expectedClass: 'max-w-6xl' }, | ||
| ])('applies $expectedClass for size=$size', ({ size, expectedClass }) => { | ||
| const { container } = render(ModalWrapper, { props: { open: true, size } }); | ||
| expect(container.querySelector('.modal-container')?.classList.contains(expectedClass)).toBe(true); | ||
| }); | ||
|
|
||
| it('defaults to lg (max-w-4xl)', () => { | ||
| const { container } = render(ModalWrapper, { props: { open: true } }); | ||
| expect(container.querySelector('.modal-container')?.classList.contains('max-w-4xl')).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('footer', () => { | ||
| it.each([ | ||
| { showFooter: true, hasFooter: true }, | ||
| { showFooter: false, hasFooter: false }, | ||
| ])('footer present=$hasFooter when showFooter=$showFooter', ({ showFooter, hasFooter }) => { | ||
| const { container } = render(ModalWrapper, { props: { open: true, showFooter } }); | ||
| if (hasFooter) { | ||
| expect(screen.getByTestId('modal-footer-content')).toBeInTheDocument(); | ||
| } else { | ||
| expect(container.querySelector('.modal-footer')).not.toBeInTheDocument(); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,32 @@ | ||
| <script lang="ts"> | ||
| import Modal from '$components/Modal.svelte'; | ||
|
|
||
| interface Props { | ||
| open?: boolean; | ||
| title?: string; | ||
| onClose?: () => void; | ||
| size?: 'sm' | 'md' | 'lg' | 'xl'; | ||
| showFooter?: boolean; | ||
| } | ||
|
|
||
| let { | ||
| open = false, | ||
| title = 'Test Modal', | ||
| onClose = () => {}, | ||
| size, | ||
| showFooter = false, | ||
| }: Props = $props(); | ||
| </script> | ||
|
|
||
| {#if showFooter} | ||
| <Modal {open} {title} {onClose} {size}> | ||
| <p data-testid="modal-body">Modal body content</p> | ||
| {#snippet footer()} | ||
| <div data-testid="modal-footer-content">Footer content</div> | ||
| {/snippet} | ||
| </Modal> | ||
| {:else} | ||
| <Modal {open} {title} {onClose} {size}> | ||
| <p data-testid="modal-body">Modal body content</p> | ||
| </Modal> | ||
| {/if} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.