test: add tests for gadget filter types - #52
Conversation
Signed-off-by: mrhapile <allinonegaming3456@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds initial unit test coverage for gadget filter type definitions in the gadgets module (ref #20), ensuring the exported FILTERS_TYPE mapping stays consistent.
Changes:
- Added a new Vitest test file verifying the shape/values of
FILTERS_TYPEentries (uint32/int32/string/bool/[]string).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| @@ -0,0 +1,39 @@ | |||
| /** @vitest-environment jsdom */ | |||
There was a problem hiding this comment.
The file-level @vitest-environment jsdom directive looks unnecessary here since these assertions only exercise a plain object and don’t touch DOM APIs. Consider removing it (or using the default/node environment) to keep test startup lighter and avoid coupling this unit test to jsdom.
| /** @vitest-environment jsdom */ |
| test('exports FILTERS_TYPE constant', () => { | ||
| expect(FILTERS_TYPE).toBeDefined(); | ||
| expect(typeof FILTERS_TYPE).toBe('object'); | ||
| }); | ||
|
|
||
| test('uint32 filter is mapped correctly', () => { | ||
| expect(FILTERS_TYPE.uint32).toBeDefined(); | ||
| expect(FILTERS_TYPE.uint32.type).toBe('number'); | ||
| expect(FILTERS_TYPE.uint32.max).toBe(4294967295); | ||
| expect(FILTERS_TYPE.uint32.min).toBe(0); | ||
| }); | ||
|
|
||
| test('int32 filter is mapped correctly', () => { | ||
| expect(FILTERS_TYPE.int32).toBeDefined(); | ||
| expect(FILTERS_TYPE.int32.type).toBe('number'); | ||
| expect(FILTERS_TYPE.int32.max).toBe(2147483647); | ||
| expect(FILTERS_TYPE.int32.min).toBe(-2147483648); | ||
| }); | ||
|
|
||
| test('string filter is mapped correctly', () => { | ||
| expect(FILTERS_TYPE.string).toBeDefined(); | ||
| expect(FILTERS_TYPE.string.type).toBe('string'); | ||
| }); | ||
|
|
||
| test('bool filter is mapped correctly', () => { | ||
| expect(FILTERS_TYPE.bool).toBeDefined(); | ||
| expect(FILTERS_TYPE.bool.type).toBe('checkbox'); | ||
| }); | ||
|
|
||
| test('[]string filter is mapped correctly', () => { | ||
| expect(FILTERS_TYPE['[]string']).toBeDefined(); | ||
| expect(FILTERS_TYPE['[]string'].type).toBe('string'); | ||
| }); |
There was a problem hiding this comment.
Indentation in this test file doesn’t match the repository’s typical 2-space formatting (e.g., other TS/TSX files in src/gadgets). Running the formatter (or adjusting indentation) will keep the codebase style-consistent.
| test('exports FILTERS_TYPE constant', () => { | |
| expect(FILTERS_TYPE).toBeDefined(); | |
| expect(typeof FILTERS_TYPE).toBe('object'); | |
| }); | |
| test('uint32 filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.uint32).toBeDefined(); | |
| expect(FILTERS_TYPE.uint32.type).toBe('number'); | |
| expect(FILTERS_TYPE.uint32.max).toBe(4294967295); | |
| expect(FILTERS_TYPE.uint32.min).toBe(0); | |
| }); | |
| test('int32 filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.int32).toBeDefined(); | |
| expect(FILTERS_TYPE.int32.type).toBe('number'); | |
| expect(FILTERS_TYPE.int32.max).toBe(2147483647); | |
| expect(FILTERS_TYPE.int32.min).toBe(-2147483648); | |
| }); | |
| test('string filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.string).toBeDefined(); | |
| expect(FILTERS_TYPE.string.type).toBe('string'); | |
| }); | |
| test('bool filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.bool).toBeDefined(); | |
| expect(FILTERS_TYPE.bool.type).toBe('checkbox'); | |
| }); | |
| test('[]string filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE['[]string']).toBeDefined(); | |
| expect(FILTERS_TYPE['[]string'].type).toBe('string'); | |
| }); | |
| test('exports FILTERS_TYPE constant', () => { | |
| expect(FILTERS_TYPE).toBeDefined(); | |
| expect(typeof FILTERS_TYPE).toBe('object'); | |
| }); | |
| test('uint32 filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.uint32).toBeDefined(); | |
| expect(FILTERS_TYPE.uint32.type).toBe('number'); | |
| expect(FILTERS_TYPE.uint32.max).toBe(4294967295); | |
| expect(FILTERS_TYPE.uint32.min).toBe(0); | |
| }); | |
| test('int32 filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.int32).toBeDefined(); | |
| expect(FILTERS_TYPE.int32.type).toBe('number'); | |
| expect(FILTERS_TYPE.int32.max).toBe(2147483647); | |
| expect(FILTERS_TYPE.int32.min).toBe(-2147483648); | |
| }); | |
| test('string filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.string).toBeDefined(); | |
| expect(FILTERS_TYPE.string.type).toBe('string'); | |
| }); | |
| test('bool filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE.bool).toBeDefined(); | |
| expect(FILTERS_TYPE.bool.type).toBe('checkbox'); | |
| }); | |
| test('[]string filter is mapped correctly', () => { | |
| expect(FILTERS_TYPE['[]string']).toBeDefined(); | |
| expect(FILTERS_TYPE['[]string'].type).toBe('string'); | |
| }); |
| import { FILTERS_TYPE } from './filter_types'; | ||
|
|
||
| describe('gadget filter types', () => { | ||
| test('exports FILTERS_TYPE constant', () => { |
There was a problem hiding this comment.
PR description mentions “helper logic” and “edge cases”, but this test file only validates the FILTERS_TYPE constant values. Either update the PR description to match what’s being tested, or add tests for the referenced helper behavior (if it exists elsewhere).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
illume
left a comment
There was a problem hiding this comment.
Thanks for your contributions!
Please let us know if you want to continue this by addressing the review comments? If not that's ok, we can take over the PR (and finish it or close it ourselves).
Add tests for gadget filter types
ref #20
This PR adds a test file for the filter type definitions and helper logic implemented in
src/gadgets/filter_types.tsx.The tests validate that the exported filter types and related helper functions behave as expected and handle edge cases safely. These tests follow the existing testing conventions used in the repository and help improve overall test coverage for the gadgets module.
How to use
Reviewers can validate this PR by running the test suite locally.
Steps:
Testing done
Commands executed:
npm install
npm test
Result:
The test suite runs successfully and the new test file
src/gadgets/filter_types.test.tsxexecutes without errors.