Client - display only active sports in application in user preferences

+ fixes
This commit is contained in:
Sam 2021-11-13 12:12:22 +01:00
parent 529adb0403
commit 50094d1fda
34 changed files with 327 additions and 66 deletions

View File

@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"><link rel="stylesheet" href="/static/css/leaflet.css"><title>FitTrackee</title><link href="/static/css/admin.dc8b6d66.css" rel="prefetch"><link href="/static/css/main.411e7bd3.css" rel="prefetch"><link href="/static/css/main~workouts.c8c5694b.css" rel="prefetch"><link href="/static/css/profile.314b1d45.css" rel="prefetch"><link href="/static/css/reset.a71577d5.css" rel="prefetch"><link href="/static/css/workouts.811b57d6.css" rel="prefetch"><link href="/static/js/admin.2f1d393d.js" rel="prefetch"><link href="/static/js/chunk-2d0c9189.c81458cc.js" rel="prefetch"><link href="/static/js/chunk-2d0cf391.020c75ea.js" rel="prefetch"><link href="/static/js/chunk-2d0da8f3.c8c3e7e8.js" rel="prefetch"><link href="/static/js/chunk-2d2248b6.d84473c1.js" rel="prefetch"><link href="/static/js/chunk-2d22523a.4b710d99.js" rel="prefetch"><link href="/static/js/main.db9cee98.js" rel="prefetch"><link href="/static/js/main~workouts.a74990d7.js" rel="prefetch"><link href="/static/js/profile.62578012.js" rel="prefetch"><link href="/static/js/reset.518e646f.js" rel="prefetch"><link href="/static/js/workouts.f44fc0c9.js" rel="prefetch"><link href="/static/css/app.97115085.css" rel="preload" as="style"><link href="/static/js/app.1cea050c.js" rel="preload" as="script"><link href="/static/js/chunk-vendors.71654064.js" rel="preload" as="script"><link href="/static/css/app.97115085.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/static/js/chunk-vendors.71654064.js"></script><script src="/static/js/app.1cea050c.js"></script></body></html> <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"><link rel="stylesheet" href="/static/css/leaflet.css"><title>FitTrackee</title><link href="/static/css/admin.babfd43e.css" rel="prefetch"><link href="/static/css/main.7229c1ab.css" rel="prefetch"><link href="/static/css/main~workouts.0edb3403.css" rel="prefetch"><link href="/static/css/profile.05400f70.css" rel="prefetch"><link href="/static/css/reset.46776e72.css" rel="prefetch"><link href="/static/css/workouts.1b0a7916.css" rel="prefetch"><link href="/static/js/admin.2f1d393d.js" rel="prefetch"><link href="/static/js/chunk-2d0c9189.c81458cc.js" rel="prefetch"><link href="/static/js/chunk-2d0cf391.020c75ea.js" rel="prefetch"><link href="/static/js/chunk-2d0da8f3.c8c3e7e8.js" rel="prefetch"><link href="/static/js/chunk-2d2248b6.d84473c1.js" rel="prefetch"><link href="/static/js/chunk-2d22523a.4b710d99.js" rel="prefetch"><link href="/static/js/main.db9cee98.js" rel="prefetch"><link href="/static/js/main~workouts.a74990d7.js" rel="prefetch"><link href="/static/js/profile.62578012.js" rel="prefetch"><link href="/static/js/reset.518e646f.js" rel="prefetch"><link href="/static/js/workouts.d69cf48a.js" rel="prefetch"><link href="/static/css/app.f5a49827.css" rel="preload" as="style"><link href="/static/js/app.4af713c5.js" rel="preload" as="script"><link href="/static/js/chunk-vendors.71654064.js" rel="preload" as="script"><link href="/static/css/app.f5a49827.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/static/js/chunk-vendors.71654064.js"></script><script src="/static/js/app.4af713c5.js"></script></body></html>

View File

@ -64,7 +64,7 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/img/workouts/mountains.svg" "url": "/img/workouts/mountains.svg"
}, },
{ {
"revision": "b25a1a86fb5897d7e1aa7c29ab6c767a", "revision": "e1822eea53975be4c7802859ebb65de1",
"url": "/index.html" "url": "/index.html"
}, },
{ {
@ -76,12 +76,12 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/robots.txt" "url": "/robots.txt"
}, },
{ {
"revision": "55e1f50bd31cac2908e3", "revision": "33002d1c4452ecd02e50",
"url": "/static/css/admin.dc8b6d66.css" "url": "/static/css/admin.babfd43e.css"
}, },
{ {
"revision": "e9224bbb1b4b15d1c11d", "revision": "592aef69082002fccf26",
"url": "/static/css/app.97115085.css" "url": "/static/css/app.f5a49827.css"
}, },
{ {
"revision": "82c1118c918377daaa71a320ab8eea42", "revision": "82c1118c918377daaa71a320ab8eea42",
@ -92,24 +92,24 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/css/leaflet.css" "url": "/static/css/leaflet.css"
}, },
{ {
"revision": "be5a37c7e9ea6bfcb8d7", "revision": "00c35b353719122c16cd",
"url": "/static/css/main.411e7bd3.css" "url": "/static/css/main.7229c1ab.css"
}, },
{ {
"revision": "ce60ed388b792b0e9a0e", "revision": "11b770a11a1cd8dae5f4",
"url": "/static/css/main~workouts.c8c5694b.css" "url": "/static/css/main~workouts.0edb3403.css"
}, },
{ {
"revision": "74137feddeb35e2de067", "revision": "058a877bc4b9cbf8929f",
"url": "/static/css/profile.314b1d45.css" "url": "/static/css/profile.05400f70.css"
}, },
{ {
"revision": "6066a5f13daad652feea", "revision": "8635e7636aa413afd289",
"url": "/static/css/reset.a71577d5.css" "url": "/static/css/reset.46776e72.css"
}, },
{ {
"revision": "152a2e4eea88a89fbd00", "revision": "c78ff76a4bb0919c4b94",
"url": "/static/css/workouts.811b57d6.css" "url": "/static/css/workouts.1b0a7916.css"
}, },
{ {
"revision": "e719f9244c69e28e7d00e725ca1e280e", "revision": "e719f9244c69e28e7d00e725ca1e280e",
@ -192,12 +192,12 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/img/pt-sans-v9-latin-regular.f1f73e45.svg" "url": "/static/img/pt-sans-v9-latin-regular.f1f73e45.svg"
}, },
{ {
"revision": "55e1f50bd31cac2908e3", "revision": "33002d1c4452ecd02e50",
"url": "/static/js/admin.2f1d393d.js" "url": "/static/js/admin.2f1d393d.js"
}, },
{ {
"revision": "e9224bbb1b4b15d1c11d", "revision": "592aef69082002fccf26",
"url": "/static/js/app.1cea050c.js" "url": "/static/js/app.4af713c5.js"
}, },
{ {
"revision": "bd7d183c9f68e5f4027d", "revision": "bd7d183c9f68e5f4027d",
@ -224,23 +224,23 @@ self.__precacheManifest = (self.__precacheManifest || []).concat([
"url": "/static/js/chunk-vendors.71654064.js" "url": "/static/js/chunk-vendors.71654064.js"
}, },
{ {
"revision": "be5a37c7e9ea6bfcb8d7", "revision": "00c35b353719122c16cd",
"url": "/static/js/main.db9cee98.js" "url": "/static/js/main.db9cee98.js"
}, },
{ {
"revision": "ce60ed388b792b0e9a0e", "revision": "11b770a11a1cd8dae5f4",
"url": "/static/js/main~workouts.a74990d7.js" "url": "/static/js/main~workouts.a74990d7.js"
}, },
{ {
"revision": "74137feddeb35e2de067", "revision": "058a877bc4b9cbf8929f",
"url": "/static/js/profile.62578012.js" "url": "/static/js/profile.62578012.js"
}, },
{ {
"revision": "6066a5f13daad652feea", "revision": "8635e7636aa413afd289",
"url": "/static/js/reset.518e646f.js" "url": "/static/js/reset.518e646f.js"
}, },
{ {
"revision": "152a2e4eea88a89fbd00", "revision": "c78ff76a4bb0919c4b94",
"url": "/static/js/workouts.f44fc0c9.js" "url": "/static/js/workouts.d69cf48a.js"
} }
]); ]);

View File

@ -14,7 +14,7 @@
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
importScripts( importScripts(
"/precache-manifest.c464572cf53279a4a77a0b894d8a1e6c.js" "/precache-manifest.ddc2833e5b0364615f3352c5edfaec71.js"
); );
workbox.core.setCacheNameDetails({prefix: "fittrackee_client"}); workbox.core.setCacheNameDetails({prefix: "fittrackee_client"});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -24,7 +24,7 @@
</thead> </thead>
<tbody> <tbody>
<tr v-for="sport in translatedSports" :key="sport.id"> <tr v-for="sport in translatedSports" :key="sport.id">
<td class="center-text"> <td class="text-center">
<span class="cell-heading">id</span> <span class="cell-heading">id</span>
{{ sport.id }} {{ sport.id }}
</td> </td>
@ -44,12 +44,12 @@
</span> </span>
{{ sport.translatedLabel }} {{ sport.translatedLabel }}
</td> </td>
<td class="center-text"> <td class="text-center">
<span class="cell-heading"> <span class="cell-heading">
{{ $t('admin.SPORTS.TABLE.ACTIVE') }} {{ $t('admin.SPORTS.TABLE.ACTIVE') }}
</span> </span>
<i <i
:class="`fa fa${sport.is_active ? '-check' : ''}-square-o`" :class="`fa fa${sport.is_active ? '-check' : ''}`"
aria-hidden="true" aria-hidden="true"
/> />
</td> </td>

View File

@ -63,13 +63,13 @@
) )
}} }}
</td> </td>
<td class="center-text"> <td class="text-center">
<span class="cell-heading"> <span class="cell-heading">
{{ capitalize($t('workouts.WORKOUT', 0)) }} {{ capitalize($t('workouts.WORKOUT', 0)) }}
</span> </span>
{{ user.nb_workouts }} {{ user.nb_workouts }}
</td> </td>
<td class="center-text"> <td class="text-center">
<span class="cell-heading"> <span class="cell-heading">
{{ $t('user.ADMIN') }} {{ $t('user.ADMIN') }}
</span> </span>
@ -78,7 +78,7 @@
aria-hidden="true" aria-hidden="true"
/> />
</td> </td>
<td class="center-text"> <td class="text-center">
<span class="cell-heading"> <span class="cell-heading">
{{ $t('admin.ACTION') }} {{ $t('admin.ACTION') }}
</span> </span>

View File

@ -22,6 +22,7 @@
<tr> <tr>
<th>{{ $t('user.PROFILE.SPORT.COLOR') }}</th> <th>{{ $t('user.PROFILE.SPORT.COLOR') }}</th>
<th class="text-left">{{ $t('workouts.SPORT', 0) }}</th> <th class="text-left">{{ $t('workouts.SPORT', 0) }}</th>
<th>{{ $t('workouts.WORKOUT', 0) }}</th>
<th>{{ $t('user.PROFILE.SPORT.IS_ACTIVE') }}</th> <th>{{ $t('user.PROFILE.SPORT.IS_ACTIVE') }}</th>
<th>{{ $t('user.PROFILE.SPORT.STOPPED_SPEED_THRESHOLD') }}</th> <th>{{ $t('user.PROFILE.SPORT.STOPPED_SPEED_THRESHOLD') }}</th>
<th v-if="isEdition">{{ $t('user.PROFILE.SPORT.ACTION') }}</th> <th v-if="isEdition">{{ $t('user.PROFILE.SPORT.ACTION') }}</th>
@ -47,11 +48,17 @@
:color="sport.color ? sport.color : sportColors[sport.label]" :color="sport.color ? sport.color : sportColors[sport.label]"
/> />
</td> </td>
<td class="sport-label"> <td
class="sport-label"
:class="{ 'disabled-sport': !sport.is_active }"
>
<span class="cell-heading"> <span class="cell-heading">
{{ $t('user.PROFILE.SPORT.LABEL') }} {{ $t('user.PROFILE.SPORT.LABEL') }}
</span> </span>
{{ sport.translatedLabel }} {{ sport.translatedLabel }}
<span class="disabled-message" v-if="!sport.is_active">
({{ $t('user.PROFILE.SPORT.DISABLED_BY_ADMIN') }})
</span>
<i <i
v-if="loading && isSportInEdition(sport.id)" v-if="loading && isSportInEdition(sport.id)"
class="fa fa-refresh fa-spin fa-fw" class="fa fa-refresh fa-spin fa-fw"
@ -61,31 +68,49 @@
v-if="errorMessages && sportPayload.sport_id === sport.id" v-if="errorMessages && sportPayload.sport_id === sport.id"
/> />
</td> </td>
<td class="text-center"> <td
class="text-center"
:class="{ 'disabled-sport': !sport.is_active }"
>
<span class="cell-heading">
{{ $t('workouts.WORKOUT', 0) }}
</span>
<i
:class="`fa fa${
user.sports_list.includes(sport.id) ? '-check' : ''
}`"
aria-hidden="true"
/>
</td>
<td
class="text-center"
:class="{ 'disabled-sport': !sport.is_active }"
>
<span class="cell-heading"> <span class="cell-heading">
{{ $t('user.PROFILE.SPORT.IS_ACTIVE') }} {{ $t('user.PROFILE.SPORT.IS_ACTIVE') }}
</span> </span>
<input <input
v-if="isSportInEdition(sport.id)" v-if="isSportInEdition(sport.id) && sport.is_active"
type="checkbox" type="checkbox"
:checked="sport.is_active_for_user" :checked="sport.is_active_for_user"
@change="updateIsActive" @change="updateIsActive"
/> />
<i <i
v-else v-else
:class="`fa fa${ :class="`fa fa${sport.is_active_for_user ? '-check' : ''}`"
sport.is_active_for_user ? '-check' : ''
}-square-o`"
aria-hidden="true" aria-hidden="true"
/> />
</td> </td>
<td class="text-center"> <td
class="text-center"
:class="{ 'disabled-sport': !sport.is_active }"
>
<span class="cell-heading"> <span class="cell-heading">
{{ $t('user.PROFILE.SPORT.STOPPED_SPEED_THRESHOLD') }} {{ $t('user.PROFILE.SPORT.STOPPED_SPEED_THRESHOLD') }}
</span> </span>
<input <input
class="threshold-input" class="threshold-input"
v-if="isSportInEdition(sport.id)" v-if="isSportInEdition(sport.id) && sport.is_active"
type="number" type="number"
min="0" min="0"
step="0.1" step="0.1"
@ -139,11 +164,12 @@
import { AUTH_USER_STORE, ROOT_STORE, SPORTS_STORE } from '@/store/constants' import { AUTH_USER_STORE, ROOT_STORE, SPORTS_STORE } from '@/store/constants'
import { ISport, ITranslatedSport } from '@/types/sports' import { ISport, ITranslatedSport } from '@/types/sports'
import { IUserSportPreferencesPayload } from '@/types/user' import { IUserProfile, IUserSportPreferencesPayload } from '@/types/user'
import { useStore } from '@/use/useStore' import { useStore } from '@/use/useStore'
import { translateSports } from '@/utils/sports' import { translateSports } from '@/utils/sports'
interface Props { interface Props {
user: IUserProfile
isEdition: boolean isEdition: boolean
} }
const props = defineProps<Props>() const props = defineProps<Props>()
@ -151,13 +177,13 @@
const store = useStore() const store = useStore()
const { t } = useI18n() const { t } = useI18n()
const { isEdition } = toRefs(props) const { isEdition, user } = toRefs(props)
const sportColors = inject('sportColors') const sportColors = inject('sportColors')
const sports: ComputedRef<ISport[]> = computed( const sports: ComputedRef<ISport[]> = computed(
() => store.getters[SPORTS_STORE.GETTERS.SPORTS] () => store.getters[SPORTS_STORE.GETTERS.SPORTS]
) )
const translatedSports: ComputedRef<ITranslatedSport[]> = computed(() => const translatedSports: ComputedRef<ITranslatedSport[]> = computed(() =>
translateSports(sports.value, t) translateSports(sports.value, t, true, user.value.sports_list)
) )
const loading = computed( const loading = computed(
() => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING] () => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING]
@ -236,6 +262,17 @@
.sport-label { .sport-label {
width: 170px; width: 170px;
} }
.disabled-sport {
font-style: italic;
color: var(--disabled-sport-color);
.disabled-message {
font-size: 0.9em;
}
.cell-heading {
font-style: normal;
}
}
.action-buttons { .action-buttons {
width: 70px; width: 70px;
} }

View File

@ -259,7 +259,12 @@
const { workout, isCreation, loading } = toRefs(props) const { workout, isCreation, loading } = toRefs(props)
const translatedSports: ComputedRef<ISport[]> = computed(() => const translatedSports: ComputedRef<ISport[]> = computed(() =>
translateSports(props.sports, t, true) translateSports(
props.sports,
t,
true,
workout.value.id ? [workout.value.sport_id] : null
)
) )
const appConfig: ComputedRef<TAppConfig> = computed( const appConfig: ComputedRef<TAppConfig> = computed(
() => store.getters[ROOT_STORE.GETTERS.APP_CONFIG] () => store.getters[ROOT_STORE.GETTERS.APP_CONFIG]

View File

@ -48,6 +48,7 @@
"SPORT": { "SPORT": {
"ACTION": "action", "ACTION": "action",
"COLOR": "color", "COLOR": "color",
"DISABLED_BY_ADMIN": "disabled by admin",
"IS_ACTIVE": "active", "IS_ACTIVE": "active",
"LABEL": "label", "LABEL": "label",
"STOPPED_SPEED_THRESHOLD": "stopped speed threshold" "STOPPED_SPEED_THRESHOLD": "stopped speed threshold"

View File

@ -48,6 +48,7 @@
"SPORT": { "SPORT": {
"ACTION": "action", "ACTION": "action",
"COLOR": "couleur", "COLOR": "couleur",
"DISABLED_BY_ADMIN": "désactivé par l'administrateur",
"IS_ACTIVE": "actif", "IS_ACTIVE": "actif",
"LABEL": "label", "LABEL": "label",
"STOPPED_SPEED_THRESHOLD": "seuil de vitesse arrêtée" "STOPPED_SPEED_THRESHOLD": "seuil de vitesse arrêtée"

View File

@ -53,6 +53,7 @@
--disabled-background-color: #e0e0e0; --disabled-background-color: #e0e0e0;
--disabled-color: #a3a3a3; --disabled-color: #a3a3a3;
--disabled-sport-color: #616161;
--scroll-button-bg-color: rgba(255, 255, 255, .7); --scroll-button-bg-color: rgba(255, 255, 255, .7);

View File

@ -38,10 +38,17 @@ const sortSports = (a: ITranslatedSport, b: ITranslatedSport): number => {
export const translateSports = ( export const translateSports = (
sports: ISport[], sports: ISport[],
t: CallableFunction, t: CallableFunction,
onlyActive = false onlyActive = false,
userSports: number[] | null = null
): ITranslatedSport[] => ): ITranslatedSport[] =>
sports sports
.filter((sport) => (onlyActive ? sport.is_active_for_user : true)) .filter((sport) =>
onlyActive
? userSports === null
? sport.is_active_for_user
: userSports.includes(sport.id) || sport.is_active
: true
)
.map((sport) => ({ .map((sport) => ({
...sport, ...sport,
translatedLabel: t(`sports.${sport.label}.LABEL`), translatedLabel: t(`sports.${sport.label}.LABEL`),

View File

@ -16,7 +16,7 @@ export const sports: ISport[] = [
}, },
{ {
color: '#000000', color: '#000000',
has_workouts: false, has_workouts: true,
id: 2, id: 2,
img: '/img/sports/cycling-transport.png', img: '/img/sports/cycling-transport.png',
is_active: false, is_active: false,

View File

@ -7,7 +7,7 @@ import { translateSports } from '@/utils/sports'
const { t, locale } = createI18n.global const { t, locale } = createI18n.global
describe('sortSports', () => { describe('translateSports', () => {
const testsParams = [ const testsParams = [
{ {
description: "returns sorted all translated sports (with 'en' locale)", description: "returns sorted all translated sports (with 'en' locale)",
@ -15,6 +15,7 @@ describe('sortSports', () => {
sports, sports,
locale: 'en', locale: 'en',
onlyActive: false, onlyActive: false,
userSports: null,
}, },
expected: [ expected: [
{ {
@ -30,7 +31,7 @@ describe('sortSports', () => {
}, },
{ {
color: '#000000', color: '#000000',
has_workouts: false, has_workouts: true,
id: 2, id: 2,
img: '/img/sports/cycling-transport.png', img: '/img/sports/cycling-transport.png',
is_active: false, is_active: false,
@ -54,11 +55,12 @@ describe('sortSports', () => {
}, },
{ {
description: description:
"returns sorted only active translated sports (with 'en' locales)", "returns sorted only translated sports, active for user (with 'en' locales)",
inputParams: { inputParams: {
sports, sports,
locale: 'en', locale: 'en',
onlyActive: true, onlyActive: true,
userSports: null,
}, },
expected: [ expected: [
{ {
@ -80,6 +82,7 @@ describe('sortSports', () => {
sports: [], sports: [],
locale: 'en', locale: 'en',
onlyActive: false, onlyActive: false,
userSports: null,
}, },
expected: [], expected: [],
}, },
@ -89,6 +92,7 @@ describe('sortSports', () => {
sports, sports,
locale: 'fr', locale: 'fr',
onlyActive: false, onlyActive: false,
userSports: [],
}, },
expected: [ expected: [
{ {
@ -115,7 +119,7 @@ describe('sortSports', () => {
}, },
{ {
color: '#000000', color: '#000000',
has_workouts: false, has_workouts: true,
id: 2, id: 2,
img: '/img/sports/cycling-transport.png', img: '/img/sports/cycling-transport.png',
is_active: false, is_active: false,
@ -128,11 +132,12 @@ describe('sortSports', () => {
}, },
{ {
description: description:
"returns sorted only active translated sports (with 'fr' locales)", "returns sorted only translated sports, active for user (with 'fr' locales)",
inputParams: { inputParams: {
sports, sports,
locale: 'fr', locale: 'fr',
onlyActive: true, onlyActive: true,
userSports: null,
}, },
expected: [ expected: [
{ {
@ -154,6 +159,209 @@ describe('sortSports', () => {
sports: [], sports: [],
locale: 'fr', locale: 'fr',
onlyActive: false, onlyActive: false,
userSports: null,
},
expected: [],
},
{
description:
"returns sorted all translated sports, even with user sports list provided (with 'en' locale)",
inputParams: {
sports,
locale: 'en',
onlyActive: false,
userSports: [2],
},
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',
onlyActive: true,
userSports: [2],
},
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',
onlyActive: false,
userSports: null,
},
expected: [],
},
{
description:
"returns sorted all translated sports, even with user sports list provided (with 'fr' locale)",
inputParams: {
sports,
locale: 'fr',
onlyActive: false,
userSports: [2],
},
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',
onlyActive: true,
userSports: [2],
},
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',
onlyActive: false,
userSports: [2],
}, },
expected: [], expected: [],
}, },
@ -165,7 +373,8 @@ describe('sortSports', () => {
translateSports( translateSports(
testParams.inputParams.sports, testParams.inputParams.sports,
t, t,
testParams.inputParams.onlyActive testParams.inputParams.onlyActive,
testParams.inputParams.userSports
), ),
testParams.expected testParams.expected
) )