Skip to content

Commit

Permalink
Generate test schedule data for view testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvonen committed May 13, 2024
1 parent 3fb4afe commit cbc57fd
Show file tree
Hide file tree
Showing 8 changed files with 730 additions and 104 deletions.
17 changes: 17 additions & 0 deletions src/components/__tests__/ExportView.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {mount} from '@vue/test-utils';
import {describe, it, expect, beforeEach} from 'vitest';
import ExportView from '@/views/ExportView.vue';
import {useScheduleStore} from '@/stores/schedule';
import {getTestWeeks} from '@/utils';

describe('ExportView', () => {
beforeEach(() => {
const scheduleStore = useScheduleStore();
scheduleStore.weeks.push(...getTestWeeks());
});

it('mounts', () => {
const wrapper = mount(ExportView);
expect(wrapper.html()).toMatchSnapshot();
});
});
9 changes: 8 additions & 1 deletion src/components/__tests__/ScheduleView.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {mount} from '@vue/test-utils';
import {describe, it, expect} from 'vitest';
import {describe, it, expect, beforeEach} from 'vitest';
import ScheduleView from '@/views/ScheduleView.vue';
import {useScheduleStore} from '@/stores/schedule';
import {getTestWeeks} from '@/utils';

describe('ScheduleView', () => {
beforeEach(() => {
const scheduleStore = useScheduleStore();
scheduleStore.weeks.push(...getTestWeeks());
});

it('mounts', () => {
const wrapper = mount(ScheduleView);
expect(wrapper.html()).toMatchSnapshot();
Expand Down
10 changes: 9 additions & 1 deletion src/components/__tests__/StatsView.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import {describe, it, expect, vi, afterEach} from 'vitest';
import {describe, it, expect, vi, afterEach, beforeEach} from 'vitest';
import {mount} from '@vue/test-utils';
import StatsView from '@/views/StatsView.vue';
import {useScheduleStore} from '@/stores/schedule';
import {getTestWeeks} from '@/utils';

describe('StatsView', () => {
afterEach(() => {
vi.restoreAllMocks();
});

beforeEach(() => {
const scheduleStore = useScheduleStore();
scheduleStore.weeks.push(...getTestWeeks());
});

it('mounts', () => {
vi.mock('vue-chartjs', () => ({
Pie: {
Expand Down
366 changes: 366 additions & 0 deletions src/components/__tests__/__snapshots__/ExportView.spec.ts.snap

Large diffs are not rendered by default.

167 changes: 166 additions & 1 deletion src/components/__tests__/__snapshots__/ScheduleView.spec.ts.snap

Large diffs are not rendered by default.

65 changes: 61 additions & 4 deletions src/components/__tests__/__snapshots__/StatsView.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,25 @@ exports[`StatsView > mounts 1`] = `
<thead>
<tr>
<!--v-if-->
<th>Running</th>
<th>Swimming</th>
<th>Badminton</th>
<th>Body Maintenance</th>
<th>Gym</th>
<th>Sprint</th>
<th>Other</th>
</tr>
</thead>
<tbody>
<tr></tr>
<tr>
<td>2</td>
<td>2</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -48,10 +63,17 @@ exports[`StatsView > mounts 1`] = `
<thead>
<tr>
<!--v-if-->
<th>Light</th>
<th>Normal</th>
<th>Demanding</th>
</tr>
</thead>
<tbody>
<tr></tr>
<tr>
<td>1</td>
<td>5</td>
<td>3</td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -62,10 +84,21 @@ exports[`StatsView > mounts 1`] = `
<thead>
<tr>
<!--v-if-->
<th>No rating</th>
<th>1 ★</th>
<th>2 ★</th>
<th>4 ★</th>
<th>5 ★</th>
</tr>
</thead>
<tbody>
<tr></tr>
<tr>
<td>5</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
</div>
Expand All @@ -78,14 +111,20 @@ exports[`StatsView > mounts 1`] = `
<thead>
<tr>
<td></td>
<th>Week 1</th>
<th>Week 2</th>
</tr>
</thead>
<tbody>
<tr>
<th>Total trainings</th>
<td>4</td>
<td>5</td>
</tr>
<tr>
<th>Completed trainings</th>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
Expand All @@ -99,9 +138,27 @@ exports[`StatsView > mounts 1`] = `
<thead>
<tr>
<td></td>
<th>Week 1</th>
<th>Week 2</th>
</tr>
</thead>
<tbody></tbody>
<tbody>
<tr>
<th>Hours</th>
<td>2</td>
<td>5.25</td>
</tr>
<tr>
<th>Kilometers</th>
<td>30</td>
<td>15</td>
</tr>
<tr>
<th>Miles</th>
<td>1</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
</div>
Expand Down
95 changes: 2 additions & 93 deletions src/components/__tests__/charts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {describe, it, expect, beforeEach} from 'vitest';
import {mount} from '@vue/test-utils';
import {v4 as uuid} from 'uuid';
import {useScheduleStore} from '@/stores/schedule';
import {getEmptyTraining} from '@/utils';
import {Intensity} from '@/types';
import {getTestWeeks} from '@/utils';
import {COLORS} from '@/constants';
import ActivityChart from '@/components/charts/ActivityChart.vue';
import IntensityChart from '@/components/charts/IntensityChart.vue';
Expand All @@ -13,97 +11,8 @@ import WeeklySummaryChart from '@/components/charts/WeeklySummaryChart.vue';

describe('Charts', () => {
beforeEach(() => {
const weekId = uuid();
const weekId2 = uuid();
const scheduleStore = useScheduleStore();
scheduleStore.weeks.push(
{
id: weekId,
trainings: [
getEmptyTraining({
weekId,
dayIndex: 0,
activity: 'running',
duration: 30,
unitOfDuration: 'km',
intensity: Intensity.DEMANDING,
}),
getEmptyTraining({
weekId,
dayIndex: 3,
activity: 'swimming',
duration: 30,
unitOfDuration: 'm',
completed: true,
}),
getEmptyTraining({
weekId,
dayIndex: 3,
activity: 'gym',
duration: 1.5,
unitOfDuration: 'h',
completed: true,
rating: 2,
intensity: Intensity.DEMANDING,
}),
getEmptyTraining({
weekId,
dayIndex: 5,
activity: 'sprint',
duration: 1,
unitOfDuration: 'mi',
intensity: Intensity.DEMANDING,
}),
],
},
{
id: weekId2,
trainings: [
getEmptyTraining({
weekId: weekId2,
dayIndex: 0,
activity: 'swimming',
duration: 75,
unitOfDuration: 'm',
}),
getEmptyTraining({
weekId: weekId2,
dayIndex: 0,
activity: 'running',
duration: 15,
unitOfDuration: 'km',
completed: true,
rating: 5,
}),
getEmptyTraining({
weekId: weekId2,
dayIndex: 3,
activity: 'maintenance',
duration: 1,
unitOfDuration: 'h',
completed: true,
rating: 4,
intensity: Intensity.LIGHT,
}),
getEmptyTraining({
weekId: weekId2,
dayIndex: 5,
activity: 'badminton',
duration: 2,
unitOfDuration: 'h',
completed: true,
rating: 1,
}),
getEmptyTraining({
weekId: weekId2,
dayIndex: 6,
activity: 'tennis',
duration: 1,
unitOfDuration: 'h',
}),
],
},
);
scheduleStore.weeks.push(...getTestWeeks());
});

it('calculates data for ActivityChart', () => {
Expand Down
Loading

0 comments on commit cbc57fd

Please sign in to comment.