Fix getters mutating state on repeated access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 07:31:59 +08:00
parent ef8ce0d778
commit eeea16be38
4 changed files with 77 additions and 35 deletions

View File

@@ -237,5 +237,28 @@ describe('allMapDataStore', () => {
store.allBaseCase = [{ id: 1 }];
expect(store.BaseInfiniteFirstCases).toBeUndefined();
});
it('filterAttrs getter does not corrupt original state on repeated access', () => {
const originalDate = '2023-06-15T10:30:00Z';
store.allFilterAttrs = [
{ type: 'date', min: originalDate, max: '2023-12-31T23:59:00Z' },
];
// Access the getter once
store.filterAttrs;
// The original state should still contain the ISO date, not a formatted string
expect(store.allFilterAttrs[0].min).toBe(originalDate);
});
it('filterAttrs getter returns consistent float values on repeated access', () => {
store.allFilterAttrs = [
{ type: 'float', min: 1.239, max: 5.671 },
];
const first = store.filterAttrs;
const second = store.filterAttrs;
// min rounds down (ROUND_DOWN=1), max rounds up (ROUND_UP=0)
// Both accesses should produce the same result
expect(first[0].min).toBe(second[0].min);
expect(first[0].max).toBe(second[0].max);
});
});
});