|
| 1 | +import { getDefaultUISchema } from '../../utils/trixta'; |
| 2 | + |
1 | 3 | describe('trixta Tests', () => {
|
2 |
| - it('Comming soon', () => { |
3 |
| - expect(true).toEqual(true); |
| 4 | + describe('React Json Schema Form', () => { |
| 5 | + describe('Request for Effect true', () => { |
| 6 | + it('Should merge uiSchema with norender true with existing uiSchema', () => { |
| 7 | + const requestForEffect = true; |
| 8 | + const inComingSchema = { |
| 9 | + 'ui:submitButtonOptions': { |
| 10 | + submitText: 'Confirm Details', |
| 11 | + norender: false, |
| 12 | + props: { |
| 13 | + disabled: false, |
| 14 | + className: 'btn btn-info', |
| 15 | + }, |
| 16 | + }, |
| 17 | + firstName: { |
| 18 | + 'ui:autofocus': true, |
| 19 | + 'ui:emptyValue': '', |
| 20 | + 'ui:autocomplete': 'family-name', |
| 21 | + }, |
| 22 | + lastName: { |
| 23 | + 'ui:title': 'Surname', |
| 24 | + 'ui:emptyValue': '', |
| 25 | + 'ui:autocomplete': 'given-name', |
| 26 | + }, |
| 27 | + age: { |
| 28 | + 'ui:widget': 'updown', |
| 29 | + 'ui:title': 'Age of person', |
| 30 | + 'ui:description': '(earthian year)', |
| 31 | + }, |
| 32 | + bio: { |
| 33 | + 'ui:widget': 'textarea', |
| 34 | + }, |
| 35 | + password: { |
| 36 | + 'ui:widget': 'password', |
| 37 | + 'ui:help': 'Hint: Make it strong!', |
| 38 | + }, |
| 39 | + date: { |
| 40 | + 'ui:widget': 'alt-datetime', |
| 41 | + }, |
| 42 | + telephone: { |
| 43 | + 'ui:options': { |
| 44 | + inputType: 'tel', |
| 45 | + }, |
| 46 | + }, |
| 47 | + }; |
| 48 | + |
| 49 | + const result = getDefaultUISchema(inComingSchema, requestForEffect); |
| 50 | + expect(result).toHaveProperty('ui:submitButtonOptions'); |
| 51 | + expect(result['ui:submitButtonOptions']['norender']).toEqual(true); |
| 52 | + }); |
| 53 | + |
| 54 | + it('Should return uiSchema with norender true with no uiSchema', () => { |
| 55 | + const requestForEffect = true; |
| 56 | + const inComingSchema = undefined; |
| 57 | + |
| 58 | + const result = getDefaultUISchema(inComingSchema, requestForEffect); |
| 59 | + expect(result).toHaveProperty('ui:submitButtonOptions'); |
| 60 | + expect(result['ui:submitButtonOptions']['norender']).toEqual(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it('Should return uiSchema with norender true with uiSchema and norender false', () => { |
| 64 | + const requestForEffect = true; |
| 65 | + const inComingSchema = { |
| 66 | + 'ui:submitButtonOptions': { |
| 67 | + submitText: 'Confirm Details', |
| 68 | + norender: true, |
| 69 | + props: { |
| 70 | + disabled: false, |
| 71 | + className: 'btn btn-info', |
| 72 | + }, |
| 73 | + }, |
| 74 | + firstName: { |
| 75 | + 'ui:autofocus': true, |
| 76 | + 'ui:emptyValue': '', |
| 77 | + 'ui:autocomplete': 'family-name', |
| 78 | + }, |
| 79 | + lastName: { |
| 80 | + 'ui:title': 'Surname', |
| 81 | + 'ui:emptyValue': '', |
| 82 | + 'ui:autocomplete': 'given-name', |
| 83 | + }, |
| 84 | + age: { |
| 85 | + 'ui:widget': 'updown', |
| 86 | + 'ui:title': 'Age of person', |
| 87 | + 'ui:description': '(earthian year)', |
| 88 | + }, |
| 89 | + bio: { |
| 90 | + 'ui:widget': 'textarea', |
| 91 | + }, |
| 92 | + password: { |
| 93 | + 'ui:widget': 'password', |
| 94 | + 'ui:help': 'Hint: Make it strong!', |
| 95 | + }, |
| 96 | + date: { |
| 97 | + 'ui:widget': 'alt-datetime', |
| 98 | + }, |
| 99 | + telephone: { |
| 100 | + 'ui:options': { |
| 101 | + inputType: 'tel', |
| 102 | + }, |
| 103 | + }, |
| 104 | + }; |
| 105 | + |
| 106 | + const result = getDefaultUISchema(inComingSchema, requestForEffect); |
| 107 | + expect(result).toHaveProperty('ui:submitButtonOptions'); |
| 108 | + expect(result['ui:submitButtonOptions']['norender']).toEqual(true); |
| 109 | + }); |
| 110 | + }); |
| 111 | + |
| 112 | + describe('Request for Effect false', () => { |
| 113 | + it('Should merge uiSchema with norender false with existing uiSchema', () => { |
| 114 | + const requestForEffect = false; |
| 115 | + const inComingSchema = { |
| 116 | + 'ui:submitButtonOptions': { |
| 117 | + submitText: 'Confirm Details', |
| 118 | + norender: false, |
| 119 | + props: { |
| 120 | + disabled: false, |
| 121 | + className: 'btn btn-info', |
| 122 | + }, |
| 123 | + }, |
| 124 | + firstName: { |
| 125 | + 'ui:autofocus': true, |
| 126 | + 'ui:emptyValue': '', |
| 127 | + 'ui:autocomplete': 'family-name', |
| 128 | + }, |
| 129 | + lastName: { |
| 130 | + 'ui:title': 'Surname', |
| 131 | + 'ui:emptyValue': '', |
| 132 | + 'ui:autocomplete': 'given-name', |
| 133 | + }, |
| 134 | + age: { |
| 135 | + 'ui:widget': 'updown', |
| 136 | + 'ui:title': 'Age of person', |
| 137 | + 'ui:description': '(earthian year)', |
| 138 | + }, |
| 139 | + bio: { |
| 140 | + 'ui:widget': 'textarea', |
| 141 | + }, |
| 142 | + password: { |
| 143 | + 'ui:widget': 'password', |
| 144 | + 'ui:help': 'Hint: Make it strong!', |
| 145 | + }, |
| 146 | + date: { |
| 147 | + 'ui:widget': 'alt-datetime', |
| 148 | + }, |
| 149 | + telephone: { |
| 150 | + 'ui:options': { |
| 151 | + inputType: 'tel', |
| 152 | + }, |
| 153 | + }, |
| 154 | + }; |
| 155 | + |
| 156 | + const result = getDefaultUISchema(inComingSchema, requestForEffect); |
| 157 | + expect(result).toHaveProperty('ui:submitButtonOptions'); |
| 158 | + expect(result['ui:submitButtonOptions']['norender']).toEqual(false); |
| 159 | + }); |
| 160 | + |
| 161 | + it('Should return uiSchema with norender false with no uiSchema', () => { |
| 162 | + const requestForEffect = false; |
| 163 | + const inComingSchema = undefined; |
| 164 | + |
| 165 | + const result = getDefaultUISchema(inComingSchema, requestForEffect); |
| 166 | + expect(result).toHaveProperty('ui:submitButtonOptions'); |
| 167 | + expect(result['ui:submitButtonOptions']['norender']).toEqual(false); |
| 168 | + }); |
| 169 | + |
| 170 | + it('Should return uiSchema with norender false with uiSchema and norender true', () => { |
| 171 | + const requestForEffect = false; |
| 172 | + const inComingSchema = { |
| 173 | + 'ui:submitButtonOptions': { |
| 174 | + submitText: 'Confirm Details', |
| 175 | + norender: true, |
| 176 | + props: { |
| 177 | + disabled: false, |
| 178 | + className: 'btn btn-info', |
| 179 | + }, |
| 180 | + }, |
| 181 | + firstName: { |
| 182 | + 'ui:autofocus': true, |
| 183 | + 'ui:emptyValue': '', |
| 184 | + 'ui:autocomplete': 'family-name', |
| 185 | + }, |
| 186 | + lastName: { |
| 187 | + 'ui:title': 'Surname', |
| 188 | + 'ui:emptyValue': '', |
| 189 | + 'ui:autocomplete': 'given-name', |
| 190 | + }, |
| 191 | + age: { |
| 192 | + 'ui:widget': 'updown', |
| 193 | + 'ui:title': 'Age of person', |
| 194 | + 'ui:description': '(earthian year)', |
| 195 | + }, |
| 196 | + bio: { |
| 197 | + 'ui:widget': 'textarea', |
| 198 | + }, |
| 199 | + password: { |
| 200 | + 'ui:widget': 'password', |
| 201 | + 'ui:help': 'Hint: Make it strong!', |
| 202 | + }, |
| 203 | + date: { |
| 204 | + 'ui:widget': 'alt-datetime', |
| 205 | + }, |
| 206 | + telephone: { |
| 207 | + 'ui:options': { |
| 208 | + inputType: 'tel', |
| 209 | + }, |
| 210 | + }, |
| 211 | + }; |
| 212 | + |
| 213 | + const result = getDefaultUISchema(inComingSchema, requestForEffect); |
| 214 | + expect(result).toHaveProperty('ui:submitButtonOptions'); |
| 215 | + expect(result['ui:submitButtonOptions']['norender']).toEqual(false); |
| 216 | + }); |
| 217 | + }); |
4 | 218 | });
|
5 | 219 | });
|
0 commit comments