mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-31 15:20:32 +08:00
fix(blocks-antd): Fix selector index comparison.
This commit is contained in:
parent
f10b7c919a
commit
3f06fcde4b
@ -12,7 +12,7 @@ module.exports = {
|
||||
],
|
||||
coverageReporters: [['lcov', { projectRoot: '../../..' }], 'text', 'clover'],
|
||||
errorOnDeprecated: true,
|
||||
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/src/test'],
|
||||
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/es/', '<rootDir>/src/test'],
|
||||
moduleNameMapper: {
|
||||
'\\.(css|less)$': '<rootDir>/tests/__mocks__/styleMock.js',
|
||||
'^antd/.*/style$': '<rootDir>/tests/__mocks__/styleMock.js',
|
||||
|
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { type } from '@lowdefy/helpers';
|
||||
import { serializer, type } from '@lowdefy/helpers';
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
const getIndex = (value, options, key = 'value') => {
|
||||
@ -23,7 +23,11 @@ const getIndex = (value, options, key = 'value') => {
|
||||
if (type.isPrimitive(options[i]) && options[i] === value) {
|
||||
return i;
|
||||
}
|
||||
if (type.isObject(options[i]) && JSON.stringify(options[i][key]) === JSON.stringify(value)) {
|
||||
if (
|
||||
type.isObject(options[i]) &&
|
||||
serializer.serializeToString(options[i][key], { stable: true }) ===
|
||||
serializer.serializeToString(value, { stable: true })
|
||||
) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -154,3 +154,9 @@ test('object.value mixed multiple', () => {
|
||||
expect(getValueIndex(['x', [1, 2], 'x'], options, true)).toEqual([6, 1, 6]);
|
||||
expect(getValueIndex([{ a: 1, b: { c: 'x' } }], options, true)).toEqual([7]);
|
||||
});
|
||||
|
||||
test('object.value stable comparison,', () => {
|
||||
const options = [{ value: { a: 1, b: 1 } }, { value: { a: 2, b: 2 } }];
|
||||
expect(getValueIndex({ b: 1, a: 1 }, options)).toEqual(0);
|
||||
expect(getValueIndex([{ b: 1, a: 1 }], options, true)).toEqual([0]);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user