Skip to content

Commit f6f1d8c

Browse files
authored
Feature/add alias and vite config fix (#19)
* ♻️ Add alias configuration * 🩹 Add lint ignore config
1 parent ac0c95a commit f6f1d8c

File tree

18 files changed

+730
-268
lines changed

18 files changed

+730
-268
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

dev/_variables.scss

Lines changed: 0 additions & 2 deletions
This file was deleted.

dev/serve.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { ref } from 'vue'
3-
import DatePicker from '../src/DatePicker/components/DatePicker/DatePicker.vue'
3+
import DatePicker from '~/components/DatePicker/DatePicker.vue'
44
/**
55
* To debug using yarn link, follow these steps
66
* Open a terminal and navigate to the root directory of your project.
@@ -67,8 +67,8 @@ const yearContent = ref('')
6767
<template>
6868
<div>
6969
<DatePicker
70-
v-model="currentDate"
7170
ref="datePick"
71+
v-model="currentDate"
7272
:months="months"
7373
:weekdays="weekdays"
7474
:year-first="yearFirst"

package.json

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,51 +39,51 @@
3939
"date-fns"
4040
],
4141
"scripts": {
42-
"dev": "DEV_MODE=true vite",
42+
"dev": "vite",
4343
"build": "vue-tsc && vite build",
4444
"preview": "vite preview",
4545
"test": "vitest run",
4646
"prettier": "prettier --write .",
4747
"lint": "yarn lint:js & yarn lint:style",
4848
"lint:style": "stylelint \"**/*.{css,scss}\" --ignore-path .gitignore",
49-
"lint:js": "eslint --format=stylish --ignore-pattern .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
49+
"lint:js": "eslint --format=stylish --cache --cache-location ./node_modules/.cache/eslint .",
5050
"prepare": "husky install"
5151
},
5252
"peerDependencies": {
53-
"vue": "^3.4.19"
53+
"vue": "3.4.19"
5454
},
5555
"dependencies": {
56-
"date-fns": "^3.3.1"
56+
"date-fns": "3.3.1"
5757
},
5858
"devDependencies": {
59-
"@testing-library/jest-dom": "^6.4.6",
60-
"@testing-library/vue": "^8.1.0",
61-
"@types/node": "^22.2.0",
62-
"@types/vue": "^2.0.0",
63-
"@typescript-eslint/eslint-plugin": "^7.16.1",
64-
"@typescript-eslint/parser": "^7.16.1",
65-
"@vitejs/plugin-vue": "^5.0.4",
66-
"eslint": "^8.57.0",
67-
"eslint-config-prettier": "^9.1.0",
68-
"eslint-plugin-prettier": "^5.2.1",
69-
"eslint-plugin-vue": "^9.27.0",
70-
"husky": "^8.0.0",
71-
"jsdom": "^24.1.1",
72-
"lint-staged": "^15.2.7",
73-
"prettier": "^3.3.3",
74-
"sass": "^1.71.1",
75-
"sass-loader": "^14.1.1",
76-
"stylelint": "^16.7.0",
77-
"stylelint-config-recommended-scss": "^14.1.0",
78-
"stylelint-config-standard": "^36.0.1",
79-
"stylelint-scss": "^6.4.1",
80-
"typescript": "^5.2.2",
81-
"vite": "^5.1.4",
82-
"vite-plugin-css-injected-by-js": "^3.4.0",
83-
"vite-plugin-dts": "^3.7.3",
84-
"vitest": "^2.0.3",
85-
"vue": "^3.4.19",
86-
"vue-tsc": "^2.0.29"
59+
"@testing-library/jest-dom": "6.4.6",
60+
"@testing-library/vue": "8.1.0",
61+
"@types/node": "22.2.0",
62+
"@types/vue": "2.0.0",
63+
"@typescript-eslint/eslint-plugin": "7.16.1",
64+
"@typescript-eslint/parser": "7.16.1",
65+
"@vitejs/plugin-vue": "5.0.4",
66+
"eslint": "8.57.0",
67+
"eslint-config-prettier": "9.1.0",
68+
"eslint-plugin-prettier": "5.2.1",
69+
"eslint-plugin-vue": "9.27.0",
70+
"husky": "8.0.0",
71+
"jsdom": "24.1.1",
72+
"lint-staged": "15.2.7",
73+
"prettier": "3.3.3",
74+
"sass": "1.71.1",
75+
"sass-loader": "14.1.1",
76+
"stylelint": "16.7.0",
77+
"stylelint-config-recommended-scss": "14.1.0",
78+
"stylelint-config-standard": "36.0.1",
79+
"stylelint-scss": "6.4.1",
80+
"typescript": "5.2.2",
81+
"vite": "5.1.4",
82+
"vite-plugin-css-injected-by-js": "3.4.0",
83+
"vite-plugin-dts": "3.7.3",
84+
"vitest": "2.0.3",
85+
"vue": "3.4.19",
86+
"vue-tsc": "2.0.29"
8787
},
8888
"resolutions": {
8989
"strip-ansi": "6.0.1",
@@ -92,12 +92,10 @@
9292
},
9393
"lint-staged": {
9494
"*.{js,ts,vue}": [
95-
"yarn lint:js",
96-
"yarn prettier"
95+
"yarn lint:js"
9796
],
9897
"*.{scss,css}": [
99-
"yarn lint:style",
100-
"yarn prettier"
98+
"yarn lint:style"
10199
]
102100
}
103101
}

src/DatePicker/components/DatePicker/DatePicker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mount, shallowMount } from '@vue/test-utils'
22
import { beforeAll, describe, expect, it, vi } from 'vitest'
3-
import { Props } from '../../types'
3+
import { Props } from '~/types'
44
import DatePicker from './DatePicker.vue'
55

66
const mockOpenUpdated = vi.fn()

src/DatePicker/components/DatePicker/DatePicker.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script setup lang="ts">
22
import { ref } from 'vue'
3-
import { Props } from '../../types'
4-
import DpButton from '../DpButton/DpButton.vue'
5-
import DpCalendar from '../DpCalendar/DpCalendar.vue'
6-
import DpMonthPicker from '../DpMonthPicker/DpMonthPicker.vue'
7-
import DpYearPicker from '../DpYearPicker/DpYearPicker.vue'
3+
import { DpButton } from '~/components/DpButton'
4+
import { DpCalendar } from '~/components/DpCalendar'
5+
import { DpMonthPicker } from '~/components/DpMonthPicker'
6+
import { DpYearPicker } from '~/components/DpYearPicker'
7+
import { Props } from '~/types'
88
import { useDatePicker } from './useDatePicker'
99
1010
const props = withDefaults(defineProps<Props>(), {
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest'
2+
import { ref } from 'vue'
3+
import { EnhancedDay, Props } from '~/types'
4+
import { useDatePicker } from './useDatePicker'
5+
6+
// Vueのライフサイクルフックだけをモック
7+
vi.mock('vue', async (importOriginal) => {
8+
const actual = (await importOriginal()) as typeof import('vue')
9+
return {
10+
...actual,
11+
onBeforeUnmount: vi.fn(), // onBeforeUnmountだけをモック
12+
}
13+
})
14+
15+
describe('useDatePicker', () => {
16+
const mockEmit = vi.fn()
17+
18+
const props: Required<Props> = {
19+
modelValue: '2023-09-30',
20+
displayFormat: 'yyyy-MM-dd',
21+
isDateDisabled: vi.fn(() => false),
22+
weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
23+
startWeekOnSunday: false,
24+
yearFirst: false,
25+
months: [
26+
'January',
27+
'February',
28+
'March',
29+
'April',
30+
'May',
31+
'June',
32+
'July',
33+
'August',
34+
'September',
35+
'October',
36+
'November',
37+
'December',
38+
],
39+
disabled: false,
40+
placeholder: 'Please select a date',
41+
yearContent: '',
42+
}
43+
44+
const el = ref(null)
45+
const outerWrap = ref(null)
46+
47+
afterEach(() => {
48+
vi.clearAllMocks()
49+
vi.clearAllTimers()
50+
})
51+
52+
it('should initialize correctly', () => {
53+
const { inputValue, currentPeriod, opened } = useDatePicker(
54+
props,
55+
el,
56+
outerWrap,
57+
mockEmit
58+
)
59+
60+
expect(inputValue.value).toBe('2023-09-30')
61+
expect(currentPeriod.value).toEqual({ month: 8, year: 2023 })
62+
expect(opened.value).toBe(false)
63+
})
64+
65+
it('should open the date picker', () => {
66+
const { openUpdated, opened } = useDatePicker(
67+
props,
68+
el,
69+
outerWrap,
70+
mockEmit
71+
)
72+
73+
openUpdated()
74+
expect(opened.value).toBe(true)
75+
})
76+
77+
it('should close the date picker', () => {
78+
const { closeUpdated, opened } = useDatePicker(
79+
props,
80+
el,
81+
outerWrap,
82+
mockEmit
83+
)
84+
85+
closeUpdated()
86+
expect(opened.value).toBe(false)
87+
})
88+
89+
it('should update the modelValue when a valid date is selected', () => {
90+
const { selectDateItem } = useDatePicker(props, el, outerWrap, mockEmit)
91+
92+
const item: EnhancedDay = {
93+
date: new Date('2023-10-01'),
94+
disabled: false,
95+
}
96+
selectDateItem(item)
97+
98+
expect(mockEmit).toHaveBeenCalledWith('update:modelValue', '2023-10-01')
99+
})
100+
101+
it('should not select a disabled date', () => {
102+
const { selectDateItem } = useDatePicker(props, el, outerWrap, mockEmit)
103+
104+
const item: EnhancedDay = {
105+
date: new Date('2023-10-01'),
106+
disabled: true,
107+
}
108+
selectDateItem(item)
109+
110+
expect(mockEmit).not.toHaveBeenCalled()
111+
})
112+
113+
it('should handle input correctly', () => {
114+
const { handleInput, handleFocusOut } = useDatePicker(
115+
props,
116+
el,
117+
outerWrap,
118+
mockEmit
119+
)
120+
121+
const inputElement = document.createElement('input')
122+
inputElement.value = '2023-10-01'
123+
const event = { target: inputElement } as unknown as Event
124+
handleInput(event)
125+
handleFocusOut()
126+
127+
expect(mockEmit).toHaveBeenCalledWith('update:modelValue', '2023-10-01')
128+
})
129+
130+
it('should handle focus out and emit correct value', async () => {
131+
const { handleFocusOut, inputValue } = useDatePicker(
132+
props,
133+
el,
134+
outerWrap,
135+
mockEmit
136+
)
137+
138+
inputValue.value = '2023-10-01'
139+
handleFocusOut()
140+
141+
expect(mockEmit).toHaveBeenCalledWith('update:modelValue', '2023-10-01')
142+
})
143+
144+
it('should close via overlay click', () => {
145+
const { closeViaOverlay, opened } = useDatePicker(
146+
props,
147+
el,
148+
outerWrap,
149+
mockEmit
150+
)
151+
152+
const event = { target: outerWrap.value } as Event
153+
closeViaOverlay(event)
154+
155+
expect(opened.value).toBe(false)
156+
})
157+
})

src/DatePicker/components/DatePicker/useDatePicker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Ref, computed, ref, watch } from 'vue'
2-
import { useCloseEventListener } from '../../composables/useCloseEventListener'
3-
import { useDateUtilities } from '../../composables/useDateUtilities'
4-
import { useToggle } from '../../composables/useToggle'
5-
import { EnhancedDay, Props } from '../../types'
2+
import { useCloseEventListener } from '~/composables/useCloseEventListener'
3+
import { useDateUtilities } from '~/composables/useDateUtilities'
4+
import { useToggle } from '~/composables/useToggle'
5+
import { EnhancedDay, Props } from '~/types'
66

77
export const useDatePicker = (
88
props: Required<Props>,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import DpButton from './DpButton.vue'
2+
export { DpButton }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import DpCalendar from './DpCalendar.vue'
2+
export { DpCalendar }

0 commit comments

Comments
 (0)