@nordicsemiconductor/pc-nrfconnect-shared 60.0.0-pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/custom.md +10 -0
- package/.husky/pre-push +3 -0
- package/.renovaterc.json +10 -0
- package/Changelog.md +2973 -0
- package/LICENSE +35 -0
- package/README.md +11 -0
- package/azure-pipelines.yml +34 -0
- package/config/eslintrc.js +190 -0
- package/config/jest.config.js +41 -0
- package/config/prettier.config.js +13 -0
- package/config/tsconfig.json +15 -0
- package/fw/bootloader/graviton_bootloader_v1.0.1-[nRF5_SDK_15.0.1-1.alpha_f76d012].zip +0 -0
- package/jest.config.js +7 -0
- package/main/index.ts +32 -0
- package/mocks/deviceLibMock.ts +21 -0
- package/mocks/electronMock.ts +15 -0
- package/mocks/electronStoreMock.ts +19 -0
- package/mocks/emptyMock.ts +7 -0
- package/mocks/fileMock.ts +13 -0
- package/mocks/gaMock.ts +9 -0
- package/mocks/mockTests.test.ts +15 -0
- package/mocks/packageJsonMock.ts +10 -0
- package/mocks/remoteMock.ts +17 -0
- package/package.json +132 -0
- package/scripts/check-app-properties.ts +197 -0
- package/scripts/check-for-typescript.ts +41 -0
- package/scripts/esbuild-bootstrap.js +15 -0
- package/scripts/esbuild-renderer.js +131 -0
- package/scripts/esbuild.js +57 -0
- package/scripts/installHusky.ts +17 -0
- package/scripts/nordic-publish.ts +485 -0
- package/scripts/nrfconnect-license.ts +277 -0
- package/scripts/prepare-shared-release.ts +122 -0
- package/scripts/release-shared.test.ts +132 -0
- package/scripts/release-shared.ts +207 -0
- package/src/About/About.tsx +25 -0
- package/src/About/AboutButton.tsx +28 -0
- package/src/About/ApplicationCard.tsx +83 -0
- package/src/About/DeviceCard.tsx +74 -0
- package/src/About/DocumentationCard.tsx +18 -0
- package/src/About/DocumentationSection.tsx +24 -0
- package/src/About/Section.tsx +21 -0
- package/src/About/ShortcutButton.tsx +41 -0
- package/src/About/SupportCard.tsx +97 -0
- package/src/About/about.scss +40 -0
- package/src/About/documentationSlice.ts +41 -0
- package/src/About/section.scss +15 -0
- package/src/About/shortcutSlice.ts +52 -0
- package/src/Alert/Alert.module.scss +29 -0
- package/src/Alert/Alert.tsx +37 -0
- package/src/App/App.test.tsx +47 -0
- package/src/App/App.tsx +227 -0
- package/src/App/ConnectedToStore.tsx +19 -0
- package/src/App/VisibilityBar.tsx +103 -0
- package/src/App/app.scss +83 -0
- package/src/App/appLayout.ts +95 -0
- package/src/App/shared.scss +49 -0
- package/src/App/visibility-bar.scss +55 -0
- package/src/Button/Button.tsx +66 -0
- package/src/Button/button.module.scss +154 -0
- package/src/Card/Card.tsx +26 -0
- package/src/Card/card.module.scss +28 -0
- package/src/Device/BrokenDeviceDialog/BrokenDeviceDialog.tsx +58 -0
- package/src/Device/BrokenDeviceDialog/broken-device-dialog.scss +18 -0
- package/src/Device/BrokenDeviceDialog/brokenDeviceDialogSlice.tsx +48 -0
- package/src/Device/DeviceSelector/BasicDeviceInfo.tsx +115 -0
- package/src/Device/DeviceSelector/DeviceIcon.tsx +27 -0
- package/src/Device/DeviceSelector/DeviceList/AnimatedList.tsx +62 -0
- package/src/Device/DeviceSelector/DeviceList/BrokenDevice.tsx +34 -0
- package/src/Device/DeviceSelector/DeviceList/Device.tsx +84 -0
- package/src/Device/DeviceSelector/DeviceList/DeviceList.tsx +113 -0
- package/src/Device/DeviceSelector/DeviceList/EditDeviceButtons.tsx +28 -0
- package/src/Device/DeviceSelector/DeviceList/MoreDeviceInfo.tsx +65 -0
- package/src/Device/DeviceSelector/DeviceList/RenameDevice.tsx +22 -0
- package/src/Device/DeviceSelector/DeviceList/broken-device.scss +32 -0
- package/src/Device/DeviceSelector/DeviceList/device-list.scss +64 -0
- package/src/Device/DeviceSelector/DeviceList/device.scss +28 -0
- package/src/Device/DeviceSelector/DeviceList/edit-device-buttons.scss +31 -0
- package/src/Device/DeviceSelector/DeviceList/more-device-info.scss +33 -0
- package/src/Device/DeviceSelector/DeviceList/rename-device.scss +13 -0
- package/src/Device/DeviceSelector/DeviceSelector.test.tsx +342 -0
- package/src/Device/DeviceSelector/DeviceSelector.tsx +173 -0
- package/src/Device/DeviceSelector/Favorite.tsx +49 -0
- package/src/Device/DeviceSelector/SelectDevice.tsx +36 -0
- package/src/Device/DeviceSelector/SelectedDevice.tsx +65 -0
- package/src/Device/DeviceSelector/arrow-down.svg +1 -0
- package/src/Device/DeviceSelector/basic-device-info.scss +62 -0
- package/src/Device/DeviceSelector/device-icon.scss +27 -0
- package/src/Device/DeviceSelector/favorite.scss +17 -0
- package/src/Device/DeviceSelector/select-device.scss +38 -0
- package/src/Device/DeviceSelector/selected-device.scss +57 -0
- package/src/Device/DeviceSetup/DeviceSetupView.tsx +102 -0
- package/src/Device/deviceAutoSelectSlice.ts +144 -0
- package/src/Device/deviceInfo/deviceInfo.ts +254 -0
- package/src/Device/deviceInfo/nRF51-Series-logo.svg +1 -0
- package/src/Device/deviceInfo/nRF52-Series-logo.svg +1 -0
- package/src/Device/deviceInfo/nRF53-Series-logo.svg +1 -0
- package/src/Device/deviceInfo/nRF70-Series_no-background_RGB.svg +36 -0
- package/src/Device/deviceInfo/nRF91-Series-logo.svg +1 -0
- package/src/Device/deviceInfo/ppk-logo.svg +1 -0
- package/src/Device/deviceInfo/unknown-logo.svg +30 -0
- package/src/Device/deviceInfo/unknown-nordic-logo.svg +25 -0
- package/src/Device/deviceLibWrapper.test.ts +97 -0
- package/src/Device/deviceLibWrapper.ts +133 -0
- package/src/Device/deviceLister.test.ts +89 -0
- package/src/Device/deviceLister.ts +396 -0
- package/src/Device/deviceSetup.ts +264 -0
- package/src/Device/deviceSetupSlice.ts +94 -0
- package/src/Device/deviceSlice.ts +248 -0
- package/src/Device/dfu-cc.ts +162 -0
- package/src/Device/initPacket.ts +402 -0
- package/src/Device/jprogOperations.ts +206 -0
- package/src/Device/sdfuOperations.ts +601 -0
- package/src/Dialog/Dialog.test.tsx +134 -0
- package/src/Dialog/Dialog.tsx +236 -0
- package/src/Dialog/dialog.scss +60 -0
- package/src/Dropdown/Dropdown.module.scss +83 -0
- package/src/Dropdown/Dropdown.test.tsx +62 -0
- package/src/Dropdown/Dropdown.tsx +106 -0
- package/src/ErrorBoundary/ErrorBoundary.test.tsx +105 -0
- package/src/ErrorBoundary/ErrorBoundary.tsx +186 -0
- package/src/ErrorBoundary/bug.svg +1 -0
- package/src/ErrorBoundary/error-boundary.scss +102 -0
- package/src/ErrorDialog/ErrorDialog.test.tsx +70 -0
- package/src/ErrorDialog/ErrorDialog.tsx +94 -0
- package/src/ErrorDialog/error.scss +14 -0
- package/src/ErrorDialog/errorDialogSlice.test.ts +64 -0
- package/src/ErrorDialog/errorDialogSlice.ts +80 -0
- package/src/FactoryReset/FactoryResetButton.test.tsx +46 -0
- package/src/FactoryReset/FactoryResetButton.tsx +81 -0
- package/src/InlineInput/InlineInput.tsx +170 -0
- package/src/InlineInput/NumberInlineInput.tsx +107 -0
- package/src/InlineInput/inline-input.scss +38 -0
- package/src/InlineInput/number-inline-input.scss +15 -0
- package/src/Log/LogEntry.tsx +62 -0
- package/src/Log/LogViewer.tsx +54 -0
- package/src/Log/log-entry.scss +30 -0
- package/src/Log/log-viewer.scss +24 -0
- package/src/Log/logSlice.ts +73 -0
- package/src/Log/syncLogToStore.ts +36 -0
- package/src/Logo/Logo.tsx +48 -0
- package/src/Logo/logo.scss +11 -0
- package/src/Logo/nordic-logo-blue-icon-only.png +0 -0
- package/src/Logo/nordic-logo-gray-icon-only.png +0 -0
- package/src/Logo/nordic-logo-white-icon-only.png +0 -0
- package/src/Main/Main.tsx +13 -0
- package/src/Main/main.scss +13 -0
- package/src/MasonryLayout/MasonryLayout.tsx +234 -0
- package/src/MasonryLayout/masonryLayout.module.scss +46 -0
- package/src/NavBar/NavBar.tsx +22 -0
- package/src/NavBar/NavMenu.test.tsx +41 -0
- package/src/NavBar/NavMenu.tsx +53 -0
- package/src/NavBar/NavMenuItem.tsx +41 -0
- package/src/NavBar/nav-bar.scss +26 -0
- package/src/NavBar/nav-menu-item.scss +34 -0
- package/src/OpenApp/openApp.ts +18 -0
- package/src/Panes/FeedbackPane.tsx +149 -0
- package/src/PseudoButton/PseudoButton.tsx +56 -0
- package/src/PseudoButton/pseudo-button.scss +11 -0
- package/src/SerialPort/ConflictingSettingsDialog.tsx +242 -0
- package/src/SerialPort/SerialPort.test.ts +54 -0
- package/src/SerialPort/SerialPort.ts +202 -0
- package/src/Shortcuts/Shortcut-item.scss +33 -0
- package/src/Shortcuts/Shortcut-modal.scss +20 -0
- package/src/Shortcuts/ShortcutItem.tsx +48 -0
- package/src/Shortcuts/ShortcutModal.tsx +67 -0
- package/src/SidePanel/Group.tsx +106 -0
- package/src/SidePanel/SidePanel.tsx +19 -0
- package/src/SidePanel/group.scss +42 -0
- package/src/SidePanel/sidepanel.scss +20 -0
- package/src/Slider/Bar.tsx +24 -0
- package/src/Slider/Factor.test.ts +48 -0
- package/src/Slider/Handle.tsx +121 -0
- package/src/Slider/Slider.test.tsx +25 -0
- package/src/Slider/Slider.tsx +91 -0
- package/src/Slider/Ticks.tsx +54 -0
- package/src/Slider/__snapshots__/Slider.test.tsx.snap +50 -0
- package/src/Slider/bar.scss +24 -0
- package/src/Slider/factor.ts +24 -0
- package/src/Slider/handle.scss +32 -0
- package/src/Slider/percentage.ts +67 -0
- package/src/Slider/range.ts +92 -0
- package/src/Slider/slider.scss +14 -0
- package/src/Slider/ticks.scss +28 -0
- package/src/Slider/variables.scss +16 -0
- package/src/StartStopButton/StartStopButton.tsx +60 -0
- package/src/StartStopButton/play-circle.svg +1 -0
- package/src/StartStopButton/start-stop-button.scss +47 -0
- package/src/StartStopButton/stop-circle.svg +1 -0
- package/src/StateSelector/StateSelector.tsx +64 -0
- package/src/StateSelector/state-selector.scss +38 -0
- package/src/Stepper/Stepper.tsx +139 -0
- package/src/Stepper/stepper.scss +127 -0
- package/src/Toggle/Toggle.tsx +120 -0
- package/src/Toggle/toggle.scss +109 -0
- package/src/bootstrap.scss +14 -0
- package/src/index.ts +146 -0
- package/src/logging/appTransport.test.ts +78 -0
- package/src/logging/appTransport.ts +41 -0
- package/src/logging/describeError.test.ts +38 -0
- package/src/logging/describeError.ts +56 -0
- package/src/logging/index.ts +103 -0
- package/src/logging/logBuffer.test.ts +41 -0
- package/src/logging/logBuffer.ts +24 -0
- package/src/logging/sendInitialLogMessages.ts +64 -0
- package/src/store.ts +60 -0
- package/src/svg.d.ts +15 -0
- package/src/utils/AppTypes.ts +60 -0
- package/src/utils/appDirs.ts +78 -0
- package/src/utils/bleChannels.ts +16 -0
- package/src/utils/classNames.test.ts +29 -0
- package/src/utils/classNames.ts +25 -0
- package/src/utils/colors.scss +46 -0
- package/src/utils/colors.ts +38 -0
- package/src/utils/describeVersion.ts +21 -0
- package/src/utils/environment.ts +6 -0
- package/src/utils/logLibVersions.ts +103 -0
- package/src/utils/open.ts +46 -0
- package/src/utils/packageJson.ts +60 -0
- package/src/utils/persistentStore.ts +144 -0
- package/src/utils/systemReport.ts +160 -0
- package/src/utils/truncateMiddle.test.ts +21 -0
- package/src/utils/truncateMiddle.ts +20 -0
- package/src/utils/usageData.ts +189 -0
- package/src/utils/useHotKey.ts +62 -0
- package/src/utils/useStopwatch.test.tsx +311 -0
- package/src/utils/useStopwatch.ts +140 -0
- package/src/variables.scss +820 -0
- package/styles.scss +88 -0
- package/test/dispatchTo.ts +23 -0
- package/test/index.ts +7 -0
- package/test/jestResolver.js +28 -0
- package/test/setupTests.ts +27 -0
- package/test/testUtil.ts +20 -0
- package/test/testrenderer.tsx +39 -0
- package/tsconfig.json +9 -0
- package/typings/externals.d.ts +31 -0
- package/typings/generated/main/index.d.ts +25 -0
- package/typings/generated/src/About/About.d.ts +4 -0
- package/typings/generated/src/About/AboutButton.d.ts +8 -0
- package/typings/generated/src/About/ApplicationCard.d.ts +3 -0
- package/typings/generated/src/About/DeviceCard.d.ts +3 -0
- package/typings/generated/src/About/DocumentationCard.d.ts +3 -0
- package/typings/generated/src/About/DocumentationSection.d.ts +9 -0
- package/typings/generated/src/About/Section.d.ts +8 -0
- package/typings/generated/src/About/ShortcutButton.d.ts +6 -0
- package/typings/generated/src/About/SupportCard.d.ts +3 -0
- package/typings/generated/src/About/documentationSlice.d.ts +12 -0
- package/typings/generated/src/About/shortcutSlice.d.ts +11 -0
- package/typings/generated/src/Alert/Alert.d.ts +10 -0
- package/typings/generated/src/App/App.d.ts +27 -0
- package/typings/generated/src/App/App.test.d.ts +1 -0
- package/typings/generated/src/App/ConnectedToStore.d.ts +7 -0
- package/typings/generated/src/App/VisibilityBar.d.ts +6 -0
- package/typings/generated/src/App/appLayout.d.ts +17 -0
- package/typings/generated/src/Button/Button.d.ts +13 -0
- package/typings/generated/src/Card/Card.d.ts +7 -0
- package/typings/generated/src/Device/BrokenDeviceDialog/BrokenDeviceDialog.d.ts +4 -0
- package/typings/generated/src/Device/BrokenDeviceDialog/brokenDeviceDialogSlice.d.ts +12 -0
- package/typings/generated/src/Device/DeviceSelector/BasicDeviceInfo.d.ts +11 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceIcon.d.ts +7 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/AnimatedList.d.ts +10 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/BrokenDevice.d.ts +7 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/Device.d.ts +10 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/DeviceList.d.ts +10 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/EditDeviceButtons.d.ts +9 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/MoreDeviceInfo.d.ts +7 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceList/RenameDevice.d.ts +6 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceSelector.d.ts +20 -0
- package/typings/generated/src/Device/DeviceSelector/DeviceSelector.test.d.ts +1 -0
- package/typings/generated/src/Device/DeviceSelector/Favorite.d.ts +9 -0
- package/typings/generated/src/Device/DeviceSelector/SelectDevice.d.ts +8 -0
- package/typings/generated/src/Device/DeviceSelector/SelectedDevice.d.ts +7 -0
- package/typings/generated/src/Device/DeviceSetup/DeviceSetupView.d.ts +3 -0
- package/typings/generated/src/Device/deviceAutoSelectSlice.d.ts +28 -0
- package/typings/generated/src/Device/deviceInfo/deviceInfo.d.ts +18 -0
- package/typings/generated/src/Device/deviceLibWrapper.d.ts +8 -0
- package/typings/generated/src/Device/deviceLibWrapper.test.d.ts +1 -0
- package/typings/generated/src/Device/deviceLister.d.ts +25 -0
- package/typings/generated/src/Device/deviceLister.test.d.ts +2 -0
- package/typings/generated/src/Device/deviceSetup.d.ts +40 -0
- package/typings/generated/src/Device/deviceSetupSlice.d.ts +20 -0
- package/typings/generated/src/Device/deviceSlice.d.ts +30 -0
- package/typings/generated/src/Device/dfu-cc.d.ts +3 -0
- package/typings/generated/src/Device/initPacket.d.ts +109 -0
- package/typings/generated/src/Device/jprogOperations.d.ts +2 -0
- package/typings/generated/src/Device/sdfuOperations.d.ts +14 -0
- package/typings/generated/src/Dialog/Dialog.d.ts +64 -0
- package/typings/generated/src/Dialog/Dialog.test.d.ts +1 -0
- package/typings/generated/src/Dropdown/Dropdown.d.ts +16 -0
- package/typings/generated/src/Dropdown/Dropdown.test.d.ts +1 -0
- package/typings/generated/src/ErrorBoundary/ErrorBoundary.d.ts +26 -0
- package/typings/generated/src/ErrorBoundary/ErrorBoundary.test.d.ts +1 -0
- package/typings/generated/src/ErrorDialog/ErrorDialog.d.ts +4 -0
- package/typings/generated/src/ErrorDialog/ErrorDialog.test.d.ts +1 -0
- package/typings/generated/src/ErrorDialog/errorDialogSlice.d.ts +23 -0
- package/typings/generated/src/ErrorDialog/errorDialogSlice.test.d.ts +1 -0
- package/typings/generated/src/FactoryReset/FactoryResetButton.d.ts +12 -0
- package/typings/generated/src/FactoryReset/FactoryResetButton.test.d.ts +1 -0
- package/typings/generated/src/InlineInput/InlineInput.d.ts +14 -0
- package/typings/generated/src/InlineInput/NumberInlineInput.d.ts +12 -0
- package/typings/generated/src/Log/LogEntry.d.ts +7 -0
- package/typings/generated/src/Log/LogViewer.d.ts +5 -0
- package/typings/generated/src/Log/logSlice.d.ts +12 -0
- package/typings/generated/src/Log/syncLogToStore.d.ts +11 -0
- package/typings/generated/src/Logo/Logo.d.ts +6 -0
- package/typings/generated/src/Main/Main.d.ts +6 -0
- package/typings/generated/src/MasonryLayout/MasonryLayout.d.ts +14 -0
- package/typings/generated/src/NavBar/NavBar.d.ts +6 -0
- package/typings/generated/src/NavBar/NavMenu.d.ts +3 -0
- package/typings/generated/src/NavBar/NavMenu.test.d.ts +1 -0
- package/typings/generated/src/NavBar/NavMenuItem.d.ts +10 -0
- package/typings/generated/src/OpenApp/openApp.d.ts +7 -0
- package/typings/generated/src/Panes/FeedbackPane.d.ts +3 -0
- package/typings/generated/src/PseudoButton/PseudoButton.d.ts +10 -0
- package/typings/generated/src/SerialPort/ConflictingSettingsDialog.d.ts +13 -0
- package/typings/generated/src/SerialPort/SerialPort.d.ts +21 -0
- package/typings/generated/src/SerialPort/SerialPort.test.d.ts +1 -0
- package/typings/generated/src/Shortcuts/ShortcutItem.d.ts +8 -0
- package/typings/generated/src/Shortcuts/ShortcutModal.d.ts +8 -0
- package/typings/generated/src/SidePanel/Group.d.ts +16 -0
- package/typings/generated/src/SidePanel/SidePanel.d.ts +7 -0
- package/typings/generated/src/Slider/Bar.d.ts +7 -0
- package/typings/generated/src/Slider/Factor.test.d.ts +1 -0
- package/typings/generated/src/Slider/Handle.d.ts +13 -0
- package/typings/generated/src/Slider/Slider.d.ts +15 -0
- package/typings/generated/src/Slider/Slider.test.d.ts +1 -0
- package/typings/generated/src/Slider/Ticks.d.ts +12 -0
- package/typings/generated/src/Slider/factor.d.ts +1 -0
- package/typings/generated/src/Slider/percentage.d.ts +4 -0
- package/typings/generated/src/Slider/range.d.ts +13 -0
- package/typings/generated/src/StartStopButton/StartStopButton.d.ts +16 -0
- package/typings/generated/src/StateSelector/StateSelector.d.ts +15 -0
- package/typings/generated/src/Stepper/Stepper.d.ts +26 -0
- package/typings/generated/src/Toggle/Toggle.d.ts +19 -0
- package/typings/generated/src/index.d.ts +69 -0
- package/typings/generated/src/logging/appTransport.d.ts +12 -0
- package/typings/generated/src/logging/appTransport.test.d.ts +1 -0
- package/typings/generated/src/logging/describeError.d.ts +2 -0
- package/typings/generated/src/logging/describeError.test.d.ts +1 -0
- package/typings/generated/src/logging/index.d.ts +9 -0
- package/typings/generated/src/logging/logBuffer.d.ts +9 -0
- package/typings/generated/src/logging/logBuffer.test.d.ts +1 -0
- package/typings/generated/src/logging/sendInitialLogMessages.d.ts +2 -0
- package/typings/generated/src/store.d.ts +65 -0
- package/typings/generated/src/utils/AppTypes.d.ts +49 -0
- package/typings/generated/src/utils/appDirs.d.ts +35 -0
- package/typings/generated/src/utils/bleChannels.d.ts +6 -0
- package/typings/generated/src/utils/classNames.d.ts +17 -0
- package/typings/generated/src/utils/classNames.test.d.ts +1 -0
- package/typings/generated/src/utils/colors.d.ts +31 -0
- package/typings/generated/src/utils/describeVersion.d.ts +3 -0
- package/typings/generated/src/utils/environment.d.ts +1 -0
- package/typings/generated/src/utils/logLibVersions.d.ts +2 -0
- package/typings/generated/src/utils/open.d.ts +15 -0
- package/typings/generated/src/utils/packageJson.d.ts +4 -0
- package/typings/generated/src/utils/persistentStore.d.ts +35 -0
- package/typings/generated/src/utils/systemReport.d.ts +4 -0
- package/typings/generated/src/utils/truncateMiddle.d.ts +2 -0
- package/typings/generated/src/utils/truncateMiddle.test.d.ts +1 -0
- package/typings/generated/src/utils/usageData.d.ts +63 -0
- package/typings/generated/src/utils/useHotKey.d.ts +6 -0
- package/typings/generated/src/utils/useStopwatch.d.ts +22 -0
- package/typings/generated/src/utils/useStopwatch.test.d.ts +1 -0
- package/typings/generated/test/dispatchTo.d.ts +3 -0
- package/typings/generated/test/testrenderer.d.ts +5 -0
- package/typings/nrf-intel-hex.d.ts +58 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 Nordic Semiconductor ASA
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { act, render } from '@testing-library/react';
|
|
9
|
+
|
|
10
|
+
import useStopWatch, { ITimer, Stopwatch } from './useStopwatch';
|
|
11
|
+
|
|
12
|
+
let appCallback = () => {};
|
|
13
|
+
|
|
14
|
+
const setup = (stopwatch: Stopwatch) => {
|
|
15
|
+
const returnVal = {};
|
|
16
|
+
const TestComponent = () => {
|
|
17
|
+
Object.assign(returnVal, useStopWatch(stopwatch));
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
render(<TestComponent />);
|
|
21
|
+
return returnVal as ReturnType<typeof useStopWatch>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('Stop Watch', () => {
|
|
25
|
+
const mockNow = jest.fn(() => 0);
|
|
26
|
+
const mockSetTimeout = jest.fn((callback: () => void) => {
|
|
27
|
+
appCallback = callback;
|
|
28
|
+
return () => {};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const timerMock: ITimer = {
|
|
32
|
+
now: mockNow,
|
|
33
|
+
setTimeout: mockSetTimeout,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const expectZeroElapsedTime = (
|
|
37
|
+
stopwatch: ReturnType<typeof useStopWatch>
|
|
38
|
+
) => {
|
|
39
|
+
expect(stopwatch.time).toBe(0);
|
|
40
|
+
expect(stopwatch.seconds).toBe(0);
|
|
41
|
+
expect(stopwatch.minutes).toBe(0);
|
|
42
|
+
expect(stopwatch.hours).toBe(0);
|
|
43
|
+
expect(stopwatch.days).toBe(0);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
mockNow.mockReturnValue(0);
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('Auto Start will init timer', () => {
|
|
52
|
+
const { isRunning } = setup({
|
|
53
|
+
autoStart: true,
|
|
54
|
+
resolution: 1000,
|
|
55
|
+
timer: timerMock,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(timerMock.setTimeout).toBeCalledTimes(1);
|
|
59
|
+
expect(timerMock.setTimeout).toBeCalledWith(expect.anything(), 1000);
|
|
60
|
+
expect(isRunning).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('Pause will stop the stopwatch and report elapsed time', () => {
|
|
64
|
+
const stopwatch = setup({
|
|
65
|
+
autoStart: true,
|
|
66
|
+
resolution: 1000,
|
|
67
|
+
timer: timerMock,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(timerMock.setTimeout).toBeCalledTimes(1);
|
|
71
|
+
expect(timerMock.setTimeout).toBeCalledWith(expect.anything(), 1000);
|
|
72
|
+
expect(stopwatch.isRunning).toBeTruthy();
|
|
73
|
+
|
|
74
|
+
expectZeroElapsedTime(stopwatch);
|
|
75
|
+
|
|
76
|
+
mockNow.mockReturnValue(433);
|
|
77
|
+
|
|
78
|
+
act(() => {
|
|
79
|
+
stopwatch.pause();
|
|
80
|
+
stopwatch;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(stopwatch.time).toBe(433);
|
|
84
|
+
expect(stopwatch.seconds).toBe(0);
|
|
85
|
+
expect(stopwatch.minutes).toBe(0);
|
|
86
|
+
expect(stopwatch.hours).toBe(0);
|
|
87
|
+
expect(stopwatch.days).toBe(0);
|
|
88
|
+
expect(stopwatch.isRunning).toBeFalsy();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('Start a paused timer will continue timer', () => {
|
|
92
|
+
const stopwatch = setup({
|
|
93
|
+
autoStart: true,
|
|
94
|
+
resolution: 1000,
|
|
95
|
+
timer: timerMock,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(timerMock.setTimeout).toBeCalledTimes(1);
|
|
99
|
+
expect(timerMock.setTimeout).toBeCalledWith(expect.anything(), 1000);
|
|
100
|
+
expect(stopwatch.isRunning).toBeTruthy();
|
|
101
|
+
|
|
102
|
+
expectZeroElapsedTime(stopwatch);
|
|
103
|
+
|
|
104
|
+
expect(timerMock.setTimeout).nthCalledWith(1, expect.anything(), 1000);
|
|
105
|
+
|
|
106
|
+
mockNow.mockReturnValue(500);
|
|
107
|
+
|
|
108
|
+
act(() => {
|
|
109
|
+
stopwatch.pause();
|
|
110
|
+
stopwatch;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(stopwatch.time).toBe(500);
|
|
114
|
+
expect(stopwatch.seconds).toBe(0);
|
|
115
|
+
expect(stopwatch.minutes).toBe(0);
|
|
116
|
+
expect(stopwatch.hours).toBe(0);
|
|
117
|
+
expect(stopwatch.days).toBe(0);
|
|
118
|
+
expect(stopwatch.isRunning).toBeFalsy();
|
|
119
|
+
|
|
120
|
+
mockNow.mockReturnValue(5000);
|
|
121
|
+
|
|
122
|
+
act(() => {
|
|
123
|
+
stopwatch.start();
|
|
124
|
+
stopwatch;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(timerMock.setTimeout).toBeCalledTimes(2);
|
|
128
|
+
expect(timerMock.setTimeout).nthCalledWith(2, expect.anything(), 500);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('Timer will not automatically start', () => {
|
|
132
|
+
const { isRunning } = setup({
|
|
133
|
+
autoStart: false,
|
|
134
|
+
resolution: 1000,
|
|
135
|
+
timer: timerMock,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(timerMock.setTimeout).toBeCalledTimes(0);
|
|
139
|
+
expect(isRunning).toBeFalsy();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('Start call will start the timer', () => {
|
|
143
|
+
const stopwatch = setup({
|
|
144
|
+
autoStart: false,
|
|
145
|
+
resolution: 1000,
|
|
146
|
+
timer: timerMock,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(timerMock.setTimeout).toBeCalledTimes(0);
|
|
150
|
+
expect(stopwatch.isRunning).toBeFalsy();
|
|
151
|
+
|
|
152
|
+
mockNow.mockReturnValue(5000);
|
|
153
|
+
|
|
154
|
+
act(() => {
|
|
155
|
+
stopwatch.start();
|
|
156
|
+
stopwatch;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(timerMock.setTimeout).toBeCalledTimes(1);
|
|
160
|
+
expect(timerMock.setTimeout).toBeCalledWith(expect.anything(), 1000);
|
|
161
|
+
expect(stopwatch.isRunning).toBeTruthy();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('Reset will reset all time the stopwatch and report elapsed time', () => {
|
|
165
|
+
const stopwatch = setup({
|
|
166
|
+
autoStart: true,
|
|
167
|
+
resolution: 1000,
|
|
168
|
+
timer: timerMock,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(timerMock.setTimeout).toBeCalledTimes(1);
|
|
172
|
+
expect(timerMock.setTimeout).nthCalledWith(1, expect.anything(), 1000);
|
|
173
|
+
expect(stopwatch.isRunning).toBeTruthy();
|
|
174
|
+
|
|
175
|
+
expectZeroElapsedTime(stopwatch);
|
|
176
|
+
|
|
177
|
+
mockNow.mockReturnValue(1200);
|
|
178
|
+
|
|
179
|
+
act(() => {
|
|
180
|
+
appCallback();
|
|
181
|
+
stopwatch;
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(timerMock.setTimeout).nthCalledWith(2, expect.anything(), 800);
|
|
185
|
+
|
|
186
|
+
expect(stopwatch.time).toBe(1200);
|
|
187
|
+
expect(stopwatch.seconds).toBe(1);
|
|
188
|
+
expect(stopwatch.minutes).toBe(0);
|
|
189
|
+
expect(stopwatch.hours).toBe(0);
|
|
190
|
+
expect(stopwatch.days).toBe(0);
|
|
191
|
+
expect(stopwatch.isRunning).toBeTruthy();
|
|
192
|
+
|
|
193
|
+
mockNow.mockReturnValue(6800);
|
|
194
|
+
act(() => {
|
|
195
|
+
stopwatch.reset();
|
|
196
|
+
stopwatch;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(timerMock.setTimeout).nthCalledWith(3, expect.anything(), 1000);
|
|
200
|
+
|
|
201
|
+
expectZeroElapsedTime(stopwatch);
|
|
202
|
+
expect(stopwatch.isRunning).toBeTruthy();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('Time will update output after precise interval elapsed trigger a new timeout', () => {
|
|
206
|
+
const stopwatch = setup({
|
|
207
|
+
autoStart: true,
|
|
208
|
+
resolution: 1000,
|
|
209
|
+
timer: timerMock,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expectZeroElapsedTime(stopwatch);
|
|
213
|
+
|
|
214
|
+
// trigger timeout with precise time elapsed
|
|
215
|
+
mockNow.mockReturnValue(1000);
|
|
216
|
+
|
|
217
|
+
act(() => {
|
|
218
|
+
appCallback();
|
|
219
|
+
stopwatch;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
expect(timerMock.setTimeout).toBeCalledTimes(2);
|
|
223
|
+
expect(timerMock.setTimeout).toBeCalledWith(expect.anything(), 1000);
|
|
224
|
+
|
|
225
|
+
expect(stopwatch.time).toBe(1000);
|
|
226
|
+
expect(stopwatch.seconds).toBe(1);
|
|
227
|
+
expect(stopwatch.minutes).toBe(0);
|
|
228
|
+
expect(stopwatch.hours).toBe(0);
|
|
229
|
+
expect(stopwatch.days).toBe(0);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('Time will update trigger a new timeout and add positive correction', () => {
|
|
233
|
+
const stopwatch = setup({
|
|
234
|
+
autoStart: true,
|
|
235
|
+
resolution: 1000,
|
|
236
|
+
timer: timerMock,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expectZeroElapsedTime(stopwatch);
|
|
240
|
+
|
|
241
|
+
// trigger timeout with error of -200ms
|
|
242
|
+
mockNow.mockReturnValue(800);
|
|
243
|
+
|
|
244
|
+
act(() => {
|
|
245
|
+
appCallback();
|
|
246
|
+
stopwatch;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
expect(timerMock.setTimeout).toBeCalledTimes(2);
|
|
250
|
+
expect(timerMock.setTimeout).nthCalledWith(1, expect.anything(), 1000);
|
|
251
|
+
expect(timerMock.setTimeout).nthCalledWith(2, expect.anything(), 200);
|
|
252
|
+
|
|
253
|
+
expect(stopwatch.time).toBe(800);
|
|
254
|
+
expect(stopwatch.seconds).toBe(0);
|
|
255
|
+
expect(stopwatch.minutes).toBe(0);
|
|
256
|
+
expect(stopwatch.hours).toBe(0);
|
|
257
|
+
expect(stopwatch.days).toBe(0);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('Time will update trigger a new timeout and add negative correction', () => {
|
|
261
|
+
const stopwatch = setup({
|
|
262
|
+
autoStart: true,
|
|
263
|
+
resolution: 1000,
|
|
264
|
+
timer: timerMock,
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
expectZeroElapsedTime(stopwatch);
|
|
268
|
+
|
|
269
|
+
// trigger timeout with error of +200ms
|
|
270
|
+
mockNow.mockReturnValue(1200);
|
|
271
|
+
|
|
272
|
+
act(() => {
|
|
273
|
+
appCallback();
|
|
274
|
+
stopwatch;
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
expect(timerMock.setTimeout).toBeCalledTimes(2);
|
|
278
|
+
expect(timerMock.setTimeout).nthCalledWith(1, expect.anything(), 1000);
|
|
279
|
+
expect(timerMock.setTimeout).nthCalledWith(2, expect.anything(), 800);
|
|
280
|
+
|
|
281
|
+
expect(stopwatch.time).toBe(1200);
|
|
282
|
+
expect(stopwatch.seconds).toBe(1);
|
|
283
|
+
expect(stopwatch.minutes).toBe(0);
|
|
284
|
+
expect(stopwatch.hours).toBe(0);
|
|
285
|
+
expect(stopwatch.days).toBe(0);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('Test time part splitting', () => {
|
|
289
|
+
const stopwatch = setup({
|
|
290
|
+
autoStart: true,
|
|
291
|
+
resolution: 1000,
|
|
292
|
+
timer: timerMock,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expectZeroElapsedTime(stopwatch);
|
|
296
|
+
|
|
297
|
+
// 2days 1hr 1 min 3 seconds 500ms
|
|
298
|
+
mockNow.mockReturnValue(176588500);
|
|
299
|
+
|
|
300
|
+
act(() => {
|
|
301
|
+
appCallback();
|
|
302
|
+
stopwatch;
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
expect(stopwatch.time).toBe(176588500);
|
|
306
|
+
expect(stopwatch.seconds).toBe(8);
|
|
307
|
+
expect(stopwatch.minutes).toBe(3);
|
|
308
|
+
expect(stopwatch.hours).toBe(1);
|
|
309
|
+
expect(stopwatch.days).toBe(2);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 Nordic Semiconductor ASA
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
export interface ITimer {
|
|
10
|
+
now: () => number;
|
|
11
|
+
setTimeout: (callback: () => void, ms: number) => () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Stopwatch = {
|
|
15
|
+
autoStart: boolean;
|
|
16
|
+
resolution?: number;
|
|
17
|
+
timer?: ITimer;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const defaultTimer: ITimer = {
|
|
21
|
+
now: () => Date.now(),
|
|
22
|
+
setTimeout: (callback: () => void, ms: number) => {
|
|
23
|
+
const t = setTimeout(callback, ms);
|
|
24
|
+
return () => clearTimeout(t);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const splitMS = (ms: number) => {
|
|
29
|
+
const time = ms;
|
|
30
|
+
const days = Math.floor(ms / (24 * 60 * 60 * 1000));
|
|
31
|
+
ms -= days * 24 * 60 * 60 * 1000;
|
|
32
|
+
|
|
33
|
+
const hours = Math.floor(ms / (60 * 60 * 1000));
|
|
34
|
+
ms -= hours * 60 * 60 * 1000;
|
|
35
|
+
|
|
36
|
+
const minutes = Math.floor(ms / (60 * 1000));
|
|
37
|
+
ms -= minutes * 60 * 1000;
|
|
38
|
+
|
|
39
|
+
const seconds = Math.floor(ms / 1000);
|
|
40
|
+
const millisecond = ms - seconds * 60 * 1000;
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
time,
|
|
44
|
+
days,
|
|
45
|
+
hours,
|
|
46
|
+
minutes,
|
|
47
|
+
seconds,
|
|
48
|
+
millisecond,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default ({
|
|
53
|
+
autoStart = false,
|
|
54
|
+
timer = defaultTimer,
|
|
55
|
+
resolution = 1000,
|
|
56
|
+
}: Stopwatch) => {
|
|
57
|
+
const previousTickTime = useRef(timer.now());
|
|
58
|
+
const expectedTickTime = useRef(-1);
|
|
59
|
+
const autoStarted = useRef(false);
|
|
60
|
+
const pauseTimeout = useRef<(() => void) | null>(null);
|
|
61
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
62
|
+
const [time, setTime] = useState(0);
|
|
63
|
+
|
|
64
|
+
const nextTick = useCallback(
|
|
65
|
+
(elapsedTime: number) => {
|
|
66
|
+
expectedTickTime.current =
|
|
67
|
+
previousTickTime.current +
|
|
68
|
+
(resolution - (elapsedTime % resolution));
|
|
69
|
+
|
|
70
|
+
const nextInterval = expectedTickTime.current - timer.now();
|
|
71
|
+
|
|
72
|
+
const handler = (delta: number, shouldContinue = true) => {
|
|
73
|
+
setTime(elapsedTime + delta);
|
|
74
|
+
previousTickTime.current = timer.now();
|
|
75
|
+
if (shouldContinue)
|
|
76
|
+
pauseTimeout.current = nextTick(elapsedTime + delta);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const release = timer.setTimeout(() => {
|
|
80
|
+
handler(timer.now() - previousTickTime.current);
|
|
81
|
+
}, nextInterval);
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
handler(timer.now() - previousTickTime.current, false);
|
|
85
|
+
release();
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
[resolution, timer]
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const start = useCallback(
|
|
92
|
+
(elapsedTime = time) => {
|
|
93
|
+
if (pauseTimeout.current === null) {
|
|
94
|
+
previousTickTime.current = timer.now();
|
|
95
|
+
expectedTickTime.current =
|
|
96
|
+
timer.now() + (resolution - (elapsedTime % resolution));
|
|
97
|
+
setIsRunning(true);
|
|
98
|
+
pauseTimeout.current = nextTick(elapsedTime);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
[nextTick, resolution, time, timer]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const pause = useCallback(() => {
|
|
105
|
+
setIsRunning(false);
|
|
106
|
+
if (pauseTimeout.current) {
|
|
107
|
+
pauseTimeout.current();
|
|
108
|
+
pauseTimeout.current = null;
|
|
109
|
+
}
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
const reset = useCallback(() => {
|
|
113
|
+
pause();
|
|
114
|
+
setTime(0);
|
|
115
|
+
start(0);
|
|
116
|
+
}, [pause, start]);
|
|
117
|
+
|
|
118
|
+
useEffect(
|
|
119
|
+
() => () => {
|
|
120
|
+
if (pauseTimeout.current) {
|
|
121
|
+
pauseTimeout.current();
|
|
122
|
+
pauseTimeout.current = null;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
[]
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
if (autoStart && !autoStarted.current) {
|
|
129
|
+
autoStarted.current = true;
|
|
130
|
+
start(0);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
...splitMS(time),
|
|
135
|
+
start,
|
|
136
|
+
pause,
|
|
137
|
+
reset,
|
|
138
|
+
isRunning,
|
|
139
|
+
};
|
|
140
|
+
};
|