Newer
Older
import { Season } from 'enum/ecogesture.enum'
import { FluidType } from 'enum/fluid.enum'
import { FluidSlugType } from 'enum/fluidSlug.enum'
import {
formatNumberValues,
getChallengeTitleWithLineReturn,
getFluidType,
getMonthNameWithPrep,
describe('utils test', () => {
it('should the electricity fluid type', () => {
const result = getFluidType('eLectRicity')
expect(result).toBe(FluidType.ELECTRICITY)
})
it('should the water fluid type', () => {
const result = getFluidType('WatER')
expect(result).toBe(FluidType.WATER)
})
it('should the gas fluid type', () => {
const result = getFluidType('gas')
expect(result).toBe(FluidType.GAS)
})
})
describe('getKonnectorSlug', () => {
it('should return correct slug for elec', () => {
const slug = getKonnectorSlug(FluidType.ELECTRICITY)
expect(slug).toBe(FluidSlugType.ELECTRICITY)
})
it('should return correct slug for water', () => {
const slug = getKonnectorSlug(FluidType.WATER)
expect(slug).toBe(FluidSlugType.WATER)
})
it('should return correct slug for gas', () => {
const slug = getKonnectorSlug(FluidType.GAS)
expect(slug).toBe(FluidSlugType.GAS)
})
})
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
describe('formatNumberValues test', () => {
it('should return --,-- if there is not value', () => {
const result = formatNumberValues(null)
expect(result).toBe('--,--')
})
it('should return a value at english number format two digits decimal', () => {
const result = formatNumberValues(2000.555)
expect(result).toEqual('2 000,56')
})
it('should return a float value', () => {
const result = formatNumberValues(2000.55, '', true)
expect(result).toEqual(2000)
})
})
describe('getSeason test', () => {
it('should return summer', () => {
const now = DateTime.local().setZone('utc', {
keepLocalTime: true,
})
jest
.spyOn(DateTime, 'local')
.mockReturnValueOnce(now.set({ day: 12, month: 6, year: 2021 }))
const result = getSeason()
expect(result).toBe(Season.SUMMER)
})
it('should return winter', () => {
const now = DateTime.local().setZone('utc', {
keepLocalTime: true,
})
jest
.spyOn(DateTime, 'local')
.mockReturnValueOnce(now.set({ day: 1, month: 12, year: 2021 }))
const result = getSeason()
expect(result).toBe(Season.WINTER)
})
it('should return none', () => {
const now = DateTime.local().setZone('utc', {
keepLocalTime: true,
})
jest
.spyOn(DateTime, 'local')
.mockReturnValueOnce(now.set({ day: 1, month: 10, year: 2021 }))
const result = getSeason()
expect(result).toBe(Season.NONE)
})
})
describe('getChallengeTitleWithLineReturn test', () => {
it('should return Simone\\nVEILLE', () => {
expect(getChallengeTitleWithLineReturn('CHALLENGE0001')).toBe(
'Simone\nVEILLE'
)
})
it('should return undefined', () => {
expect(getChallengeTitleWithLineReturn('CHALLENGE0000')).toBe(undefined)
})
})
describe('getMonthNameWithPrep', () => {
it('should return the name of the month with " de " ', () => {
const date = DateTime.fromISO('2020-11-29T23:59:59.999Z')
expect(getMonthNameWithPrep(date)).toBe('de novembre')
})
it('should return the name of the month with " d\'" ', () => {
const date = DateTime.fromISO('2020-10-29T23:59:59.999Z')
expect(getMonthNameWithPrep(date)).toBe('d’octobre')
})
})