Client - display only active sports (+ workout sport) on workout edition
fix #129
This commit is contained in:
@ -3,19 +3,33 @@ import { assert } from 'chai'
|
||||
import { sports } from './fixtures'
|
||||
|
||||
import createI18n from '@/i18n'
|
||||
import { ISport, TActiveStatus } from '@/types/sports'
|
||||
import { translateSports } from '@/utils/sports'
|
||||
|
||||
const { t, locale } = createI18n.global
|
||||
|
||||
interface IInputParam {
|
||||
sports: ISport[]
|
||||
locale: string
|
||||
activeStatus: TActiveStatus
|
||||
sportsToInclude: number[]
|
||||
}
|
||||
|
||||
interface ITestParameter {
|
||||
description: string
|
||||
inputParams: IInputParam
|
||||
expected: Record<never, never>[]
|
||||
}
|
||||
|
||||
describe('translateSports', () => {
|
||||
const testsParams = [
|
||||
const testsParams: ITestParameter[] = [
|
||||
{
|
||||
description: "returns sorted all translated sports (with 'en' locale)",
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'en',
|
||||
onlyActive: false,
|
||||
userSports: null,
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -55,12 +69,46 @@ describe('translateSports', () => {
|
||||
},
|
||||
{
|
||||
description:
|
||||
"returns sorted only translated sports, active for user (with 'en' locales)",
|
||||
"returns sorted only active translated sports (with 'en' locales)",
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'en',
|
||||
onlyActive: true,
|
||||
userSports: null,
|
||||
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)",
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'en',
|
||||
activeStatus: 'is_active_for_user',
|
||||
sportsToInclude: [],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -77,12 +125,12 @@ describe('translateSports', () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "returns empty array (with 'en' locale)",
|
||||
description: "returns empty array if not sports (with 'en' locale)",
|
||||
inputParams: {
|
||||
sports: [],
|
||||
locale: 'en',
|
||||
onlyActive: false,
|
||||
userSports: null,
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [],
|
||||
},
|
||||
expected: [],
|
||||
},
|
||||
@ -91,8 +139,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'fr',
|
||||
onlyActive: false,
|
||||
userSports: [],
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -132,12 +180,46 @@ describe('translateSports', () => {
|
||||
},
|
||||
{
|
||||
description:
|
||||
"returns sorted only translated sports, active for user (with 'fr' locales)",
|
||||
"returns sorted only active translated sports (with 'fr' locales)",
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'fr',
|
||||
onlyActive: true,
|
||||
userSports: null,
|
||||
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)",
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'fr',
|
||||
activeStatus: 'is_active_for_user',
|
||||
sportsToInclude: [],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -154,12 +236,12 @@ describe('translateSports', () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "returns empty array (with 'fr' locale)",
|
||||
description: "returns empty array if not sports (with 'fr' locale)",
|
||||
inputParams: {
|
||||
sports: [],
|
||||
locale: 'fr',
|
||||
onlyActive: false,
|
||||
userSports: null,
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [],
|
||||
},
|
||||
expected: [],
|
||||
},
|
||||
@ -169,8 +251,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'en',
|
||||
onlyActive: false,
|
||||
userSports: [2],
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [2],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -214,8 +296,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'en',
|
||||
onlyActive: true,
|
||||
userSports: [2],
|
||||
activeStatus: 'is_active',
|
||||
sportsToInclude: [2],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -259,8 +341,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports: [],
|
||||
locale: 'en',
|
||||
onlyActive: false,
|
||||
userSports: null,
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [2],
|
||||
},
|
||||
expected: [],
|
||||
},
|
||||
@ -270,8 +352,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'fr',
|
||||
onlyActive: false,
|
||||
userSports: [2],
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [2],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -315,8 +397,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports,
|
||||
locale: 'fr',
|
||||
onlyActive: true,
|
||||
userSports: [2],
|
||||
activeStatus: 'is_active',
|
||||
sportsToInclude: [2],
|
||||
},
|
||||
expected: [
|
||||
{
|
||||
@ -360,8 +442,8 @@ describe('translateSports', () => {
|
||||
inputParams: {
|
||||
sports: [],
|
||||
locale: 'fr',
|
||||
onlyActive: false,
|
||||
userSports: [2],
|
||||
activeStatus: 'all',
|
||||
sportsToInclude: [2],
|
||||
},
|
||||
expected: [],
|
||||
},
|
||||
@ -373,8 +455,8 @@ describe('translateSports', () => {
|
||||
translateSports(
|
||||
testParams.inputParams.sports,
|
||||
t,
|
||||
testParams.inputParams.onlyActive,
|
||||
testParams.inputParams.userSports
|
||||
testParams.inputParams.activeStatus,
|
||||
testParams.inputParams.sportsToInclude
|
||||
),
|
||||
testParams.expected
|
||||
)
|
||||
|
Reference in New Issue
Block a user