useObjectManagerAttributes.spec.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. })
  77. })
  78. })