useObjectManagerAttributes.spec.ts 2.1 KB

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