form_schema_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::FormSchema, type: :graphql do
  4. context 'when fetching form schema data' do
  5. let(:query) do
  6. <<~QUERY
  7. query formSchema($formSchemaId: EnumFormSchemaId!) {
  8. formSchema(formSchemaId: $formSchemaId)
  9. }
  10. QUERY
  11. end
  12. let(:variables) { { formSchemaId: 'FormSchema__Form__Mobile__Login' } }
  13. let(:expected) do
  14. [
  15. {
  16. type: 'text',
  17. name: 'login',
  18. label: __('Username / Email'),
  19. required: true,
  20. props: {
  21. placeholder: __('Username / Email'),
  22. },
  23. },
  24. {
  25. type: 'password',
  26. label: __('Password'),
  27. name: 'password',
  28. required: true,
  29. props: {
  30. placeholder: __('Password'),
  31. },
  32. },
  33. {
  34. isLayout: true,
  35. element: 'div',
  36. attrs: {
  37. class: 'mt-2.5 flex grow items-center justify-between text-white',
  38. },
  39. children: [
  40. {
  41. type: 'checkbox',
  42. label: __('Remember me'),
  43. name: 'remember_me',
  44. props: {},
  45. },
  46. {
  47. isLayout: true,
  48. component: 'CommonLink',
  49. props: {
  50. class: 'text-right !text-white',
  51. link: '/#password_reset',
  52. },
  53. children: __('Forgot password?'),
  54. },
  55. ],
  56. },
  57. ]
  58. end
  59. before do
  60. gql.execute(query, variables: variables)
  61. end
  62. it 'returns form schema' do
  63. expect(gql.result.data).to eq(expected)
  64. end
  65. end
  66. end