Client - move unit tests to Vitest

This commit is contained in:
Sam 2023-11-11 17:12:20 +01:00
parent 1befae927d
commit e9c482c585
18 changed files with 838 additions and 300 deletions

View File

@ -6,6 +6,7 @@
"dev": "vite", "dev": "vite",
"build": "run-p type-check \"build-only {@}\" --", "build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview", "preview": "vite preview",
"test:unit": "vitest",
"build-only": "vite build", "build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false", "type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
@ -44,22 +45,23 @@
"@intlify/vue-i18n-loader": "^4.2.0", "@intlify/vue-i18n-loader": "^4.2.0",
"@rushstack/eslint-patch": "^1.3.3", "@rushstack/eslint-patch": "^1.3.3",
"@tsconfig/node18": "^18.2.2", "@tsconfig/node18": "^18.2.2",
"@types/chai": "^4.3.10", "@types/jsdom": "^21.1.3",
"@types/mocha": "^10.0.4",
"@types/node": "^20.9.0", "@types/node": "^20.9.0",
"@types/sanitize-html": "^2.9.4", "@types/sanitize-html": "^2.9.4",
"@vitejs/plugin-vue": "^4.4.0", "@vitejs/plugin-vue": "^4.4.0",
"@vue/eslint-config-prettier": "^8.0.0", "@vue/eslint-config-prettier": "^8.0.0",
"@vue/eslint-config-typescript": "^12.0.0", "@vue/eslint-config-typescript": "^12.0.0",
"@vue/test-utils": "^2.4.1",
"@vue/tsconfig": "^0.4.0", "@vue/tsconfig": "^0.4.0",
"chai": "^4.3.10",
"eslint": "^8.49.0", "eslint": "^8.49.0",
"eslint-plugin-vue": "^9.17.0", "eslint-plugin-vue": "^9.17.0",
"jsdom": "^22.1.0",
"npm-run-all2": "^6.1.1", "npm-run-all2": "^6.1.1",
"prettier": "^3.0.3", "prettier": "^3.0.3",
"sass": "^1.69.5", "sass": "^1.69.5",
"typescript": "~5.2.0", "typescript": "~5.2.0",
"vite": "^4.4.11", "vite": "^4.4.11",
"vitest": "^0.34.6",
"vue-tsc": "^1.8.19" "vue-tsc": "^1.8.19"
} }
} }

View File

@ -1,13 +0,0 @@
// import { expect } from 'chai'
// import { shallowMount } from '@vue/test-utils'
// import NavBar from '@/components/NavBar.vue'
//
// describe('NavBar.vue', () => {
// it('renders props.msg when passed', () => {
// const msg = 'new message'
// const wrapper = shallowMount(NavBar, {
// props: { msg },
// })
// expect(wrapper.text()).to.include(msg)
// })
// })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { import {
defaultPerPage, defaultPerPage,
@ -50,13 +50,9 @@ describe('getNumberQueryValue', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(
getNumberQueryValue( getNumberQueryValue(testParams.inputValue, testParams.inputDefaultValue)
testParams.inputValue, ).toBe(testParams.expectedValue)
testParams.inputDefaultValue
),
testParams.expectedValue
)
}) })
}) })
}) })
@ -85,14 +81,13 @@ describe('getStringQueryValue', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(
getStringQueryValue( getStringQueryValue(
testParams.inputValue, testParams.inputValue,
sortList, sortList,
testParams.inputDefaultValue testParams.inputDefaultValue
),
testParams.expectedValue
) )
).toBe(testParams.expectedValue)
}) })
}) })
}) })
@ -169,19 +164,18 @@ describe('getQuery', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getQuery(testParams.inputLocationQuery, orderByList, defaultOrderBy, { getQuery(testParams.inputLocationQuery, orderByList, defaultOrderBy, {
defaultSort, defaultSort,
}), })
testParams.expectedQuery ).toStrictEqual(testParams.expectedQuery)
)
}) })
}) })
}) })
describe('getQuery w/ default values', () => { describe('getQuery w/ default values', () => {
it('returns default query if location query is an empty object', () => { it('returns default query if location query is an empty object', () => {
assert.deepEqual(getQuery({}, orderByList, defaultOrderBy), { expect(getQuery({}, orderByList, defaultOrderBy)).toStrictEqual({
page: 1, page: 1,
per_page: 10, per_page: 10,
order: 'asc', order: 'asc',
@ -199,46 +193,48 @@ describe('getQuery w/ default values and input pagination payload', () => {
} }
it('returns query updated with default values', () => { it('returns query updated with default values', () => {
assert.deepEqual( expect(
getQuery({}, orderByList, defaultOrderBy, { query: inputQuery }), getQuery({}, orderByList, defaultOrderBy, { query: inputQuery })
{ ).toStrictEqual({
page: 1, page: 1,
per_page: 10, per_page: 10,
order: 'asc', order: 'asc',
order_by: defaultOrderBy, order_by: defaultOrderBy,
} })
)
}) })
it('returns query updated with input values', () => { it('returns query updated with input values', () => {
assert.deepEqual( expect(
getQuery({}, orderByList, defaultOrderBy, { getQuery({}, orderByList, defaultOrderBy, {
defaultSort: 'desc', defaultSort: 'desc',
query: inputQuery, query: inputQuery,
}), })
{ ).toStrictEqual({
page: 1, page: 1,
per_page: 10, per_page: 10,
order: 'desc', order: 'desc',
order_by: defaultOrderBy, order_by: defaultOrderBy,
} })
)
}) })
it('returns query updated', () => { it('returns query updated', () => {
assert.deepEqual( expect(
getQuery( getQuery(
{ page: '3', per_page: '10', order: 'asc', order_by: 'workouts_count' }, { page: '3', per_page: '10', order: 'asc', order_by: 'workouts_count' },
orderByList, orderByList,
defaultOrderBy, defaultOrderBy,
{ query: inputQuery } { query: inputQuery }
),
{ page: 3, per_page: 10, order: 'asc', order_by: 'workouts_count' }
) )
).toStrictEqual({
page: 3,
per_page: 10,
order: 'asc',
order_by: 'workouts_count',
})
}) })
it('returns query with only pagination keys', () => { it('returns query with only pagination keys', () => {
assert.deepEqual( expect(
getQuery( getQuery(
{ {
page: '3', page: '3',
@ -250,9 +246,13 @@ describe('getQuery w/ default values and input pagination payload', () => {
orderByList, orderByList,
defaultOrderBy, defaultOrderBy,
{ query: inputQuery } { query: inputQuery }
),
{ page: 3, per_page: 10, order: 'asc', order_by: 'workouts_count' }
) )
).toStrictEqual({
page: 3,
per_page: 10,
order: 'asc',
order_by: 'workouts_count',
})
}) })
}) })
@ -385,10 +385,9 @@ describe('rangePagination', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
rangePagination(testParams.input.pages, testParams.input.currentPage), rangePagination(testParams.input.pages, testParams.input.currentPage)
testParams.expectedPagination ).toStrictEqual(testParams.expectedPagination)
)
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert, expect } from 'chai' import { describe, it, expect } from 'vitest'
import { import {
getCalendarStartAndEnd, getCalendarStartAndEnd,
@ -36,8 +36,7 @@ describe('startDate (week starting Sunday)', () => {
it(testParams.description, () => { it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate) const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate) const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual( expect(getStartDate(testParams.inputDuration, day, false)).toStrictEqual(
getStartDate(testParams.inputDuration, day, false),
expected expected
) )
}) })
@ -70,8 +69,7 @@ describe('startDate (week starting Monday)', () => {
it(testParams.description, () => { it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate) const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate) const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual( expect(getStartDate(testParams.inputDuration, day, true)).toStrictEqual(
getStartDate(testParams.inputDuration, day, true),
expected expected
) )
}) })
@ -133,7 +131,9 @@ describe('dateIncrement', () => {
it(testParams.description, () => { it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate) const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate) const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual(incrementDate(testParams.inputDuration, day), expected) expect(incrementDate(testParams.inputDuration, day)).toStrictEqual(
expected
)
}) })
) )
}) })
@ -173,8 +173,10 @@ describe('getCalendarStartAndEnd', () => {
date, date,
testParams.inputWeekStartingMonday testParams.inputWeekStartingMonday
) )
assert.deepEqual(results.start, new Date(testParams.expectedStartDate)) expect(results.start).toStrictEqual(
assert.deepEqual(results.end, new Date(testParams.expectedEndDate)) new Date(testParams.expectedStartDate)
)
expect(results.end).toStrictEqual(new Date(testParams.expectedEndDate))
}) })
) )
}) })
@ -232,14 +234,13 @@ describe('formatWorkoutDate', () => {
] ]
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
formatWorkoutDate( formatWorkoutDate(
testParams.inputParams.date, testParams.inputParams.date,
testParams.inputParams.dateFormat, testParams.inputParams.dateFormat,
testParams.inputParams.timeFormat testParams.inputParams.timeFormat
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -271,31 +272,29 @@ describe('formatDate', () => {
] ]
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
formatDate( formatDate(
dateString, dateString,
testParams.inputParams.timezone, testParams.inputParams.timezone,
testParams.inputParams.dateFormat, testParams.inputParams.dateFormat,
testParams.inputParams.withTime testParams.inputParams.withTime
),
testParams.expectedDate
) )
).toStrictEqual(testParams.expectedDate)
}) })
}) })
}) })
describe('formatDate (w/ default value)', () => { describe('formatDate (w/ default value)', () => {
it('format date for "Europe/Paris" timezone and "dd/MM/yyyy" format', () => { it('format date for "Europe/Paris" timezone and "dd/MM/yyyy" format', () => {
assert.deepEqual( expect(
formatDate('Tue, 01 Nov 2022 00:00:00 GMT', 'Europe/Paris', 'yyyy-MM-dd'), formatDate('Tue, 01 Nov 2022 00:00:00 GMT', 'Europe/Paris', 'yyyy-MM-dd')
'2022-11-01 01:00' ).toBe('2022-11-01 01:00')
)
}) })
}) })
describe('formatDate with_seconds', () => { describe('formatDate with_seconds', () => {
it('format date for "Europe/Paris" timezone and "dd/MM/yyyy" format and seconds', () => { it('format date for "Europe/Paris" timezone and "dd/MM/yyyy" format and seconds', () => {
assert.deepEqual( expect(
formatDate( formatDate(
'Tue, 01 Nov 2022 00:00:00 GMT', 'Tue, 01 Nov 2022 00:00:00 GMT',
'Europe/Paris', 'Europe/Paris',
@ -303,9 +302,8 @@ describe('formatDate with_seconds', () => {
true, true,
null, null,
true true
),
'2022-11-01 01:00:00'
) )
).toBe('2022-11-01 01:00:00')
}) })
}) })
@ -356,13 +354,12 @@ describe('getDateFormat', () => {
] ]
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`get date format for "${testParams.inputParams.language}" and "${testParams.inputParams.dateFormat}" `, () => { it(`get date format for "${testParams.inputParams.language}" and "${testParams.inputParams.dateFormat}" `, () => {
assert.deepEqual( expect(
getDateFormat( getDateFormat(
testParams.inputParams.dateFormat, testParams.inputParams.dateFormat,
testParams.inputParams.language testParams.inputParams.language
),
testParams.expectedFormat
) )
).toBe(testParams.expectedFormat)
}) })
}) })
}) })
@ -403,14 +400,13 @@ describe('availableDateFormatOptions', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`returns available options for ${testParams.inputLanguage} locale`, () => { it(`returns available options for ${testParams.inputLanguage} locale`, () => {
assert.deepEqual( expect(
availableDateFormatOptions( availableDateFormatOptions(
inputDate, inputDate,
inputTimezone, inputTimezone,
testParams.inputLanguage testParams.inputLanguage
),
testParams.expectedOptions
) )
).toStrictEqual(testParams.expectedOptions)
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { formatDuration } from '@/utils/duration' import { formatDuration } from '@/utils/duration'
@ -43,8 +43,7 @@ describe('formatDuration (without days)', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(formatDuration(testParams.inputDuration)).toStrictEqual(
formatDuration(testParams.inputDuration),
testParams.expectedDuration testParams.expectedDuration
) )
}) })
@ -92,8 +91,7 @@ describe('formatDuration (with days)', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(formatDuration(testParams.inputDuration, true)).toStrictEqual(
formatDuration(testParams.inputDuration, true),
testParams.expectedDuration testParams.expectedDuration
) )
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { getFileSizeInMB, getReadableFileSize } from '@/utils/files' import { getFileSizeInMB, getReadableFileSize } from '@/utils/files'
@ -23,8 +23,7 @@ describe('getReadableFileSize (as text)', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(getReadableFileSize(testParams.inputFileSize, true)).toStrictEqual(
getReadableFileSize(testParams.inputFileSize, true),
testParams.expectedReadableFileSize testParams.expectedReadableFileSize
) )
}) })
@ -52,10 +51,9 @@ describe('getReadableFileSize (as object)', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getReadableFileSize(testParams.inputFileSize, false), getReadableFileSize(testParams.inputFileSize, false)
testParams.expectedReadableFileSize ).toStrictEqual(testParams.expectedReadableFileSize)
)
}) })
}) })
}) })
@ -81,8 +79,7 @@ describe('getFileSizeInMB', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(getFileSizeInMB(testParams.inputFileSize)).toStrictEqual(
getFileSizeInMB(testParams.inputFileSize),
testParams.expectedFileSize testParams.expectedFileSize
) )
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { linkifyAndClean } from '@/utils/inputs' import { linkifyAndClean } from '@/utils/inputs'
@ -11,15 +11,14 @@ describe('linkifyAndClean (clean input remains unchanged)', () => {
testInputs.map((testInput) => { testInputs.map((testInput) => {
it(`it returns unmodified input: '${testInput}'`, () => { it(`it returns unmodified input: '${testInput}'`, () => {
assert.equal(linkifyAndClean(testInput), testInput) expect(linkifyAndClean(testInput)).toBe(testInput)
}) })
}) })
}) })
describe('linkifyAndClean (URL is linkified)', () => { describe('linkifyAndClean (URL is linkified)', () => {
it('it returns URL as link with target blank', () => { it('it returns URL as link with target blank', () => {
assert.equal( expect(linkifyAndClean('link: http://www.example.com')).toBe(
linkifyAndClean('link: http://www.example.com'),
'link: <a href="http://www.example.com" target="_blank">http://www.example.com</a>' 'link: <a href="http://www.example.com" target="_blank">http://www.example.com</a>'
) )
}) })
@ -62,8 +61,7 @@ describe('linkifyAndClean (input sanitization)', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(linkifyAndClean(testParams.inputString)).toBe(
linkifyAndClean(testParams.inputString),
testParams.expectedString testParams.expectedString
) )
}) })

View File

@ -1,4 +1,4 @@
import { assert, expect } from 'chai' import { describe, it, expect } from 'vitest'
import { translatedSports } from './fixtures' import { translatedSports } from './fixtures'
@ -19,7 +19,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
id: 9, id: 9,
@ -42,7 +42,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/MM/dd' date_format: 'yyyy/MM/dd',
}, },
expected: { expected: {
id: 10, id: 10,
@ -65,7 +65,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/MM/dd' date_format: 'yyyy/MM/dd',
}, },
expected: { expected: {
id: 11, id: 11,
@ -88,7 +88,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'dd/MM/yyyy' date_format: 'dd/MM/yyyy',
}, },
expected: { expected: {
id: 12, id: 12,
@ -111,7 +111,7 @@ describe('formatRecord', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'MMM. do, yyyy' date_format: 'MMM. do, yyyy',
}, },
expected: { expected: {
id: 13, id: 13,
@ -124,15 +124,14 @@ describe('formatRecord', () => {
] ]
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
formatRecord( formatRecord(
testParams.inputParams.record, testParams.inputParams.record,
testParams.inputParams.timezone, testParams.inputParams.timezone,
false, false,
testParams.inputParams.date_format testParams.inputParams.date_format
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -152,7 +151,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
id: 9, id: 9,
@ -175,7 +174,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
id: 10, id: 10,
@ -198,7 +197,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
id: 11, id: 11,
@ -221,7 +220,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
id: 12, id: 12,
@ -244,7 +243,7 @@ describe('formatRecord after conversion', () => {
workout_id: 'hvYBqYBRa7wwXpaStWR4V2', workout_id: 'hvYBqYBRa7wwXpaStWR4V2',
}, },
timezone: 'Europe/Paris', timezone: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
id: 13, id: 13,
@ -257,15 +256,14 @@ describe('formatRecord after conversion', () => {
] ]
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
formatRecord( formatRecord(
testParams.inputParams.record, testParams.inputParams.record,
testParams.inputParams.timezone, testParams.inputParams.timezone,
true, true,
testParams.inputParams.date_format testParams.inputParams.date_format
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -300,7 +298,7 @@ describe('getRecordsBySports', () => {
input: { input: {
records: [], records: [],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: {}, expected: {},
}, },
@ -319,7 +317,7 @@ describe('getRecordsBySports', () => {
}, },
], ],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
'Cycling (Sport)': { 'Cycling (Sport)': {
@ -370,7 +368,7 @@ describe('getRecordsBySports', () => {
}, },
], ],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
'Cycling (Sport)': { 'Cycling (Sport)': {
@ -411,7 +409,7 @@ describe('getRecordsBySports', () => {
] ]
testsParams.map((testParams) => testsParams.map((testParams) =>
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getRecordsBySports( getRecordsBySports(
testParams.input.records, testParams.input.records,
translatedSports, translatedSports,
@ -419,11 +417,8 @@ describe('getRecordsBySports', () => {
false, false,
true, true,
testParams.input.date_format testParams.input.date_format
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
) )
}) })
@ -435,7 +430,7 @@ describe('getRecordsBySports after conversion', () => {
input: { input: {
records: [], records: [],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: {}, expected: {},
}, },
@ -454,7 +449,7 @@ describe('getRecordsBySports after conversion', () => {
}, },
], ],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
'Cycling (Sport)': { 'Cycling (Sport)': {
@ -505,7 +500,7 @@ describe('getRecordsBySports after conversion', () => {
}, },
], ],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
'Cycling (Sport)': { 'Cycling (Sport)': {
@ -546,7 +541,7 @@ describe('getRecordsBySports after conversion', () => {
] ]
testsParams.map((testParams) => testsParams.map((testParams) =>
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getRecordsBySports( getRecordsBySports(
testParams.input.records, testParams.input.records,
translatedSports, translatedSports,
@ -554,11 +549,8 @@ describe('getRecordsBySports after conversion', () => {
true, true,
true, true,
testParams.input.date_format testParams.input.date_format
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
) )
}) })
@ -570,7 +562,7 @@ describe('getRecordsBySports with HA record', () => {
input: { input: {
records: [], records: [],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: {}, expected: {},
}, },
@ -598,7 +590,7 @@ describe('getRecordsBySports with HA record', () => {
}, },
], ],
tz: 'Europe/Paris', tz: 'Europe/Paris',
date_format: 'yyyy/dd/MM' date_format: 'yyyy/dd/MM',
}, },
expected: { expected: {
'Cycling (Sport)': { 'Cycling (Sport)': {
@ -619,7 +611,7 @@ describe('getRecordsBySports with HA record', () => {
] ]
testsParams.map((testParams) => testsParams.map((testParams) =>
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getRecordsBySports( getRecordsBySports(
testParams.input.records, testParams.input.records,
translatedSports, translatedSports,
@ -627,11 +619,8 @@ describe('getRecordsBySports with HA record', () => {
false, false,
false, false,
testParams.input.date_format testParams.input.date_format
),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
) )
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { sports } from './fixtures' import { sports } from './fixtures'
@ -451,15 +451,14 @@ describe('translateSports', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
locale.value = testParams.inputParams.locale locale.value = testParams.inputParams.locale
assert.deepEqual( expect(
translateSports( translateSports(
testParams.inputParams.sports, testParams.inputParams.sports,
t, t,
testParams.inputParams.activeStatus, testParams.inputParams.activeStatus,
testParams.inputParams.sportsToInclude testParams.inputParams.sportsToInclude
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { sports } from './fixtures' import { sports } from './fixtures'
@ -87,7 +87,7 @@ describe('getDateKeys (week starting Sunday)', () => {
const expected: Date[] = testParams.expected.map( const expected: Date[] = testParams.expected.map(
(date_string: string) => new Date(date_string) (date_string: string) => new Date(date_string)
) )
assert.deepEqual(getDateKeys(testParams.inputParams, false), expected) expect(getDateKeys(testParams.inputParams, false)).toStrictEqual(expected)
}) })
) )
}) })
@ -162,7 +162,7 @@ describe('getDateKeys (week starting Monday)', () => {
const expected: Date[] = testParams.expected.map( const expected: Date[] = testParams.expected.map(
(date_string: string) => new Date(date_string) (date_string: string) => new Date(date_string)
) )
assert.deepEqual(getDateKeys(testParams.inputParams, true), expected) expect(getDateKeys(testParams.inputParams, true)).toStrictEqual(expected)
}) })
) )
}) })
@ -282,8 +282,9 @@ describe('getDatasets', () => {
}, },
], ],
} }
assert.deepEqual(getDatasets(sports), expected) expect(getDatasets(sports)).toStrictEqual(expected)
}) })
it('returns chart datasets with only displayed sports', () => { it('returns chart datasets with only displayed sports', () => {
const expected: TStatisticsDatasets = { const expected: TStatisticsDatasets = {
average_speed: [ average_speed: [
@ -332,7 +333,7 @@ describe('getDatasets', () => {
}, },
], ],
} }
assert.deepEqual(getDatasets([sports[1]]), expected) expect(getDatasets([sports[1]])).toStrictEqual(expected)
}) })
}) })
@ -355,7 +356,7 @@ describe('formatStats', () => {
total_descent: [], total_descent: [],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -364,9 +365,8 @@ describe('formatStats', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it('returns empty datasets if no data and displayed sport provided', () => { it('returns empty datasets if no data and displayed sport provided', () => {
@ -426,7 +426,7 @@ describe('formatStats', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -435,9 +435,8 @@ describe('formatStats', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it('returns empty datasets if data provided but no displayed sport', () => { it('returns empty datasets if data provided but no displayed sport', () => {
@ -497,7 +496,7 @@ describe('formatStats', () => {
total_descent: [], total_descent: [],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -506,9 +505,8 @@ describe('formatStats', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it('returns datasets when data and displayed sport provided', () => { it('returns datasets when data and displayed sport provided', () => {
@ -607,7 +605,7 @@ describe('formatStats', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -616,9 +614,8 @@ describe('formatStats', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
}) })
@ -719,7 +716,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -728,9 +725,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it("returns datasets when duration is 'month'", () => { it("returns datasets when duration is 'month'", () => {
const inputStats: TStatisticsFromApi = { const inputStats: TStatisticsFromApi = {
@ -828,7 +824,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -837,9 +833,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it("returns datasets when duration is 'week' and week starts on Sunday", () => { it("returns datasets when duration is 'week' and week starts on Sunday", () => {
@ -938,7 +933,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -947,9 +942,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it("returns datasets when duration is 'week' and week starts on Monday", () => { it("returns datasets when duration is 'week' and week starts on Monday", () => {
@ -1048,7 +1042,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
true, true,
@ -1057,9 +1051,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
false, false,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it("returns datasets when duration is 'week' and date format 'dd/MM/yyyy'", () => { it("returns datasets when duration is 'week' and date format 'dd/MM/yyyy'", () => {
@ -1158,7 +1151,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -1167,9 +1160,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
false, false,
'dd/MM/yyyy' 'dd/MM/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
it("returns datasets when duration is 'week' and date format is 'date_string'", () => { it("returns datasets when duration is 'week' and date format is 'date_string'", () => {
@ -1269,7 +1261,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -1278,9 +1270,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
false, false,
'date_string' 'date_string'
),
expected
) )
).toStrictEqual(expected)
}) })
it('returns datasets after conversion to imperial units', () => { it('returns datasets after conversion to imperial units', () => {
@ -1379,7 +1370,7 @@ describe('formatStats (duration)', () => {
], ],
}, },
} }
assert.deepEqual( expect(
formatStats( formatStats(
inputParams, inputParams,
false, false,
@ -1388,9 +1379,8 @@ describe('formatStats (duration)', () => {
inputStats, inputStats,
true, true,
'MM/dd/yyyy' 'MM/dd/yyyy'
),
expected
) )
).toStrictEqual(expected)
}) })
}) })
@ -1425,14 +1415,9 @@ describe("getStatsDateParams when time frame is 'month')", () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getStatsDateParams( getStatsDateParams(testParams.input.date, 'month', weekStartingMonday)
testParams.input.date, ).toStrictEqual(testParams.expected)
'month',
weekStartingMonday
),
testParams.expected
)
}) })
}) })
}) })
@ -1469,10 +1454,9 @@ describe("getStatsDateParams when time frame is 'year')", () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getStatsDateParams(testParams.input.date, 'year', weekStartingMonday), getStatsDateParams(testParams.input.date, 'year', weekStartingMonday)
testParams.expected ).toStrictEqual(testParams.expected)
)
}) })
}) })
}) })
@ -1537,14 +1521,13 @@ describe("getStatsDateParams when time frame is 'week')", () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
getStatsDateParams( getStatsDateParams(
testParams.input.date, testParams.input.date,
'week', 'week',
testParams.input.weekStartingMonday testParams.input.weekStartingMonday
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -1626,14 +1609,13 @@ describe("updateChartParams when time frame is 'month')", () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
updateChartParams( updateChartParams(
testParams.input.chartParams, testParams.input.chartParams,
testParams.input.backward, testParams.input.backward,
weekStartingMonday weekStartingMonday
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -1712,14 +1694,13 @@ describe("updateChartParams when time frame is 'year')", () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
updateChartParams( updateChartParams(
testParams.input.chartParams, testParams.input.chartParams,
testParams.input.backward, testParams.input.backward,
weekStartingMonday weekStartingMonday
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -1803,14 +1784,13 @@ describe("updateChartParams when time frame is 'week')", () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.deepEqual( expect(
updateChartParams( updateChartParams(
testParams.input.chartParams, testParams.input.chartParams,
testParams.input.backward, testParams.input.backward,
testParams.input.weekStartingMonday testParams.input.weekStartingMonday
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { datasetKeys } from '@/utils/statistics' import { datasetKeys } from '@/utils/statistics'
import { formatTooltipValue } from '@/utils/tooltip' import { formatTooltipValue } from '@/utils/tooltip'
@ -45,14 +45,13 @@ describe('formatTooltipValue', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(
formatTooltipValue( formatTooltipValue(
testParams.inputDisplayedData, testParams.inputDisplayedData,
testParams.inputValue, testParams.inputValue,
false false
),
testParams.expectedResult
) )
).toStrictEqual(testParams.expectedResult)
}) })
}) })
}) })
@ -99,14 +98,13 @@ describe('formatTooltipValue after conversion to imperial units', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(
formatTooltipValue( formatTooltipValue(
testParams.inputDisplayedData, testParams.inputDisplayedData,
testParams.inputValue, testParams.inputValue,
true true
),
testParams.expectedResult
) )
).toStrictEqual(testParams.expectedResult)
}) })
}) })
}) })
@ -145,16 +143,15 @@ describe('formatTooltipValue with unitFrom', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(
formatTooltipValue( formatTooltipValue(
testParams.inputDisplayedData, testParams.inputDisplayedData,
testParams.inputValue, testParams.inputValue,
testParams.useImperialUnits, testParams.useImperialUnits,
true, true,
'm' 'm'
),
testParams.expectedResult
) )
).toStrictEqual(testParams.expectedResult)
}) })
}) })
}) })
@ -201,15 +198,14 @@ describe('formatTooltipValue (formatWithUnits = false)', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
assert.equal( expect(
formatTooltipValue( formatTooltipValue(
testParams.inputDisplayedData, testParams.inputDisplayedData,
testParams.inputValue, testParams.inputValue,
false, false,
false false
),
testParams.expectedResult
) )
).toStrictEqual(testParams.expectedResult)
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { TUnit } from '@/types/units' import { TUnit } from '@/types/units'
import { convertDistance, getTemperature, getWindSpeed } from '@/utils/units' import { convertDistance, getTemperature, getWindSpeed } from '@/utils/units'
@ -26,8 +26,7 @@ describe('convertDistance', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`convert ${testParams[0]}${testParams[1]} in ${testParams[2]}}`, () => { it(`convert ${testParams[0]}${testParams[1]} in ${testParams[2]}}`, () => {
assert.equal( expect(convertDistance(testParams[0], testParams[1], testParams[2])).toBe(
convertDistance(testParams[0], testParams[1], testParams[2]),
testParams[3] testParams[3]
) )
}) })
@ -44,15 +43,14 @@ describe('convertDistance w/ digits', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`convert ${testParams[0]}${testParams[1]} in ${testParams[2]}}`, () => { it(`convert ${testParams[0]}${testParams[1]} in ${testParams[2]}}`, () => {
assert.equal( expect(
convertDistance( convertDistance(
testParams[0], testParams[0],
testParams[1], testParams[1],
testParams[2], testParams[2],
testParams[3] testParams[3]
),
testParams[4]
) )
).toBe(testParams[4])
}) })
}) })
}) })
@ -68,7 +66,7 @@ describe('getTemperature', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`get temperature for input: ${testParams[0]} and imperialUnits: ${testParams[1]}`, () => { it(`get temperature for input: ${testParams[0]} and imperialUnits: ${testParams[1]}`, () => {
assert.equal(getTemperature(testParams[0], testParams[1]), testParams[2]) expect(getTemperature(testParams[0], testParams[1])).toBe(testParams[2])
}) })
}) })
}) })
@ -84,7 +82,7 @@ describe('getWindSpeed', () => {
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`get wind speed for input: ${testParams[0]} and imperialUnits: ${testParams[1]}`, () => { it(`get wind speed for input: ${testParams[0]} and imperialUnits: ${testParams[1]}`, () => {
assert.equal(getWindSpeed(testParams[0], testParams[1]), testParams[2]) expect(getWindSpeed(testParams[0], testParams[1])).toBe(testParams[2])
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import { convertDegreeToDirection } from '@/utils/weather' import { convertDegreeToDirection } from '@/utils/weather'
@ -17,7 +17,7 @@ describe('convertDegreeToDirection', () => {
] ]
testsParams.map((testParams) => { testsParams.map((testParams) => {
it(`convert ${testParams[0]}° to ${testParams[1]}`, () => { it(`convert ${testParams[0]}° to ${testParams[1]}`, () => {
assert.equal(convertDegreeToDirection(testParams[0]), testParams[1]) expect(convertDegreeToDirection(testParams[0])).toBe(testParams[1])
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { assert } from 'chai' import { describe, it, expect } from 'vitest'
import createI18n from '@/i18n' import createI18n from '@/i18n'
import { getDatasets, getDonutDatasets } from '@/utils/workouts' import { getDatasets, getDonutDatasets } from '@/utils/workouts'
@ -172,14 +172,13 @@ describe('getDatasets', () => {
testparams.map((testParams) => { testparams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
locale.value = testParams.inputParams.locale locale.value = testParams.inputParams.locale
assert.deepEqual( expect(
getDatasets( getDatasets(
testParams.inputParams.charData, testParams.inputParams.charData,
t, t,
testParams.inputParams.useImperialUnits testParams.inputParams.useImperialUnits
),
testParams.expected
) )
).toStrictEqual(testParams.expected)
}) })
}) })
}) })
@ -329,9 +328,9 @@ describe('getDonutDatasets', () => {
] ]
testparams.map((testParams) => { testparams.map((testParams) => {
it(testParams.description, () => { it(testParams.description, () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment expect(getDonutDatasets(testParams.input)).toStrictEqual(
// @ts-ignore testParams.expected
assert.deepEqual(getDonutDatasets(testParams.input), testParams.expected) )
}) })
}) })
}) })

View File

@ -6,6 +6,9 @@
}, },
{ {
"path": "./tsconfig.app.json" "path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
} }
], ],
"compilerOptions": { "compilerOptions": {

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
"composite": true,
"lib": [],
"types": ["node", "jsdom"]
}
}

View File

@ -0,0 +1,14 @@
import { fileURLToPath } from 'node:url'
import { mergeConfig, defineConfig, configDefaults } from 'vitest/config'
import viteConfig from './vite.config'
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
},
})
)

File diff suppressed because it is too large Load Diff