Skip to content

Conversation

christian-byrne
Copy link
Contributor

@christian-byrne christian-byrne commented Sep 6, 2025

Summary

Adds component tests for some Vue Widget components.

Changes

  • What: Added tests
  • Changes include path for component tests

Review Focus

  • whether the tests are getting good coverage and applying best-practices

┆Issue is synchronized with this Notion page by Unito

@christian-byrne christian-byrne requested a review from a team as a code owner September 6, 2025 23:04
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Sep 6, 2025
Copy link

github-actions bot commented Sep 6, 2025

🎭 Playwright Test Results

All tests passed across all browsers!

⏰ Completed at: 09/07/2025, 06:04:55 AM UTC

📊 Test Reports by Browser


🎉 Your tests are passing across all browsers!

benceruleanlu
benceruleanlu previously approved these changes Sep 6, 2025
DrJKL
DrJKL previously approved these changes Sep 7, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests in here look pretty good, but it's kind of hard to see what differentiates one from another when there's so much similarity in the arrange/act sections

You already have a convenience setup function for the widget data, what about one for the wrapper too?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably have a similar utility to batch the operations like finding the child element, setting value, then blurring. If that's the standard, anything that deviates will stand out as interesting.

Copy link
Contributor Author

@christian-byrne christian-byrne Sep 7, 2025

Choose a reason for hiding this comment

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

Moved to utilities in 77b0207 and f615cf8

})

const input = wrapper.find('input[type="text"]')
expect((input.element as HTMLInputElement).disabled).toBe(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be inside an instanceof gate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 77b0207

callback
})

const mountComponent = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! Like this!

Comment on lines 115 to 116
const input = wrapper.find('input[type="number"]')
expect((input.element as HTMLInputElement).value).toBe('42')
Copy link
Contributor

Choose a reason for hiding this comment

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

If you moved these into an assertion utility, you could explicitly check that input.element instanceof HTMLInputElement and throw otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 77b0207

…@DrJKL's review feedback

- Add mountComponent utility function for consistent test setup
- Add setInputValueAndTrigger helper to batch common test operations
- Replace type assertions with proper instanceof checks for type safety
- Remove duplicate test setup code to improve test readability
- Fix TypeScript errors in WidgetSlider tests

These changes address all review comments by making tests easier to read
and understand while ensuring proper type checking.
@christian-byrne christian-byrne dismissed stale reviews from DrJKL and benceruleanlu via 77b0207 September 7, 2025 05:25
Comment on lines 90 to 116
it('disables components in readonly mode', () => {
const widget = createMockWidget(5)
const wrapper = mountComponent(widget, 5, true)

const slider = wrapper.findComponent({ name: 'Slider' })
expect(slider.props('disabled')).toBe(true)

const input = wrapper.find('input[type="number"]')
expect((input.element as HTMLInputElement).disabled).toBe(true)
})
})

describe('Component Rendering', () => {
it('renders slider and input components', () => {
const widget = createMockWidget(5)
const wrapper = mountComponent(widget, 5)

expect(wrapper.findComponent({ name: 'Slider' }).exists()).toBe(true)
expect(wrapper.find('input[type="number"]').exists()).toBe(true)
})

it('displays initial value in input field', () => {
const widget = createMockWidget(42)
const wrapper = mountComponent(widget, 42)

const input = wrapper.find('input[type="number"]')
expect((input.element as HTMLInputElement).value).toBe('42')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed duplicate tests

- Add mountComponent utility function for consistent test setup
- Add setSelectValueAndEmit helper to batch select operations
- Remove repetitive mount boilerplate code throughout tests
- Maintain existing test coverage while improving readability

This ensures all widget component tests follow the same patterns
established in WidgetInputText and WidgetSlider tests.
@christian-byrne christian-byrne merged commit 0d3b155 into main Sep 7, 2025
19 checks passed
@christian-byrne christian-byrne deleted the vue-nodes/test/widget-component-tests branch September 7, 2025 06:08
@benceruleanlu benceruleanlu mentioned this pull request Sep 7, 2025
snomiao pushed a commit that referenced this pull request Sep 12, 2025
* add component tests for vue widgets

* [refactor] improve widget test readability and type safety - addresses @DrJKL's review feedback

- Add mountComponent utility function for consistent test setup
- Add setInputValueAndTrigger helper to batch common test operations
- Replace type assertions with proper instanceof checks for type safety
- Remove duplicate test setup code to improve test readability
- Fix TypeScript errors in WidgetSlider tests

These changes address all review comments by making tests easier to read
and understand while ensuring proper type checking.

* [refactor] apply consistent test patterns to WidgetSelect.test.ts

- Add mountComponent utility function for consistent test setup
- Add setSelectValueAndEmit helper to batch select operations
- Remove repetitive mount boilerplate code throughout tests
- Maintain existing test coverage while improving readability

This ensures all widget component tests follow the same patterns
established in WidgetInputText and WidgetSlider tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:testing area:vue-migration size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants