useMyProfile.spec.ts 2.5 KB

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