useMyProfile.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { createStore, initLocalVue } from '~/tests/unit/Helpers'
  2. import { accessProfile as accessModule } from '~/tests/unit/fixture/state/profile'
  3. import { AnyStore } from '~/types/interfaces'
  4. import { useMyProfile } from '~/composables/data/useMyProfile'
  5. import { repositoryHelper } from '~/services/store/repository'
  6. import {$accessProfile} from "~/services/profile/accessProfile";
  7. import {_exportedForTesting} from "~/composables/data/useMyProfile"
  8. import DataPersister from "~/services/data/dataPersister";
  9. let store:AnyStore
  10. let useMyProfileMount:any
  11. let repositoryHelperMock = repositoryHelper as jest.Mocked<typeof repositoryHelper>
  12. beforeAll(() => {
  13. store = createStore()
  14. store.registerModule('profile', {})
  15. store.registerModule(['profile', 'access'], accessModule)
  16. repositoryHelper.setStore(store)
  17. initLocalVue({store: store})
  18. const $accessProfileMock = $accessProfile as jest.Mocked<typeof $accessProfile>
  19. $accessProfileMock.getCurrentAccessId = jest.fn().mockReturnValue(1)
  20. repositoryHelperMock.findItemFromModel = jest.fn()
  21. useMyProfileMount = useMyProfile(new DataPersister(), store)
  22. })
  23. describe('setActivityYear()', () => {
  24. it('should throw an error if year is negative nor eq to 0', () => {
  25. expect(() => useMyProfileMount.setActivityYear(-1)).toThrow()
  26. })
  27. it('should call updateStoreFromField', () => {
  28. repositoryHelperMock.updateStoreFromField = jest.fn()
  29. useMyProfileMount.setActivityYear(2020)
  30. expect(repositoryHelperMock).toHaveBeenCalled
  31. })
  32. })
  33. describe('setHistorical()', () => {
  34. it('should call updateStoreFromField', () => {
  35. repositoryHelperMock.updateStoreFromField = jest.fn()
  36. useMyProfileMount.setHistorical(['present', 'future'])
  37. expect(repositoryHelperMock).toHaveBeenCalled
  38. })
  39. })
  40. describe('getHistoricalEntry()', () => {
  41. it('should return an json object', () => {
  42. const historical = _exportedForTesting.getHistoricalEntry(['present', 'future'])
  43. expect(historical).toStrictEqual({ past: false, present: true, future: true })
  44. })
  45. })
  46. describe('getHistoricalRangeEntry()', () => {
  47. it('should return an json object', () => {
  48. const historical = _exportedForTesting.getHistoricalRangeEntry(['2020/01/01', '2020/01/31'])
  49. expect(historical).toStrictEqual({ past: false, present: false, future: false, dateStart: '2020/01/01', dateEnd: '2020/01/31' })
  50. })
  51. })
  52. describe('getMyProfileInstance()', () => {
  53. it('should call findItemFromModel', () => {
  54. repositoryHelperMock.findItemFromModel = jest.fn()
  55. _exportedForTesting.getMyProfileInstance(1)
  56. expect(repositoryHelperMock).toHaveBeenCalled
  57. })
  58. })