-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/upgrade-signature-controller-remove-gl…
…obal-network
- Loading branch information
Showing
10 changed files
with
193 additions
and
94 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useBluetoothDevices from './useBluetoothDevices'; | ||
import { Observable } from 'rxjs'; | ||
|
||
describe('useBluetoothDevices', () => { | ||
let subscribeMock: jest.Mock; | ||
|
||
beforeEach(() => { | ||
subscribeMock = jest.fn(); | ||
jest.spyOn(Observable.prototype, 'subscribe').mockImplementation(subscribeMock); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('returns empty devices and no error when permissions are false', () => { | ||
const { result } = renderHook(() => useBluetoothDevices(false, true)); | ||
|
||
expect(result.current.devices).toEqual([]); | ||
expect(result.current.deviceScanError).toBe(false); | ||
}); | ||
|
||
it('returns empty devices and no error when bluetooth is off', () => { | ||
const { result } = renderHook(() => useBluetoothDevices(true, false)); | ||
|
||
expect(result.current.devices).toEqual([]); | ||
expect(result.current.deviceScanError).toBe(false); | ||
}); | ||
|
||
it('returns expected device and no error when permissions and bluetooth are on and devices scan return devices', async () => { | ||
|
||
const expectedDevice1 = { | ||
id: '1', | ||
name: 'Device 1', | ||
}; | ||
|
||
// Mock `listen` to simulate device discovery | ||
subscribeMock.mockImplementation(({ next }) => { | ||
next({ | ||
type: 'add', | ||
descriptor: expectedDevice1, | ||
}); | ||
}); | ||
const { result } = renderHook(() => useBluetoothDevices(true, true)); | ||
|
||
expect(result.current.devices).toEqual([expectedDevice1]); | ||
expect(result.current.deviceScanError).toBe(false); | ||
}); | ||
|
||
it('returns error when device scan fails', async () => { | ||
// Mock `listen` to simulate device discovery | ||
subscribeMock.mockImplementation(({ error }) => { | ||
error('Error'); | ||
}); | ||
const { result } = renderHook(() => useBluetoothDevices(true, true)); | ||
|
||
expect(result.current.devices).toEqual([]); | ||
expect(result.current.deviceScanError).toBe(true); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.