diff --git a/cypress/integration/misc/home.spec.js b/cypress/integration/misc/home.spec.js deleted file mode 100644 index 82cbeed2..00000000 --- a/cypress/integration/misc/home.spec.js +++ /dev/null @@ -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') - }) -}) \ No newline at end of file diff --git a/src/helpers/hourToSalutation.test.ts b/src/helpers/hourToSalutation.test.ts new file mode 100644 index 00000000..ba153019 --- /dev/null +++ b/src/helpers/hourToSalutation.test.ts @@ -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') + }) +}) + + diff --git a/src/helpers/hourToSalutation.ts b/src/helpers/hourToSalutation.ts new file mode 100644 index 00000000..b05762db --- /dev/null +++ b/src/helpers/hourToSalutation.ts @@ -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' +} diff --git a/src/views/Home.vue b/src/views/Home.vue index 7a8fce5e..7696349e 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -57,7 +57,6 @@