Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ vuex 설치 및 적용 - App에 연결 * 🚚 파일 정리 - 스크립트 파일 /scripts로 이동 * 🧪 store 관련 테스트 파일 추가 - 테마 변경 테스트 - test script 경로 루트로 변경 * ✨ theme 관련 state 작업 - theme icon 변경, theme 적용을 store를 통해 설정되도록 수정 * ✨ heatmap 색상 Theme에 따라 변경되도록 수정
- Loading branch information
Showing
20 changed files
with
167 additions
and
66 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,34 @@ | ||
import NavBar from "@/components/NavBar.vue"; | ||
import { describe, test, expect } from "vitest"; | ||
import { shallowMount } from "@vue/test-utils"; | ||
import { store } from "@/store"; | ||
|
||
describe("NavBar.vue theme 변경", () => { | ||
test("theme 변경 버튼을 클릭하면 버튼의 theme icon이 변경된다.", () => { | ||
const wrapper = shallowMount(NavBar, { | ||
global: { | ||
plugins: [store], | ||
}, | ||
}); | ||
|
||
const themeButton = wrapper.find("#theme-button"); | ||
const beforeTheme = themeButton.attributes("class"); | ||
themeButton.trigger("click"); | ||
|
||
expect(themeButton.classes()).not.toBe(beforeTheme); | ||
}); | ||
|
||
test("theme 변경 버튼을 클릭하면 store state 값이 반대로 변경된다.", () => { | ||
const wrapper = shallowMount(NavBar, { | ||
global: { | ||
plugins: [store], | ||
}, | ||
}); | ||
|
||
const beforeState = store.state.darkTheme; | ||
const themeButton = wrapper.find("#theme-button"); | ||
themeButton.trigger("click"); | ||
|
||
expect(store.state.darkTheme).not.toEqual(beforeState); | ||
}); | ||
}); |
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,10 @@ | ||
import { createStore } from "vuex"; | ||
import { state } from "./state"; | ||
import { mutations } from "./mutations"; | ||
|
||
export const store = createStore({ | ||
state() { | ||
return state; | ||
}, | ||
mutations, | ||
}); |
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,13 @@ | ||
import type { RootState } from "./state"; | ||
|
||
export enum MutationTypes { | ||
TOGGLE_THEME = "TOGGLE_THEME", | ||
} | ||
|
||
export const mutations = { | ||
[MutationTypes.TOGGLE_THEME](state: RootState) { | ||
state.darkTheme = !state.darkTheme; | ||
}, | ||
}; | ||
|
||
export type Mutations = typeof mutations; |
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 { getTheme } from "@/utils/theme"; | ||
|
||
export const state = { | ||
darkTheme: getTheme() === "dark" || false, | ||
}; | ||
|
||
export type RootState = typeof state; |
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,9 @@ | ||
const getTheme = () => { | ||
return localStorage.getItem("selected-theme"); | ||
}; | ||
|
||
const setTheme = (theme: string) => { | ||
localStorage.setItem("selected-theme", theme); | ||
}; | ||
|
||
export { getTheme, setTheme }; |
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,8 @@ | ||
import { Store } from "vuex"; | ||
import { RootState } from "./store/state"; | ||
declare module "@vue/runtime-core" { | ||
// provide typings for `this.$store` | ||
interface ComponentCustomProperties { | ||
$store: Store<RootState>; | ||
} | ||
} |
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,13 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { mutations, MutationTypes } from "@/store/mutations"; | ||
|
||
describe("mutations", () => { | ||
test("TOGGLE_THEME", () => { | ||
const state = { | ||
darkTheme: false, | ||
}; | ||
|
||
mutations[MutationTypes.TOGGLE_THEME](state); | ||
expect(state.darkTheme).toBeTruthy(); | ||
}); | ||
}); |
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