feat: move the calculation of the current salutation to a different function
This commit is contained in:
parent
dd450263fb
commit
de77393905
4 changed files with 57 additions and 58 deletions
|
@ -1,35 +0,0 @@
|
||||||
import '../../support/authenticateUser'
|
|
||||||
|
|
||||||
const setHours = hours => {
|
|
||||||
const date = new Date()
|
|
||||||
date.setHours(hours)
|
|
||||||
cy.clock(+date)
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Home Page', () => {
|
|
||||||
it('shows the right salutation in the night', () => {
|
|
||||||
setHours(4)
|
|
||||||
cy.visit('/')
|
|
||||||
cy.get('h2').should('contain', 'Good Night')
|
|
||||||
})
|
|
||||||
it('shows the right salutation in the morning', () => {
|
|
||||||
setHours(8)
|
|
||||||
cy.visit('/')
|
|
||||||
cy.get('h2').should('contain', 'Good Morning')
|
|
||||||
})
|
|
||||||
it('shows the right salutation in the day', () => {
|
|
||||||
setHours(13)
|
|
||||||
cy.visit('/')
|
|
||||||
cy.get('h2').should('contain', 'Hi')
|
|
||||||
})
|
|
||||||
it('shows the right salutation in the night', () => {
|
|
||||||
setHours(20)
|
|
||||||
cy.visit('/')
|
|
||||||
cy.get('h2').should('contain', 'Good Evening')
|
|
||||||
})
|
|
||||||
it('shows the right salutation in the night again', () => {
|
|
||||||
setHours(23)
|
|
||||||
cy.visit('/')
|
|
||||||
cy.get('h2').should('contain', 'Good Night')
|
|
||||||
})
|
|
||||||
})
|
|
34
src/helpers/hourToSalutation.test.ts
Normal file
34
src/helpers/hourToSalutation.test.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import {describe, it, expect} from 'vitest'
|
||||||
|
|
||||||
|
import {hourToSalutation} from './hourToSalutation'
|
||||||
|
|
||||||
|
const dateWithHour = (hours: number): Date => {
|
||||||
|
const date = new Date()
|
||||||
|
date.setHours(hours)
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Salutation', () => {
|
||||||
|
it('shows the right salutation in the night', () => {
|
||||||
|
const salutation = hourToSalutation(dateWithHour(4))
|
||||||
|
expect(salutation).toBe('Night')
|
||||||
|
})
|
||||||
|
it('shows the right salutation in the morning', () => {
|
||||||
|
const salutation = hourToSalutation(dateWithHour(8))
|
||||||
|
expect(salutation).toBe('Morning')
|
||||||
|
})
|
||||||
|
it('shows the right salutation in the day', () => {
|
||||||
|
const salutation = hourToSalutation(dateWithHour(13))
|
||||||
|
expect(salutation).toBe('Day')
|
||||||
|
})
|
||||||
|
it('shows the right salutation in the night', () => {
|
||||||
|
const salutation = hourToSalutation(dateWithHour(20))
|
||||||
|
expect(salutation).toBe('Evening')
|
||||||
|
})
|
||||||
|
it('shows the right salutation in the night again', () => {
|
||||||
|
const salutation = hourToSalutation(dateWithHour(23))
|
||||||
|
expect(salutation).toBe('Night')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
21
src/helpers/hourToSalutation.ts
Normal file
21
src/helpers/hourToSalutation.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
export function hourToSalutation(now: Date = new Date()): String {
|
||||||
|
const hours = new Date(now).getHours()
|
||||||
|
|
||||||
|
if (hours < 5) {
|
||||||
|
return 'Night'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours < 11) {
|
||||||
|
return 'Morning'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours < 18) {
|
||||||
|
return 'Day'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hours < 23) {
|
||||||
|
return 'Evening'
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Night'
|
||||||
|
}
|
|
@ -57,7 +57,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {ref, computed} from 'vue'
|
import {ref, computed} from 'vue'
|
||||||
import {useStore} from 'vuex'
|
import {useStore} from 'vuex'
|
||||||
import {useNow} from '@vueuse/core'
|
|
||||||
|
|
||||||
import Message from '@/components/misc/message.vue'
|
import Message from '@/components/misc/message.vue'
|
||||||
import ShowTasks from '@/views/tasks/ShowTasks.vue'
|
import ShowTasks from '@/views/tasks/ShowTasks.vue'
|
||||||
|
@ -67,29 +66,9 @@ import AddTask from '@/components/tasks/add-task.vue'
|
||||||
import {getHistory} from '@/modules/listHistory'
|
import {getHistory} from '@/modules/listHistory'
|
||||||
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
||||||
import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate'
|
import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate'
|
||||||
|
import {hourToSalutation} from '@/helpers/hourToSalutation'
|
||||||
|
|
||||||
const now = useNow()
|
const welcome = computed(hourToSalutation)
|
||||||
const welcome = computed(() => {
|
|
||||||
const hours = new Date(now.value).getHours()
|
|
||||||
|
|
||||||
if (hours < 5) {
|
|
||||||
return 'Night'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hours < 11) {
|
|
||||||
return 'Morning'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hours < 18) {
|
|
||||||
return 'Day'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hours < 23) {
|
|
||||||
return 'Evening'
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'Night'
|
|
||||||
})
|
|
||||||
|
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const listHistory = computed(() => {
|
const listHistory = computed(() => {
|
||||||
|
|
Loading…
Reference in a new issue