2023-11-11 17:12:20 +01:00
|
|
|
import { describe, it, expect } from 'vitest'
|
2021-09-22 10:39:25 +02:00
|
|
|
|
2021-09-25 11:28:40 +02:00
|
|
|
import { sports } from './fixtures'
|
2021-09-22 10:39:25 +02:00
|
|
|
|
|
|
|
import createI18n from '@/i18n'
|
2022-01-01 18:33:06 +01:00
|
|
|
import { ISport, TActiveStatus } from '@/types/sports'
|
2021-09-22 10:39:25 +02:00
|
|
|
import { translateSports } from '@/utils/sports'
|
|
|
|
|
|
|
|
const { t, locale } = createI18n.global
|
|
|
|
|
2022-01-01 18:33:06 +01:00
|
|
|
interface IInputParam {
|
|
|
|
sports: ISport[]
|
|
|
|
locale: string
|
|
|
|
activeStatus: TActiveStatus
|
|
|
|
sportsToInclude: number[]
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ITestParameter {
|
|
|
|
description: string
|
|
|
|
inputParams: IInputParam
|
|
|
|
expected: Record<never, never>[]
|
|
|
|
}
|
|
|
|
|
2021-11-13 12:12:22 +01:00
|
|
|
describe('translateSports', () => {
|
2022-01-01 18:33:06 +01:00
|
|
|
const testsParams: ITestParameter[] = [
|
2021-09-22 10:39:25 +02:00
|
|
|
{
|
|
|
|
description: "returns sorted all translated sports (with 'en' locale)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'en',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
2021-10-01 16:48:48 +02:00
|
|
|
expected: [
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-10-01 16:48:48 +02:00
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: true,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Sport)',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Cycling (Sport)',
|
|
|
|
},
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: '#000000',
|
2021-11-13 12:12:22 +01:00
|
|
|
has_workouts: true,
|
2021-10-01 16:48:48 +02:00
|
|
|
id: 2,
|
|
|
|
img: '/img/sports/cycling-transport.png',
|
|
|
|
is_active: false,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: false,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Transport)',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Cycling (Transport)',
|
|
|
|
},
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-10-01 16:48:48 +02:00
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: false,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Hiking',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 0.1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Hiking',
|
|
|
|
},
|
|
|
|
],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
2022-01-01 18:33:06 +01:00
|
|
|
"returns sorted only active translated sports (with 'en' locales)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'en',
|
|
|
|
activeStatus: 'is_active',
|
|
|
|
sportsToInclude: [],
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: true,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Cycling (Sport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Hiking',
|
|
|
|
stopped_speed_threshold: 0.1,
|
|
|
|
translatedLabel: 'Hiking',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns sorted translated sports active for user (with 'en' locales)",
|
2021-09-22 10:39:25 +02:00
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'en',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'is_active_for_user',
|
|
|
|
sportsToInclude: [],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-09-22 10:39:25 +02:00
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: true,
|
2021-09-22 10:39:25 +02:00
|
|
|
label: 'Cycling (Sport)',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Cycling (Sport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2022-01-01 18:33:06 +01:00
|
|
|
description: "returns empty array if not sports (with 'en' locale)",
|
2021-09-22 10:39:25 +02:00
|
|
|
inputParams: {
|
|
|
|
sports: [],
|
|
|
|
locale: 'en',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "returns sorted all translated sports (with 'fr' locale)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'fr',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-09-22 10:39:25 +02:00
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: false,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Hiking',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 0.1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Randonnée',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-09-22 10:39:25 +02:00
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: true,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Sport)',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Vélo (Sport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: '#000000',
|
2021-11-13 12:12:22 +01:00
|
|
|
has_workouts: true,
|
2021-09-22 10:39:25 +02:00
|
|
|
id: 2,
|
|
|
|
img: '/img/sports/cycling-transport.png',
|
|
|
|
is_active: false,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: false,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Transport)',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Vélo (Transport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
2022-01-01 18:33:06 +01:00
|
|
|
"returns sorted only active translated sports (with 'fr' locales)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'fr',
|
|
|
|
activeStatus: 'is_active',
|
|
|
|
sportsToInclude: [],
|
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Hiking',
|
|
|
|
stopped_speed_threshold: 0.1,
|
|
|
|
translatedLabel: 'Randonnée',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: true,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Vélo (Sport)',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns sorted translated sports, active for user (with 'fr' locales)",
|
2021-09-22 10:39:25 +02:00
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'fr',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'is_active_for_user',
|
|
|
|
sportsToInclude: [],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
2021-11-12 18:52:08 +01:00
|
|
|
color: null,
|
2021-09-22 10:39:25 +02:00
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
2021-11-12 18:52:08 +01:00
|
|
|
is_active_for_user: true,
|
2021-10-01 16:48:48 +02:00
|
|
|
label: 'Cycling (Sport)',
|
2021-11-12 18:52:08 +01:00
|
|
|
stopped_speed_threshold: 1,
|
2021-10-01 16:48:48 +02:00
|
|
|
translatedLabel: 'Vélo (Sport)',
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2022-01-01 18:33:06 +01:00
|
|
|
description: "returns empty array if not sports (with 'fr' locale)",
|
2021-09-22 10:39:25 +02:00
|
|
|
inputParams: {
|
|
|
|
sports: [],
|
|
|
|
locale: 'fr',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [],
|
2021-11-13 12:12:22 +01:00
|
|
|
},
|
|
|
|
expected: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns sorted all translated sports, even with user sports list provided (with 'en' locale)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'en',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [2],
|
2021-11-13 12:12:22 +01:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: true,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Cycling (Sport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: '#000000',
|
|
|
|
has_workouts: true,
|
|
|
|
id: 2,
|
|
|
|
img: '/img/sports/cycling-transport.png',
|
|
|
|
is_active: false,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Cycling (Transport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Cycling (Transport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Hiking',
|
|
|
|
stopped_speed_threshold: 0.1,
|
|
|
|
translatedLabel: 'Hiking',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns sorted only translated sports active on application and sports with user workouts (with 'en' locales)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'en',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'is_active',
|
|
|
|
sportsToInclude: [2],
|
2021-11-13 12:12:22 +01:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: true,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Cycling (Sport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: '#000000',
|
|
|
|
has_workouts: true,
|
|
|
|
id: 2,
|
|
|
|
img: '/img/sports/cycling-transport.png',
|
|
|
|
is_active: false,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Cycling (Transport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Cycling (Transport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Hiking',
|
|
|
|
stopped_speed_threshold: 0.1,
|
|
|
|
translatedLabel: 'Hiking',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns empty array, with user sports list provided (with 'en' locale)",
|
|
|
|
inputParams: {
|
|
|
|
sports: [],
|
|
|
|
locale: 'en',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [2],
|
2021-11-13 12:12:22 +01:00
|
|
|
},
|
|
|
|
expected: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns sorted all translated sports, even with user sports list provided (with 'fr' locale)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'fr',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [2],
|
2021-11-13 12:12:22 +01:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Hiking',
|
|
|
|
stopped_speed_threshold: 0.1,
|
|
|
|
translatedLabel: 'Randonnée',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: true,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Vélo (Sport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: '#000000',
|
|
|
|
has_workouts: true,
|
|
|
|
id: 2,
|
|
|
|
img: '/img/sports/cycling-transport.png',
|
|
|
|
is_active: false,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Cycling (Transport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Vélo (Transport)',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns sorted only translated sports active on application and sports with user workouts (with 'fr' locales)",
|
|
|
|
inputParams: {
|
|
|
|
sports,
|
|
|
|
locale: 'fr',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'is_active',
|
|
|
|
sportsToInclude: [2],
|
2021-11-13 12:12:22 +01:00
|
|
|
},
|
|
|
|
expected: [
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: true,
|
|
|
|
id: 3,
|
|
|
|
img: '/img/sports/hiking.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Hiking',
|
|
|
|
stopped_speed_threshold: 0.1,
|
|
|
|
translatedLabel: 'Randonnée',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: null,
|
|
|
|
has_workouts: false,
|
|
|
|
id: 1,
|
|
|
|
img: '/img/sports/cycling-sport.png',
|
|
|
|
is_active: true,
|
|
|
|
is_active_for_user: true,
|
|
|
|
label: 'Cycling (Sport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Vélo (Sport)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: '#000000',
|
|
|
|
has_workouts: true,
|
|
|
|
id: 2,
|
|
|
|
img: '/img/sports/cycling-transport.png',
|
|
|
|
is_active: false,
|
|
|
|
is_active_for_user: false,
|
|
|
|
label: 'Cycling (Transport)',
|
|
|
|
stopped_speed_threshold: 1,
|
|
|
|
translatedLabel: 'Vélo (Transport)',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"returns empty array, with user sports list provided (with 'fr' locale)",
|
|
|
|
inputParams: {
|
|
|
|
sports: [],
|
|
|
|
locale: 'fr',
|
2022-01-01 18:33:06 +01:00
|
|
|
activeStatus: 'all',
|
|
|
|
sportsToInclude: [2],
|
2021-09-22 10:39:25 +02:00
|
|
|
},
|
|
|
|
expected: [],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
testsParams.map((testParams) => {
|
|
|
|
it(testParams.description, () => {
|
|
|
|
locale.value = testParams.inputParams.locale
|
2023-11-11 17:12:20 +01:00
|
|
|
expect(
|
2021-09-22 10:39:25 +02:00
|
|
|
translateSports(
|
|
|
|
testParams.inputParams.sports,
|
|
|
|
t,
|
2022-01-01 18:33:06 +01:00
|
|
|
testParams.inputParams.activeStatus,
|
|
|
|
testParams.inputParams.sportsToInclude
|
2023-11-11 17:12:20 +01:00
|
|
|
)
|
|
|
|
).toStrictEqual(testParams.expected)
|
2021-09-22 10:39:25 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|