Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions renderers/angular/src/v0_9/catalog/basic/slider.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {SliderApi} from '@a2ui/web_core/v0_9/basic_catalog';
type="range"
[min]="min()"
[max]="max()"
[step]="step()"
[value]="value()"
(input)="handleInput($event)"
class="a2ui-slider"
Expand Down Expand Up @@ -85,7 +84,6 @@ export class SliderComponent extends BasicCatalogComponent<typeof SliderApi> {
readonly value = computed(() => this.props()['value']?.value());
readonly min = computed(() => this.props()['min']?.value() ?? 0);
readonly max = computed(() => this.props()['max']?.value() ?? 100);
readonly step = computed(() => this.props()['step']?.value() ?? 1);

handleInput(event: Event) {
const val = Number((event.target as HTMLInputElement).value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {describe, it} from 'node:test';
import * as assert from 'node:assert';
import {ImageApi} from './basic_components.js';
import {ImageApi, SliderApi} from './basic_components.js';

describe('Basic Components Schema', () => {
describe('ImageApi', () => {
Expand Down Expand Up @@ -46,4 +46,26 @@ describe('Basic Components Schema', () => {
assert.throws(() => ImageApi.schema.parse(invalidImage));
});
});

describe('SliderApi', () => {
it('should reject non-spec step property', () => {
const validSlider = {
max: 100,
value: 50,
};
SliderApi.schema.parse(validSlider);

const result = SliderApi.schema.safeParse({
...validSlider,
step: 5,
});

assert.strictEqual(result.success, false);
assert.ok(
result.error.issues.some(
issue => issue.code === 'unrecognized_keys' && issue.keys.includes('step'),
),
);
});
Comment on lines +51 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The regression test for SliderApi should be more robust. Currently, assert.throws will pass if the schema parsing fails for any reason (e.g., an invalid value format or missing required fields). To ensure it specifically catches the rejection of the step property, it is better to first validate a correct object and then verify that adding step causes a specific error. Additionally, using a literal number for value is more consistent with other tests in this file.

    it('should reject non-spec step property', () => {
      const validSlider = {
        max: 100,
        value: 50,
      };
      // Verify it parses correctly without the 'step' property
      SliderApi.schema.parse(validSlider);

      const invalidSlider = {
        ...validSlider,
        step: 5,
      };

      assert.throws(
        () => SliderApi.schema.parse(invalidSlider),
        /unrecognized_keys.*step/i
      );
    });

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ export const SliderApi = {
label: DynamicStringSchema.describe('The label for the slider.').optional(),
min: z.number().default(0).describe('The minimum value of the slider.').optional(),
max: z.number().describe('The maximum value of the slider.'),
step: z.number().describe('The granularity or step size of the slider.').optional(),
value: DynamicNumberSchema.describe('The current value of the slider.'),
checks: CheckableSchema.shape.checks,
})
Expand Down