-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1204 from rainlanguage/1182-mobile-styling-for-al…
…l-pages Mobile styling for Sidebar
- Loading branch information
Showing
8 changed files
with
273 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<script lang="ts"> | ||
import { props } from './MockComponent'; | ||
// whenever the props update, we want to update the store with those | ||
$: $props = $$props; | ||
</script> |
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,3 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export const props = writable<unknown>(); |
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
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,111 @@ | ||
import { render, cleanup, screen, fireEvent, waitFor } from '@testing-library/svelte'; | ||
import { vi, describe, it, expect, afterEach } from 'vitest'; | ||
import Sidebar from '../lib/components/Sidebar.svelte'; | ||
import { writable } from 'svelte/store'; | ||
|
||
vi.mock('@rainlanguage/ui-components', async () => { | ||
const MockComponent = (await import('../lib/__mocks__/MockComponent.svelte')).default; | ||
return { | ||
ButtonDarkMode: MockComponent, | ||
logoLight: 'mock-logo-light.svg', | ||
logoDark: 'mock-logo-dark.svg', | ||
IconTelegram: MockComponent, | ||
IconExternalLink: MockComponent | ||
}; | ||
}); | ||
|
||
vi.mock('svelte/store', () => { | ||
return { | ||
writable: () => ({ | ||
subscribe: () => { | ||
return () => {}; | ||
}, | ||
set: vi.fn() | ||
}) | ||
}; | ||
}); | ||
|
||
const mockWindowSize = (width: number) => { | ||
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: width }); | ||
window.dispatchEvent(new Event('resize')); | ||
}; | ||
|
||
describe('Sidebar', () => { | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it('renders correctly with colorTheme store', async () => { | ||
const mockColorTheme = writable('light'); | ||
const mockPage = { | ||
url: { pathname: '/' } | ||
}; | ||
const { container } = render(Sidebar, { | ||
props: { | ||
colorTheme: mockColorTheme, | ||
page: mockPage | ||
} | ||
}); | ||
|
||
expect(container).toBeTruthy(); | ||
}); | ||
it('renders menu bars button when screen width is small', () => { | ||
// Mock small screen width | ||
mockWindowSize(500); | ||
const mockColorTheme = writable('light'); | ||
const mockPage = { | ||
url: { pathname: '/' } | ||
}; | ||
render(Sidebar, { colorTheme: mockColorTheme, page: mockPage }); | ||
|
||
const barsButton = screen.getByTestId('sidebar-bars'); | ||
expect(barsButton).toBeInTheDocument(); | ||
}); | ||
it('shows sidebar on wide screen', () => { | ||
mockWindowSize(1025); | ||
const mockColorTheme = writable('light'); | ||
const mockPage = { | ||
url: { pathname: '/' } | ||
}; | ||
render(Sidebar, { colorTheme: mockColorTheme, page: mockPage }); | ||
|
||
expect(screen.getByTestId('sidebar')).toBeInTheDocument(); | ||
}); | ||
it('renders sidebar when bars button is clicked', async () => { | ||
// Mock small screen width | ||
mockWindowSize(500); | ||
const mockColorTheme = writable('light'); | ||
const mockPage = { | ||
url: { pathname: '/' } | ||
}; | ||
render(Sidebar, { colorTheme: mockColorTheme, page: mockPage }); | ||
|
||
const barsButton = screen.getByTestId('sidebar-bars'); | ||
fireEvent.click(barsButton); | ||
|
||
await waitFor(() => { | ||
const sidebar = screen.getByTestId('sidebar'); | ||
expect(sidebar.hidden).toBe(false); | ||
}); | ||
}); | ||
it('hides sidebar when close button is clicked', async () => { | ||
mockWindowSize(500); | ||
const mockColorTheme = writable('light'); | ||
const mockPage = { | ||
url: { pathname: '/' } | ||
}; | ||
render(Sidebar, { colorTheme: mockColorTheme, page: mockPage }); | ||
|
||
const barsButton = screen.getByTestId('sidebar-bars'); | ||
await fireEvent.click(barsButton); | ||
await waitFor(() => { | ||
expect(screen.getByTestId('sidebar')).toBeInTheDocument(); | ||
}); | ||
const closeButton = screen.getByTestId('close-button'); | ||
await fireEvent.click(closeButton); | ||
await waitFor(() => { | ||
const sidebar = screen.getByTestId('sidebar'); | ||
expect(sidebar.hidden).toBe(true); | ||
}); | ||
}); | ||
}); |
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,7 @@ | ||
import '@testing-library/jest-dom/vitest'; | ||
import { vi } from 'vitest'; | ||
|
||
// Mock for codemirror-rainlang | ||
vi.mock('codemirror-rainlang', () => ({ | ||
RainlangLR: vi.fn() | ||
})); |
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
Oops, something went wrong.