| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import { createStore, initLocalVue, mountComposition } from '~/tests/unit/Helpers'
- import { accessProfile as accessModule } from '~/tests/unit/fixture/state/profile'
- import { AnyStore } from '~/types/interfaces'
- import { useMyProfile } from '~/composables/data/useMyProfile'
- import { repositoryHelper } from '~/services/store/repository'
- import {$accessProfile} from "~/services/profile/accessProfile";
- import {_exportedForTesting} from "~/composables/data/useMyProfile"
- let store:AnyStore
- let useMyProfileMount:any
- let repositoryHelperMock = repositoryHelper as jest.Mocked<typeof repositoryHelper>
- beforeAll(() => {
- store = createStore()
- store.registerModule('profile', {})
- store.registerModule(['profile', 'access'], accessModule)
- repositoryHelper.setStore(store)
- initLocalVue({store: store})
- const $accessProfileMock = $accessProfile as jest.Mocked<typeof $accessProfile>
- $accessProfileMock.getCurrentAccessId = jest.fn().mockReturnValue(1)
- repositoryHelperMock.findItemFromModel = jest.fn()
- const component = mountComposition(() => {
- useMyProfileMount = useMyProfile()
- });
- })
- describe('setActivityYear()', () => {
- it('should throw an error if year is negative nor eq to 0', () => {
- expect(() => useMyProfileMount.setActivityYear(-1)).toThrow()
- })
- it('should call updateStoreFromField', () => {
- repositoryHelperMock.updateStoreFromField = jest.fn()
- useMyProfileMount.setActivityYear(2020)
- expect(repositoryHelperMock).toHaveBeenCalled
- })
- })
- describe('setHistorical()', () => {
- it('should call updateStoreFromField', () => {
- repositoryHelperMock.updateStoreFromField = jest.fn()
- useMyProfileMount.setHistorical(['present', 'future'])
- expect(repositoryHelperMock).toHaveBeenCalled
- })
- })
- describe('getHistoricalEntry()', () => {
- it('should return an json object', () => {
- const historical = _exportedForTesting.getHistoricalEntry(['present', 'future'])
- expect(historical).toStrictEqual({ past: false, present: true, future: true })
- })
- })
- describe('getHistoricalRangeEntry()', () => {
- it('should return an json object', () => {
- const historical = _exportedForTesting.getHistoricalRangeEntry(['2020/01/01', '2020/01/31'])
- expect(historical).toStrictEqual({ past: false, present: false, future: false, dateStart: '2020/01/01', dateEnd: '2020/01/31' })
- })
- })
- describe('getMyProfileInstance()', () => {
- it('should call findItemFromModel', () => {
- repositoryHelperMock.findItemFromModel = jest.fn()
- _exportedForTesting.getMyProfileInstance(1)
- expect(repositoryHelperMock).toHaveBeenCalled
- })
- })
|