| | |
| | | import test from "ava"; |
| | | import test, { ExecutionContext } from "ava"; |
| | | |
| | | import { Helpers } from "../src/Helpers"; |
| | | |
| | |
| | | }) |
| | | |
| | | |
| | | test("Helpers.createLocalStorageBasedApi() MC.isReady", async t => { |
| | | test("Helpers.createStorageBasedApi() MC.isReady", async t => { |
| | | const MC = Helpers.createStorageBasedApi(); |
| | | t.true(await MC.isReady()); |
| | | }) |
| | | |
| | | test("Helpers.createLocalStorageBasedApi() MC.ide.getContextFile", async t => { |
| | | test("Helpers.createStorageBasedApi() MC.ide.getContextFile", async t => { |
| | | const MC = Helpers.createStorageBasedApi(); |
| | | const contextFile = await MC.ide.getContextFile() |
| | | t.true(Helpers.isFile(contextFile)); |
| | |
| | | t.is(contextFile.path, "/file.dummy.json"); |
| | | }) |
| | | |
| | | test("Helpers.createLocalStorageBasedApi() MC.ide.getUserName", async t => { |
| | | test("Helpers.createStorageBasedApi() MC.ide.getUserName", async t => { |
| | | const MC = Helpers.createStorageBasedApi(); |
| | | t.is(await MC.ide.getUserName(), "jdoe"); |
| | | }) |
| | | |
| | | test("Helpers.createLocalStorageBasedApi() MC.ide.fs readFile+writeFile", async t => { |
| | | const MC = Helpers.createStorageBasedApi(); |
| | | async function expectThrows(t: ExecutionContext, callback: () => Promise<any>) { |
| | | try { |
| | | await callback(); |
| | | t.fail() |
| | | } catch (error) { |
| | | t.pass() |
| | | } |
| | | } |
| | | |
| | | test("Helpers.createStorageBasedApi() MC.ide.fs readFile+writeFile", async t => { |
| | | const MC = Helpers.createStorageBasedApi(); // expect InMemory Storage |
| | | const contextFile = await MC.ide.getContextFile(); |
| | | const exerciseFile = Helpers.contextFileToExerciseFile(contextFile); |
| | | |
| | |
| | | |
| | | t.is(await MC.ide.fs.readFile(contextFile), "123"); |
| | | t.is(await MC.ide.fs.readFile(exerciseFile), "456"); |
| | | |
| | | expectThrows(t, () => MC.ide.fs.writeFile({} as any, "")); |
| | | expectThrows(t, () => MC.ide.fs.writeFile(exerciseFile, 42 as any)); |
| | | expectThrows(t, () => MC.ide.fs.writeFile(null as any, null as any)); |
| | | }) |
| | | |
| | | |
| | | |
| | | test("Helpers.createLocalStorageBasedApi() MC.ide.navigator", async t => { |
| | | test("Helpers.createStorageBasedApi() MC.ide.navigator", async t => { |
| | | const MC = Helpers.createStorageBasedApi(); |
| | | const contextFile = await MC.ide.getContextFile(); |
| | | const exerciseFile = Helpers.contextFileToExerciseFile(contextFile); |
| | |
| | | MC.ide.navigator.navigateTo("www.google.de", true); |
| | | MC.ide.navigator.navigateToExercise(exerciseFile, true); |
| | | |
| | | expectThrows(t, () => MC.ide.navigator.navigateTo(null as any)); |
| | | expectThrows(t, () => MC.ide.navigator.navigateTo(42 as any)); |
| | | expectThrows(t, () => MC.ide.navigator.navigateTo("www.google.de", 42 as any)); |
| | | |
| | | t.pass(); |
| | | }) |