forked from bcgov/supreme-court-viewer
-
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.
Merge pull request #124 from bcgov/user-profile-dark-mode
Jasper 176: User Profile Settings/Dark Mode
- Loading branch information
Showing
8 changed files
with
188 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,45 @@ | ||
<template> | ||
<v-navigation-drawer location="right" temporary> | ||
<v-list-item subtitle="JSmith" color="primary" rounded="shaped"> | ||
<template v-slot:prepend> | ||
<v-icon :icon="mdiAccountCircle" size="45" /> | ||
</template> | ||
<v-list-item-title>John Smith</v-list-item-title> | ||
<template v-slot:append> | ||
<v-btn :icon="mdiCloseCircle" @click="$emit('close')" /> | ||
</template> | ||
</v-list-item> | ||
|
||
<v-divider></v-divider> | ||
|
||
<v-list-item color="primary" rounded="shaped"> | ||
<template v-slot:prepend> | ||
<v-icon :icon="mdiWeatherNight"></v-icon> | ||
</template> | ||
<v-list-item-title>Dark mode</v-list-item-title> | ||
<template v-slot:append> | ||
<v-switch v-model="isDark" hide-details @click="toggleDark" /> | ||
</template> | ||
</v-list-item> | ||
</v-navigation-drawer> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useThemeStore } from '@/stores/ThemeStore'; | ||
import { mdiAccountCircle, mdiCloseCircle, mdiWeatherNight } from '@mdi/js'; | ||
import { ref } from 'vue'; | ||
const themeStore = useThemeStore(); | ||
const theme = ref(themeStore.state); | ||
const isDark = ref(theme.value === 'dark'); | ||
function toggleDark() { | ||
themeStore.changeState(theme.value === 'dark' ? 'light' : 'dark'); | ||
} | ||
</script> | ||
|
||
<style> | ||
div.v-list-item__spacer { | ||
width: 15px !important; | ||
} | ||
</style> |
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,14 @@ | ||
import { ref } from 'vue'; | ||
|
||
// We want the default experience to be light mode | ||
const theme = localStorage.getItem('theme') ?? 'light'; | ||
const state = ref(theme); | ||
|
||
const changeState = (newTheme: string) => { | ||
localStorage.setItem('theme', newTheme); | ||
state.value = newTheme; | ||
}; | ||
|
||
export const useThemeStore = () => { | ||
return { state, changeState }; | ||
}; |
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,39 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { describe, it, expect, beforeEach, vi } from 'vitest'; | ||
import ProfileOffCanvas from 'CMP/shared/ProfileOffCanvas.vue'; | ||
|
||
vi.mock('SRC/stores/ThemeStore', () => ({ | ||
useThemeStore: () => ({ | ||
theme: 'light', | ||
setTheme: vi.fn(), | ||
changeState: vi.fn(), | ||
}), | ||
})); | ||
|
||
describe('ProfileOffCanvas.vue', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(ProfileOffCanvas); | ||
}); | ||
|
||
it('renders the component', () => { | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
// Unable to dive deeper into slotted append/prepend components | ||
// todo: find a way to test the slotted components | ||
// it('calls close when close button clicked', async () => { | ||
// await wrapper.find('v-button').trigger('click'); | ||
|
||
// expect(wrapper.emitted()).toHaveProperty('close'); | ||
// }); | ||
|
||
// it('calls set theme to dark when toggle button is clicked', async () => { | ||
// await wrapper.find('v-switch').trigger('click'); | ||
|
||
// expect(themeStore.changeState).toHaveBeenCalledWith('dark'); | ||
// }); | ||
}); | ||
|
||
|
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, it, expect, beforeEach, afterEach } from 'vitest'; | ||
import { useThemeStore } from '@/stores/ThemeStore'; | ||
|
||
describe('ThemeStore', () => { | ||
let themeStore: ReturnType<typeof useThemeStore>; | ||
|
||
beforeEach(() => { | ||
themeStore = useThemeStore(); | ||
}); | ||
|
||
afterEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
it('should initialize with light theme by default', () => { | ||
expect(themeStore.state.value).toBe('light'); | ||
}); | ||
|
||
it('should change theme and update localStorage', () => { | ||
themeStore.changeState('dark'); | ||
expect(themeStore.state.value).toBe('dark'); | ||
expect(localStorage.getItem('theme')).toBe('dark'); | ||
}); | ||
|
||
it('should persist theme from localStorage', () => { | ||
localStorage.setItem('theme', 'dark'); | ||
themeStore = useThemeStore(); | ||
expect(themeStore.state.value).toBe('dark'); | ||
}); | ||
}); |
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