Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
326b34c
commit 037806f
Showing
7 changed files
with
732 additions
and
23 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,73 @@ | ||
import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest"; | ||
import CliAutoComplete from "../src/js/CliAutoComplete"; | ||
import { cli } from "../src/js/tabs/cli"; | ||
import $ from "jquery"; | ||
import CONFIGURATOR from "../src/js/data_storage"; | ||
|
||
class MockAnalytics { | ||
sendEvent() { | ||
// Empty | ||
} | ||
} | ||
|
||
MockAnalytics.prototype.EVENT_CATEGORIES = {}; | ||
|
||
function toArrayBuffer(string) { | ||
const bufferOut = new ArrayBuffer(string.length); | ||
const bufView = new Uint8Array(bufferOut); | ||
|
||
for (let i = 0; i < string.length; i++) { | ||
bufView[i] = string.charCodeAt(i); | ||
} | ||
|
||
return bufferOut; | ||
} | ||
|
||
describe("cli", () => { | ||
describe("output", () => { | ||
let cliTab; | ||
let cliOutput; | ||
let cliPrompt; | ||
let tracking; | ||
|
||
beforeAll(() => { | ||
cliTab = $("<div>").addClass("tab-cli"); | ||
cliOutput = $("<div>").addClass("wrapper"); | ||
cliPrompt = $('<textarea name="commands">'); | ||
|
||
cliTab.append($("<div>").addClass("window").append(cliOutput)); | ||
cliTab.append(cliPrompt); | ||
|
||
CliAutoComplete.setEnabled(false); // not testing the client-side autocomplete | ||
|
||
tracking = new MockAnalytics(); | ||
|
||
$("body").append(cliTab); | ||
|
||
CONFIGURATOR.cliValid = true; | ||
cli.GUI.windowWrapper = cliOutput; | ||
}); | ||
afterAll(() => { | ||
cliTab.remove(); | ||
}); | ||
beforeEach(() => { | ||
cliOutput.empty(); | ||
cliPrompt.val(""); | ||
cli.cliBuffer = ""; | ||
}); | ||
it("ambiguous auto-complete results", () => { | ||
cli.cliBuffer = "se"; | ||
cli.read({ | ||
data: toArrayBuffer('\r\x1B[Kserialpassthrough\tservo\r\n# ser'), | ||
}); | ||
// Ambigous auto-complete from firmware is preceded with an \r carriage return | ||
// which only renders a line break on Mac | ||
const expectedValue = GUI.operating_system !== "Windows" ? | ||
'se<br>serialpassthrough\tservo<br>' : | ||
'seserialpassthrough\tservo<br>'; | ||
expect(cliOutput.html()).to.equal(expectedValue); | ||
expect(cliPrompt.val()).to.equal('ser'); | ||
|
||
}); | ||
}); | ||
}); |
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,7 @@ | ||
import { JSDOM } from "jsdom"; | ||
import $ from "jquery"; | ||
|
||
// Note: this can go away once jquery is used as module everywhere | ||
const { window } = new JSDOM(""); | ||
$(window); | ||
globalThis.$ = $; |
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,12 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
// TODO: create test dir once karma is gone | ||
// TODO: eventually it's bettter to have tetss next to the code | ||
include: ['tests/**/*.test.{js,mjs,cjs}'], | ||
environment: 'jsdom', | ||
setupFiles: ['tests/setup.js'], | ||
}, | ||
}); |
Oops, something went wrong.