Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13951 from code-dot-org/maker-testable-setup-comp…
…onent Maker: Test setup checklist component
- Loading branch information
Showing
5 changed files
with
286 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** @file Stubbable core setup check behavior for the setup page. */ | ||
import CircuitPlaygroundBoard from '../CircuitPlaygroundBoard'; | ||
import {ensureAppInstalled, findPortWithViableDevice} from '../portScanning'; | ||
import {isChrome, gtChrome33} from './browserChecks'; | ||
|
||
export default class SetupChecker { | ||
port = null; | ||
boardController = null; | ||
|
||
/** | ||
* Resolve if using Chrome > 33 | ||
* @return {Promise} | ||
*/ | ||
detectChromeVersion() { | ||
return new Promise((resolve, reject) => { | ||
if (!isChrome()) { | ||
reject(new Error('Not using Chrome')); | ||
} if (!gtChrome33()) { | ||
reject(new Error('Not using Chrome > v33')); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Resolve if the Chrome Connector App is installed. | ||
* @return {Promise} | ||
*/ | ||
detectChromeAppInstalled() { | ||
return ensureAppInstalled(); | ||
} | ||
|
||
/** | ||
* @return {Promise} | ||
*/ | ||
detectBoardPluggedIn() { | ||
return findPortWithViableDevice() | ||
.then(port => this.port = port); | ||
} | ||
|
||
/** | ||
* @return {Promise} | ||
*/ | ||
detectCorrectFirmware() { | ||
this.boardController = new CircuitPlaygroundBoard(this.port); | ||
return this.boardController.connectToFirmware(); | ||
} | ||
|
||
/** | ||
* @return {Promise} | ||
*/ | ||
detectComponentsInitialize() { | ||
return new Promise(resolve => { | ||
this.boardController.initializeComponents(); | ||
resolve(); | ||
}); | ||
} | ||
|
||
/** | ||
* @return {Promise} | ||
*/ | ||
celebrate() { | ||
return this.boardController.celebrateSuccessfulConnection(); | ||
} | ||
|
||
teardown() { | ||
if (this.boardController) { | ||
this.boardController.destroy(); | ||
} | ||
this.boardController = null; | ||
this.port = null; | ||
} | ||
} |
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,18 @@ | ||
/** @file Some misc. browser check methods for maker */ | ||
|
||
export function gtChrome33() { | ||
return getChromeVersion() >= 33; | ||
} | ||
|
||
export function isChrome() { | ||
return !!window.chrome; | ||
} | ||
|
||
export function getChromeVersion() { | ||
const raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); | ||
return raw ? parseInt(raw[2], 10) : false; | ||
} | ||
|
||
export function isWindows() { | ||
return navigator.platform.indexOf('Win') > -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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import BoardSetupCheck from '@cdo/apps/lib/kits/maker/ui/BoardSetupCheck'; | ||
import SetupChecklist from '@cdo/apps/lib/kits/maker/ui/SetupChecklist'; | ||
import SetupChecker from '@cdo/apps/lib/kits/maker/util/SetupChecker'; | ||
|
||
$(function () { | ||
ReactDOM.render(<BoardSetupCheck/>, document.getElementById('setup-status-mount')); | ||
const setupChecker = new SetupChecker(); | ||
ReactDOM.render( | ||
<SetupChecklist setupChecker={setupChecker}/>, | ||
document.getElementById('setup-status-mount') | ||
); | ||
$('.maker-setup a').attr('target', '_blank'); | ||
}); |
Oops, something went wrong.