forked from microbit-foundation/cctd-ml-machine
-
Notifications
You must be signed in to change notification settings - Fork 6
First-cut new session, connection, and testing model page E2E tests #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
87806bb
Add new-page E2E tests
microbit-grace f213876
Prettier
microbit-grace 149ba99
Setup cookies
microbit-grace 2caa80b
Remove WIP data samples test
microbit-grace 9c13361
Add workflow 10 mins build timeout
microbit-grace 44be331
WIP mock connections
microbit-grace 3cde798
Merge branch 'e2e' of https://github.com/microbit-foundation/ml-train…
microbit-grace ea855be
Fix start session and resume session tests
microbit-grace 3a8e616
Update to the latest microbit-connection library
microbit-grace 2c97803
Happy bluetooth connection flow
microbit-grace bd67da5
Bluetooth no device selected for flashing test
microbit-grace cfae3f5
Comment out E2E tests temporarily
microbit-grace 274c4c2
Bluetooth no device selected for connecting test
microbit-grace c1bf6a4
Add radio bridge happy flow test
microbit-grace 52893a5
Radio no device selected for flashing
microbit-grace 15c63e3
Use cookie mechanism to activate isMockDeviceMode
microbit-grace 3c5c44a
Fix minor lint
microbit-grace d353173
Make connection dialog tests more reliable by removing loading steps
microbit-grace 49c48f3
Uncomment build.yml e2e workflow
microbit-grace ad89519
Add unused methods into mock usb & bluetooth
microbit-grace b5c81bb
Merge branch 'main' of https://github.com/microbit-foundation/ml-trai…
microbit-grace e0f1c60
Adjust to fit changes in microbit-connection lib
microbit-grace d70f96a
Update mocks following changes in microbit-connection
microbit-grace b1fbba4
Add test model test
microbit-grace a61a634
Remove not needed type casting
microbit-grace db61b1d
Empty commit because CloudFlare is taking an unusually long time?
microbit-grace c928fd8
Enter bluetooth pattern via input fields instead
microbit-grace 5c2100c
More straight line test code. Removed some awkward tests in favour of…
microbit-grace 0278cf8
Upgrade microbit-connection
microbit-grace 360cc63
Organise imports
microbit-grace fa911b2
Fix build
microbit-grace 8e9c791
Attempt to fix E2E test.
microbit-grace 1f28286
Inline connection happy flow dialog steps and reinstate other tests
microbit-grace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ concurrency: | |
|
|
||
| jobs: | ||
| build: | ||
| timeout-minutes: 10 | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,81 @@ | ||
| import { | ||
| BoardVersion, | ||
| ConnectionStatus, | ||
| ConnectionStatusEvent, | ||
| DeviceConnectionEventMap, | ||
| LedMatrix, | ||
| MicrobitWebBluetoothConnection, | ||
| ServiceConnectionEventMap, | ||
| TypedEventTarget, | ||
| } from "@microbit/microbit-connection"; | ||
|
|
||
| export class MockWebBluetoothConnection | ||
| extends TypedEventTarget<DeviceConnectionEventMap & ServiceConnectionEventMap> | ||
| implements MicrobitWebBluetoothConnection | ||
| { | ||
| status: ConnectionStatus = ConnectionStatus.NO_AUTHORIZED_DEVICE; | ||
| private connectResults: ConnectionStatus[] = []; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| // Make globally available to allow e2e tests to configure interactions. | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access | ||
| (window as any).mockBluetooth = this; | ||
| } | ||
| private setStatus(newStatus: ConnectionStatus) { | ||
| this.status = newStatus; | ||
| this.dispatchTypedEvent("status", new ConnectionStatusEvent(newStatus)); | ||
| } | ||
|
|
||
| async initialize(): Promise<void> { | ||
| this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| } | ||
|
|
||
| dispose(): void {} | ||
|
|
||
| mockConnectResults(results: ConnectionStatus[]) { | ||
| this.connectResults = results; | ||
| } | ||
|
|
||
| async connect(): Promise<ConnectionStatus> { | ||
| if (this.connectResults.length > 0) { | ||
| for (const result of this.connectResults) { | ||
| this.setStatus(result); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| } | ||
| return this.status; | ||
| } | ||
| this.setStatus(ConnectionStatus.CONNECTING); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| this.setStatus(ConnectionStatus.CONNECTED); | ||
| return this.status; | ||
| } | ||
|
|
||
| getBoardVersion(): BoardVersion | undefined { | ||
| return "V2"; | ||
| } | ||
|
|
||
| async disconnect(): Promise<void> {} | ||
| async serialWrite(_data: string): Promise<void> {} | ||
| setNameFilter(_name: string): void {} | ||
|
|
||
| clearDevice(): void { | ||
| this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE); | ||
| } | ||
|
|
||
| async getAccelerometerData(): Promise<undefined> {} | ||
| async getAccelerometerPeriod(): Promise<undefined> {} | ||
| async setAccelerometerPeriod(_value: number): Promise<void> {} | ||
| async setLedText(_text: string): Promise<void> {} | ||
| async getLedScrollingDelay(): Promise<undefined> {} | ||
| async setLedScrollingDelay(_delayInMillis: number): Promise<void> {} | ||
| async getLedMatrix(): Promise<undefined> {} | ||
| async setLedMatrix(_matrix: LedMatrix): Promise<void> {} | ||
| async getMagnetometerData(): Promise<undefined> {} | ||
| async getMagnetometerBearing(): Promise<undefined> {} | ||
| async getMagnetometerPeriod(): Promise<undefined> {} | ||
| async setMagnetometerPeriod(_value: number): Promise<void> {} | ||
| async triggerMagnetometerCalibration(): Promise<void> {} | ||
| async writeUART(_data: Uint8Array): Promise<void> {} | ||
| } |
This file contains hidden or 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,57 @@ | ||
| import { | ||
| BoardVersion, | ||
| ConnectionStatus, | ||
| ConnectionStatusEvent, | ||
| DeviceConnectionEventMap, | ||
| MicrobitRadioBridgeConnection, | ||
| MicrobitWebUSBConnection, | ||
| ServiceConnectionEventMap, | ||
| TypedEventTarget, | ||
| } from "@microbit/microbit-connection"; | ||
|
|
||
| export class MockRadioBridgeConnection | ||
| extends TypedEventTarget<DeviceConnectionEventMap & ServiceConnectionEventMap> | ||
| implements MicrobitRadioBridgeConnection | ||
| { | ||
| status: ConnectionStatus; | ||
|
|
||
| constructor(private delegate: MicrobitWebUSBConnection) { | ||
| super(); | ||
| this.status = this.statusFromDelegate(); | ||
| } | ||
|
|
||
| private statusFromDelegate(): ConnectionStatus { | ||
| return this.delegate.status == ConnectionStatus.CONNECTED | ||
| ? ConnectionStatus.DISCONNECTED | ||
| : this.delegate.status; | ||
| } | ||
|
|
||
| async initialize(): Promise<void> {} | ||
| dispose(): void {} | ||
| setRemoteDeviceId(_deviceId: number): void {} | ||
| async disconnect(): Promise<void> {} | ||
|
|
||
| private setStatus(newStatus: ConnectionStatus) { | ||
| this.status = newStatus; | ||
| this.dispatchTypedEvent("status", new ConnectionStatusEvent(newStatus)); | ||
| } | ||
|
|
||
| async connect(): Promise<ConnectionStatus> { | ||
| await this.delegate.connect(); | ||
| this.setStatus(ConnectionStatus.CONNECTING); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| this.setStatus(ConnectionStatus.CONNECTED); | ||
| return this.status; | ||
| } | ||
|
|
||
| getBoardVersion(): BoardVersion | undefined { | ||
| return this.delegate.getBoardVersion(); | ||
| } | ||
|
|
||
| serialWrite(data: string): Promise<void> { | ||
| return this.delegate.serialWrite(data); | ||
| } | ||
| async clearDevice(): Promise<void> { | ||
| await this.delegate.clearDevice(); | ||
| } | ||
| } |
This file contains hidden or 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,89 @@ | ||
| import { | ||
| AfterRequestDevice, | ||
| BeforeRequestDevice, | ||
| BoardVersion, | ||
| ConnectionStatus, | ||
| ConnectionStatusEvent, | ||
| DeviceConnectionEventMap, | ||
| FlashDataSource, | ||
| FlashEvent, | ||
| FlashOptions, | ||
| MicrobitWebUSBConnection, | ||
| SerialConnectionEventMap, | ||
| TypedEventTarget, | ||
| } from "@microbit/microbit-connection"; | ||
|
|
||
| /** | ||
| * A mock USB connection used during end-to-end testing. | ||
| */ | ||
| export class MockWebUSBConnection | ||
| extends TypedEventTarget<DeviceConnectionEventMap & SerialConnectionEventMap> | ||
| implements MicrobitWebUSBConnection | ||
| { | ||
| status: ConnectionStatus = ConnectionStatus.NO_AUTHORIZED_DEVICE; | ||
|
|
||
| private fakeDeviceId: number | undefined = 123; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| // Make globally available to allow e2e tests to configure interactions. | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access | ||
| (window as any).mockUsb = this; | ||
| this.fakeDeviceId = Math.round(Math.random() * 1000); | ||
| } | ||
| async initialize(): Promise<void> {} | ||
| dispose(): void {} | ||
|
|
||
| mockDeviceId(deviceId: number | undefined) { | ||
| this.fakeDeviceId = deviceId; | ||
| } | ||
|
|
||
| private setStatus(newStatus: ConnectionStatus) { | ||
| this.status = newStatus; | ||
| this.dispatchTypedEvent("status", new ConnectionStatusEvent(newStatus)); | ||
| } | ||
|
|
||
| async connect(): Promise<ConnectionStatus> { | ||
| this.dispatchTypedEvent("beforerequestdevice", new BeforeRequestDevice()); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| this.dispatchTypedEvent("afterrequestdevice", new AfterRequestDevice()); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| this.setStatus(ConnectionStatus.CONNECTED); | ||
| return this.status; | ||
| } | ||
|
|
||
| getDeviceId(): number | undefined { | ||
| return this.fakeDeviceId; | ||
| } | ||
|
|
||
| getBoardVersion(): BoardVersion | undefined { | ||
| return "V2"; | ||
| } | ||
|
|
||
| async flash( | ||
| _dataSource: FlashDataSource, | ||
| options: FlashOptions | ||
| ): Promise<void> { | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| options.progress(50, options.partial); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| options.progress(undefined, options.partial); | ||
| this.dispatchTypedEvent("flash", new FlashEvent()); | ||
| } | ||
|
|
||
| async disconnect(): Promise<void> {} | ||
| async serialWrite(_data: string): Promise<void> {} | ||
|
|
||
| clearDevice(): void { | ||
| this.fakeDeviceId = undefined; | ||
| this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE); | ||
| } | ||
|
|
||
| setRequestDeviceExclusionFilters( | ||
| _exclusionFilters: USBDeviceFilter[] | ||
| ): void {} | ||
| getDevice(): USBDevice | undefined { | ||
| return undefined; | ||
| } | ||
| async softwareReset(): Promise<void> {} | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.