-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(device-page): fix search in header device selector
- Loading branch information
1 parent
d845d85
commit 919a3aa
Showing
3 changed files
with
86 additions
and
51 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/components/device-page/header-device-selector.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { createMockDevice, fireEvent, render, screen, waitFor } from '../../test-utils'; | ||
import { it, expect } from 'vitest'; | ||
import { HeaderDeviceSelector } from './header-device-selector'; | ||
|
||
it('all devices are visible in dropdown', async () => { | ||
const ieeeAddress1 = 'FF:FF:FF:FF:FF:AA'; | ||
const ieeeAddress2 = 'AA:AA:AA:AA:AA:AA'; | ||
const currentDevice = createMockDevice({ieee_address: ieeeAddress1, friendly_name: "Button"}) | ||
const devices = { | ||
[ieeeAddress1]: currentDevice, | ||
[ieeeAddress2]: createMockDevice({ieee_address: ieeeAddress2, friendly_name: "Light"}), | ||
} | ||
render( | ||
<HeaderDeviceSelector allDevices={devices} currentDevice={currentDevice}/>, | ||
); | ||
await waitFor(() => fireEvent.click(screen.getByLabelText(/Select a device/))); | ||
expect(document.querySelectorAll('.dropdown-item')).toHaveLength(2) | ||
}); | ||
|
||
it('device can be selected', async () => { | ||
const ieeeAddress1 = 'FF:FF:FF:FF:FF:AA'; | ||
const ieeeAddress2 = 'AA:AA:AA:AA:AA:AA'; | ||
const currentDevice = createMockDevice({ieee_address: ieeeAddress1, friendly_name: "Button"}) | ||
const devices = { | ||
[ieeeAddress1]: currentDevice, | ||
[ieeeAddress2]: createMockDevice({ieee_address: ieeeAddress2, friendly_name: "Light"}), | ||
} | ||
|
||
render( | ||
<HeaderDeviceSelector allDevices={devices} currentDevice={currentDevice}/>, | ||
); | ||
|
||
await waitFor(() => fireEvent.click(screen.getByLabelText(/Select a device/))); | ||
await waitFor(() => fireEvent.click(screen.getByText(/Light/))); | ||
expect(document.location.toString()).toContain(ieeeAddress2) | ||
}); | ||
|
||
it('devices list can be filtered', async () => { | ||
const ieeeAddress1 = 'FF:FF:FF:FF:FF:AA'; | ||
const ieeeAddress2 = 'AA:AA:AA:AA:AA:AA'; | ||
const currentDevice = createMockDevice({ieee_address: ieeeAddress1, friendly_name: "Button"}) | ||
const devices = { | ||
[ieeeAddress1]: currentDevice, | ||
[ieeeAddress2]: createMockDevice({ieee_address: ieeeAddress2, friendly_name: "Light"}), | ||
} | ||
render( | ||
<HeaderDeviceSelector allDevices={devices} currentDevice={currentDevice}/>, | ||
); | ||
|
||
await waitFor(() => fireEvent.click(screen.getByLabelText(/Select a device/))); | ||
await waitFor(() => fireEvent.change(screen.getByPlaceholderText(/Type to filter.../), {target: {value: 'Light'}})); | ||
|
||
expect(document.querySelectorAll('.dropdown-item')).toHaveLength(1) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters