|
| 1 | +import { |
| 2 | + useBindingSettings |
| 3 | +} from '../bindings'; |
| 4 | + |
| 5 | + |
| 6 | +describe('Bindings Composable', () => { |
| 7 | + |
| 8 | + describe('useBindingSettings', () => { |
| 9 | + const settingsThatShouldBeExcluded = { |
| 10 | + columns: { sm: 6, md: 4, lg: 3, xl: 2 }, |
| 11 | + options: [], |
| 12 | + required: true, |
| 13 | + rules: ['required'], |
| 14 | + when: () => { }, |
| 15 | + }; |
| 16 | + |
| 17 | + const settings = { |
| 18 | + ...settingsThatShouldBeExcluded, |
| 19 | + class: 'foo', |
| 20 | + color: 'primary', |
| 21 | + }; |
| 22 | + |
| 23 | + function checkExcludedSettings(result: any) { |
| 24 | + expect(result).to.not.have.property('columns'); |
| 25 | + expect(result).to.not.have.property('options'); |
| 26 | + expect(result).to.not.have.property('required'); |
| 27 | + expect(result).to.not.have.property('rules'); |
| 28 | + expect(result).to.not.have.property('when'); |
| 29 | + } |
| 30 | + |
| 31 | + it('should exclude settings in excludedSettings array by default', () => { |
| 32 | + const result = useBindingSettings(settings); |
| 33 | + |
| 34 | + // Ensure the excluded settings are not present // |
| 35 | + checkExcludedSettings(result); |
| 36 | + |
| 37 | + // Ensure the allowed settings are present // |
| 38 | + expect(result).to.have.property('class', 'foo'); |
| 39 | + expect(result).to.have.property('color', 'primary'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should exclude settings from the exclude parameter', () => { |
| 43 | + const exclude = ['color']; |
| 44 | + |
| 45 | + const result = useBindingSettings(settings, exclude); |
| 46 | + |
| 47 | + // Ensure the excluded settings are not present // |
| 48 | + checkExcludedSettings(result); |
| 49 | + |
| 50 | + // Ensure the allowed settings are present // |
| 51 | + expect(result).to.have.property('class', 'foo'); |
| 52 | + |
| 53 | + // Ensure the additional excluded settings are not present // |
| 54 | + expect(result).to.not.have.property('color'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should not exclude any settings when exclude parameter is empty', () => { |
| 58 | + const exclude: string[] = ['class']; // No settings to exclude |
| 59 | + |
| 60 | + const result = useBindingSettings(settings, exclude); |
| 61 | + |
| 62 | + // Ensure the excluded settings are not present // |
| 63 | + checkExcludedSettings(result); |
| 64 | + |
| 65 | + // Ensure the allowed settings are present // |
| 66 | + expect(result).to.have.property('color', 'primary'); |
| 67 | + |
| 68 | + // Ensure the additional excluded settings are not present // |
| 69 | + expect(result).to.not.have.property('class'); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments