useObjectAttributes.spec.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { createPinia, setActivePinia } from 'pinia'
  3. import { effectScope } from 'vue'
  4. import { mockGraphQLApi } from '#tests/support/mock-graphql-api.ts'
  5. import { waitForTimeout } from '#tests/support/utils.ts'
  6. import { EnumObjectManagerObjects } from '#shared/graphql/types.ts'
  7. import { ObjectManagerFrontendAttributesDocument } from '../../graphql/queries/objectManagerFrontendAttributes.api.ts'
  8. import { useObjectAttributes } from '../useObjectAttributes.ts'
  9. import objectFrontendAttributes from './mocks/objectFrontendAttributes.json'
  10. const mockOrganizationObjectManagerAttributes = () => {
  11. mockGraphQLApi(ObjectManagerFrontendAttributesDocument).willResolve({
  12. objectManagerFrontendAttributes: objectFrontendAttributes,
  13. })
  14. }
  15. const getMeta = async () => {
  16. mockOrganizationObjectManagerAttributes()
  17. const meta = useObjectAttributes(EnumObjectManagerObjects.Organization)
  18. await waitForTimeout()
  19. return meta
  20. }
  21. const scope = effectScope()
  22. describe('Object Manager Frontend Attributes Store', () => {
  23. beforeEach(() => {
  24. setActivePinia(createPinia())
  25. })
  26. it('is filled for Organization', async () => {
  27. await scope.run(async () => {
  28. const meta = await getMeta()
  29. expect(meta.attributes).not.toBe(undefined)
  30. })
  31. })
  32. it('contains screens', async () => {
  33. await scope.run(async () => {
  34. const meta = await getMeta()
  35. expect(meta.screens.value).toEqual({
  36. view: [
  37. 'name',
  38. 'shared',
  39. 'domain_assignment',
  40. 'domain',
  41. 'note',
  42. 'active',
  43. 'test',
  44. 'textarea',
  45. ],
  46. edit: [
  47. 'name',
  48. 'shared',
  49. 'domain_assignment',
  50. 'domain',
  51. 'note',
  52. 'active',
  53. 'test',
  54. 'textarea',
  55. ],
  56. })
  57. })
  58. })
  59. it('provides a fancy lookup of all attributes', async () => {
  60. await scope.run(async () => {
  61. const meta = await getMeta()
  62. expect(meta.attributesLookup.value.get('name')).toEqual({
  63. __typename: 'ObjectManagerFrontendAttribute',
  64. name: 'name',
  65. display: 'Name',
  66. dataType: 'input',
  67. isInternal: true,
  68. dataOption: {
  69. type: 'text',
  70. maxlength: 150,
  71. null: false,
  72. item_class: 'formGroup--halfSize',
  73. },
  74. screens: {},
  75. })
  76. // Check if also the static attribute exists.
  77. expect(meta.attributesLookup.value.get('created_at')).toEqual({
  78. name: 'created_at',
  79. display: __('Created at'),
  80. dataType: 'datetime',
  81. isStatic: true,
  82. isInternal: true,
  83. })
  84. })
  85. })
  86. })