@sankhyalabs/core 7.0.7 → 7.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -93,6 +93,10 @@ const getOptionFormat = (value: any, descriptor: FieldDescriptor) => {
93
93
  } else {
94
94
  options = {};
95
95
  if(prop != undefined){
96
+ if (descriptor.properties?.switchLabelsAndValues) {
97
+ prop.forEach(opt => options[opt.value] = opt.label);
98
+ }
99
+
96
100
  prop.forEach(opt => options[opt.label] = opt.value);
97
101
  }
98
102
  }
@@ -154,6 +154,18 @@ describe('getFormattedValue', () => {
154
154
  expect(getFormattedValue(value, descriptor)).toBe('option1');
155
155
  });
156
156
 
157
+ it('should return label when OPTIONSELECTOR has switchLabelsAndValues and value matches option value', () => {
158
+ const value = 'option1';
159
+ const descriptor: FieldDescriptor = {
160
+ userInterface: UserInterface.OPTIONSELECTOR,
161
+ properties: {
162
+ options: [{ label: 'Option 1', value: 'option1' }],
163
+ switchLabelsAndValues: true,
164
+ },
165
+ } as FieldDescriptor;
166
+ expect(getFormattedValue(value, descriptor)).toBe('Option 1');
167
+ });
168
+
157
169
  it('should format masked values correctly', () => {
158
170
  const value = '12345678901';
159
171
  const descriptor = { properties: { mask: 'cpf' } } as FieldDescriptor;