Skip to content

Instantly share code, notes, and snippets.

@dev-gasy
Created June 11, 2025 15:37
Show Gist options
  • Select an option

  • Save dev-gasy/123e52352094db1c43d9ebf09f37203b to your computer and use it in GitHub Desktop.

Select an option

Save dev-gasy/123e52352094db1c43d9ebf09f37203b to your computer and use it in GitHub Desktop.
describe('Vehicle Filter Utilities', () => {
const baseLookup: VehicleLookupOption = {
label: 'Honda Civic 2023',
value: 'civic-2023',
lookupValue: {
make: ['Honda'],
modelYear: ['2023'],
}
};
it('should match modelYear from lookupValue', () => {
const result = filterVehicleByModelYear(baseLookup, '2023');
expect(result).toBe(true);
});
it('should not match modelYear when different', () => {
const result = filterVehicleByModelYear(baseLookup, '2022');
expect(result).toBe(false);
});
it('should match make from lookupValue', () => {
const result = filterVehicleByMake(baseLookup, 'Honda');
expect(result).toBe(true);
});
it('should not match make when different', () => {
const result = filterVehicleByMake(baseLookup, 'Toyota');
expect(result).toBe(false);
});
it('should match both make and modelYear from lookupValue', () => {
const result = filterVehicleModelLookups(baseLookup, '2023', 'Honda');
expect(result).toBe(true);
});
it('should not match both make and modelYear if one mismatches', () => {
const result = filterVehicleModelLookups(baseLookup, '2022', 'Honda');
expect(result).toBe(false);
});
it('should match make and modelYear from filters property', () => {
const lookupWithFilters: VehicleLookupOption = {
label: 'Toyota Corolla 2024',
value: 'corolla-2024',
lookupValue: {},
filters: {
make: ['Toyota'],
modelYear: ['2024'],
}
};
expect(filterVehicleModelLookups(lookupWithFilters, '2024', 'Toyota')).toBe(true);
});
it('should fallback to lookupValue if filters are undefined', () => {
const result = filterVehicleModelLookups(baseLookup, '2023', 'Honda');
expect(result).toBe(true);
});
it('should return false when neither filters nor lookupValue contains valid data', () => {
const emptyLookup: VehicleLookupOption = {
label: 'Empty',
value: 'empty',
lookupValue: {}
};
expect(filterVehicleModelLookups(emptyLookup, '2023', 'Honda')).toBe(false);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment