-
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.
- Loading branch information
Showing
10 changed files
with
341 additions
and
25 deletions.
There are no files selected for viewing
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,48 @@ | ||
<script lang="ts" setup> | ||
import {computed} from 'vue'; | ||
import {storeToRefs} from 'pinia'; | ||
import {DateTime} from 'luxon'; | ||
import {useScheduleStore} from '@/stores/schedule'; | ||
import TrainingCard from '@/components/TrainingCard.vue'; | ||
const scheduleStore = useScheduleStore(); | ||
const {weeks, settings} = storeToRefs(scheduleStore); | ||
const dailyTrainings = computed(() => { | ||
const startDate = DateTime.fromJSDate(settings.value.startDate!); | ||
const difference = Math.ceil(startDate.diffNow('weeks').weeks); | ||
if (difference < 1) { | ||
const targetWeek = weeks.value[Math.abs(difference)]; | ||
if (targetWeek) { | ||
const targetDay = (DateTime.now().weekday - (settings.value.startsOnSunday ? 0 : 1)) % 7; | ||
return targetWeek.trainings.filter(({dayIndex}) => dayIndex === targetDay); | ||
} | ||
} | ||
return []; | ||
}); | ||
</script> | ||
<template> | ||
<div class="daily-agenda has-scroll mt-10 d-flex"> | ||
<TrainingCard | ||
v-for="training in dailyTrainings" | ||
:key="training.id" | ||
:training="training" | ||
simple | ||
/> | ||
<p v-if="!dailyTrainings.length" class="mx-auto">{{ $t('home.noTrainings') }}</p> | ||
</div> | ||
</template> | ||
<style lang="scss" scoped> | ||
.daily-agenda { | ||
gap: 1rem; | ||
overflow-x: scroll; | ||
} | ||
.training-card__container:first-child { | ||
margin-left: auto; | ||
} | ||
.training-card__container:last-child { | ||
margin-right: auto; | ||
} | ||
</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
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,49 @@ | ||
import {mount} from '@vue/test-utils'; | ||
import {describe, it, expect, beforeEach} from 'vitest'; | ||
import {v4 as uuid} from 'uuid'; | ||
import {DateTime} from 'luxon'; | ||
import DailyAgenda from '@/components/DailyAgenda.vue'; | ||
import {useScheduleStore} from '@/stores/schedule'; | ||
import {getEmptyTraining} from '@/utils'; | ||
|
||
describe('DailyAgenda', () => { | ||
let scheduleStore: ReturnType<typeof useScheduleStore>; | ||
|
||
beforeEach(() => { | ||
scheduleStore = useScheduleStore(); | ||
}); | ||
|
||
it('displays training data', () => { | ||
const weekId = uuid(); | ||
const todayIndex = DateTime.now().weekday - 1; | ||
scheduleStore.settings.startDate = DateTime.now().startOf('week').toJSDate(); | ||
scheduleStore.weeks.push({ | ||
id: weekId, | ||
trainings: [ | ||
getEmptyTraining({ | ||
activity: 'boxing', | ||
dayIndex: todayIndex, | ||
weekId, | ||
}), | ||
getEmptyTraining({ | ||
activity: 'swimming', | ||
dayIndex: todayIndex, | ||
weekId, | ||
}), | ||
getEmptyTraining({ | ||
dayIndex: (todayIndex + 1) % 7, | ||
weekId, | ||
}), | ||
getEmptyTraining({ | ||
dayIndex: (todayIndex + 2) % 7, | ||
weekId, | ||
}), | ||
], | ||
}); | ||
const wrapper = mount(DailyAgenda); | ||
|
||
expect(wrapper.findAll('.training-card__title').length).toBe(2); | ||
expect(wrapper.findAll('.training-card__title')[0].text()).toBe('Boxing'); | ||
expect(wrapper.findAll('.training-card__title')[1].text()).toBe('Swimming'); | ||
}); | ||
}); |
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,29 @@ | ||
import {it, expect, describe, beforeEach} from 'vitest'; | ||
import {mount} from '@vue/test-utils'; | ||
import {DateTime} from 'luxon'; | ||
import {v4 as uuid} from 'uuid'; | ||
import {useScheduleStore} from '@/stores/schedule'; | ||
import HomeView from '@/views/HomeView.vue'; | ||
|
||
describe('HomeView', () => { | ||
let scheduleStore: ReturnType<typeof useScheduleStore>; | ||
|
||
beforeEach(() => { | ||
scheduleStore = useScheduleStore(); | ||
}); | ||
|
||
it('mounts', () => { | ||
const wrapper = mount(HomeView); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
it('mounts with agenda', () => { | ||
scheduleStore.weeks.push({ | ||
id: uuid(), | ||
trainings: [], | ||
}); | ||
scheduleStore.settings.startDate = DateTime.now().startOf('week').toJSDate(); | ||
const wrapper = mount(HomeView); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
src/components/__tests__/__snapshots__/HomeView.spec.ts.snap
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,33 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`HomeView > mounts 1`] = ` | ||
"<div data-v-b4e148ca="" class="home__overlay text-body-1 text-grey-lighten-5"> | ||
<h1 data-v-b4e148ca="" class="text-h3 text-center">Let's GetFit </h1> | ||
<p data-v-b4e148ca="" class="mt-10">GetFit is a free, easy-to-use exercise program planner that allows you to plan a schedule spanning multiple weeks.</p> | ||
<p data-v-b4e148ca="" class="mt-4">To get started, navigate to settings and fill some basic info. Then, go to your schedule and start planning activities.</p> | ||
<p data-v-b4e148ca="" class="mt-4">If you give your schedule a starting date, a daily agenda will appear on this screen. All data persists in your browser's local storage only, and is not sent anywhere.</p> | ||
<p data-v-b4e148ca="" class="mt-10"><i data-v-b4e148ca="" class="mdi-github mdi v-icon notranslate v-theme--light v-icon--size-default" aria-hidden="true"></i><a data-v-b4e148ca="" class="text-grey-lighten-5 ml-2" href="https://www.github.com/ajuvonen/getfit">GitHub</a></p><button data-v-b4e148ca="" type="button" class="v-btn v-theme--light v-btn--density-default v-btn--size-x-small v-btn--variant-text home__photo-credit"><span class="v-btn__overlay"></span><span class="v-btn__underlay"></span> | ||
<!----><span class="v-btn__content" data-no-activator="">Photo credits</span> | ||
<!----> | ||
<!----> | ||
</button> | ||
<!----> | ||
<!----> | ||
</div>" | ||
`; | ||
|
||
exports[`HomeView > mounts with agenda 1`] = ` | ||
"<div data-v-b4e148ca="" class="home__overlay text-body-1 text-grey-lighten-5"> | ||
<h1 data-v-b4e148ca="" class="text-h3 text-center">Today:</h1> | ||
<div data-v-c4ee72cd="" data-v-b4e148ca="" class="daily-agenda has-scroll mt-10 d-flex"> | ||
<p data-v-c4ee72cd="" class="mx-auto">No trainings. Enjoy your day off!</p> | ||
</div> | ||
<p data-v-b4e148ca="" class="mt-10"><i data-v-b4e148ca="" class="mdi-github mdi v-icon notranslate v-theme--light v-icon--size-default" aria-hidden="true"></i><a data-v-b4e148ca="" class="text-grey-lighten-5 ml-2" href="https://www.github.com/ajuvonen/getfit">GitHub</a></p><button data-v-b4e148ca="" type="button" class="v-btn v-theme--light v-btn--density-default v-btn--size-x-small v-btn--variant-text home__photo-credit"><span class="v-btn__overlay"></span><span class="v-btn__underlay"></span> | ||
<!----><span class="v-btn__content" data-no-activator="">Photo credits</span> | ||
<!----> | ||
<!----> | ||
</button> | ||
<!----> | ||
<!----> | ||
</div>" | ||
`; |
Oops, something went wrong.