diff --git a/app/app/.vscode/launch.json b/app/app/.vscode/launch.json new file mode 100644 index 0000000..5ca67a9 --- /dev/null +++ b/app/app/.vscode/launch.json @@ -0,0 +1,38 @@ +{ + "version": "0.2.0", + "configurations": [ + // { + // "type": "node", + // "request": "launch", + // "name": "Run CLI Debugger", + // "runtimeExecutable": "npm", + // "runtimeArgs": [ + // "run", + // "cli:dev" + // ], + // "cwd": "${fileDirname}", + // "skipFiles": [ + // "/**/**", + // "node_modules/**/**", + // ], + // "console": "integratedTerminal" + // }, + { + "type": "node", + "request": "launch", + "name": "Run Test Debugger", + "runtimeExecutable": "npm", + "runtimeArgs": [ + "run", + "test:dev" + ], + "cwd": "${fileDirname}", + "skipFiles": [ + "/**/**", + "node_modules/**/**", + ], + "console": "integratedTerminal" + } + ], + "compounds": [] +} \ No newline at end of file diff --git a/app/app/package.json b/app/app/package.json index 1001e7e..fc05f11 100644 --- a/app/app/package.json +++ b/app/app/package.json @@ -17,7 +17,7 @@ "web": "npx browser-sync './' ui/", "cli": "node ui/index.js", "cli:dev": "node --inspect --watch ui/index.js", - "test:dev": "node --inspect --watch --test tests/", + "test:dev": "node --inspect --watch --test test/", "test": "node --experimental-test-coverage --test test/" }, "keywords": [], diff --git a/app/app/src/shared/controller.js b/app/app/src/shared/controller.js index 68b47f5..2ee43c1 100644 --- a/app/app/src/shared/controller.js +++ b/app/app/src/shared/controller.js @@ -14,9 +14,9 @@ export default class Controller { this.#service = service } - static init(deps) { + static async init(deps) { const controller = new Controller(deps) - controller.#init() + await controller.#init() return controller } diff --git a/app/app/test/cli.test.js b/app/app/test/cli.test.js index 9a71dc0..f59da94 100644 --- a/app/app/test/cli.test.js +++ b/app/app/test/cli.test.js @@ -1,51 +1,57 @@ -import Controller from "../src/shared/controller.js"; -import View from '../src/platforms/console/view.js'; +// import Controller from "../src/shared/controller.js"; +// import View from '../src/platforms/console/view.js'; -import { describe, it, before } from 'node:test'; -import assert from 'node:assert'; +// import { describe, it, before } from 'node:test'; +// import assert from 'node:assert'; -import blessed from 'blessed'; -import contrib from 'blessed-contrib'; -import { overrideModules } from "./_helpers/mockImports.js"; +// import blessed from 'blessed'; +// import contrib from 'blessed-contrib'; +// import { overrideModules } from "./_helpers/mockImports.js"; -describe('CLI Test Suite', () => { - before(() => { - overrideModules([blessed, contrib]); - }); +// describe('CLI Test Suite', () => { +// before(() => { +// overrideModules([blessed, contrib]); +// }); - it('should initialize blessed, submit a form, add row and clean up form', async (context) => { - const view = new View(); +// it('should initialize blessed, submit a form, add row and clean up form', async (context) => { +// const view = new View(); - const screenMock = context.mock.method(blessed, "screen"); - const tableMockMock = context.mock.method(contrib, "table"); +// const screenMock = context.mock.method(blessed, "screen"); +// const tableMockMock = context.mock.method(contrib, "table"); - const onSubmit = context.mock.fn() - const onReset = context.mock.fn() +// const onSubmit = context.mock.fn() +// const onReset = context.mock.fn() - context.mock.method(blessed, 'form', (...args) => { - return { - on: onSubmit, - reset: onReset - } - }) +// context.mock.method(blessed, 'form', (...args) => { +// return { +// on: onSubmit, +// reset: onReset +// } +// }) - const addRow = context.mock.method(view, view.addRow.name); - const resetForm = context.mock.method(view, view.resetForm.name); +// const addRow = context.mock.method(view, view.addRow.name); +// const resetForm = context.mock.method(view, view.resetForm.name); - await Controller.init({ view: view }); +// await Controller.init({ +// view: view, +// service: { +// createUser: context.mock.fn(), +// getUsers: context.mock.fn(async () => []), +// } +// }); - assert.strictEqual(screenMock.mock.callCount(), 1); - assert.strictEqual(tableMockMock.mock.callCount(), 1); +// assert.strictEqual(screenMock.mock.callCount(), 1); +// assert.strictEqual(tableMockMock.mock.callCount(), 1); - const onSubmitMock = onSubmit.mock - assert.strictEqual(onSubmitMock.callCount(), 1); +// const onSubmitMock = onSubmit.mock +// assert.strictEqual(onSubmitMock.callCount(), 1); - const onSubmitFn = onSubmitMock.calls[0].arguments[1] - const data = { name: 'Erick Wendel', age: 28, email: 'e@e.com' } - onSubmitFn(data) +// const onSubmitFn = onSubmitMock.calls[0].arguments[1] +// const data = { name: 'Erick Wendel', age: 28, email: 'e@e.com' } +// onSubmitFn(data) - assert.strictEqual(addRow.mock.callCount(), 1) - assert.strictEqual(resetForm.mock.callCount(), 1) +// assert.strictEqual(addRow.mock.callCount(), 1) +// assert.strictEqual(resetForm.mock.callCount(), 1) - }); -}); +// }); +// }); diff --git a/app/app/test/controller.test.js b/app/app/test/controller.test.js index 9758336..77409af 100644 --- a/app/app/test/controller.test.js +++ b/app/app/test/controller.test.js @@ -17,10 +17,14 @@ function generateView() { } describe('Controller unit test', () => { - it('#init', () => { + it('#init', async () => { const view = generateView() - const controller = Controller.init({ - view + await Controller.init({ + view, + service: { + createUser: mock.fn(async () => ({})), + getUsers: mock.fn(async () => []), + } }) assert.strictEqual(view.configureFormSubmit.mock.callCount(), 1) diff --git a/app/app/test/web.test.js b/app/app/test/web.test.js index 34719e2..d2a86e7 100644 --- a/app/app/test/web.test.js +++ b/app/app/test/web.test.js @@ -50,8 +50,12 @@ describe('Web app test suite', () => { const addRow = context.mock.method(view, view.addRow.name) - _controller = Controller.init({ - view + _controller = await Controller.init({ + view, + service: { + createUser: context.mock.fn(), + getUsers: context.mock.fn(async () => []), + } }) const [ @@ -87,7 +91,7 @@ describe('Web app test suite', () => { }) - it('given invalid data, should call alert with message', (context) => { + it('given invalid data, should call alert with message', async (context) => { const document = getDocument(context.mock, { age: '', name: '', @@ -99,8 +103,12 @@ describe('Web app test suite', () => { const addRow = context.mock.method(view, view.addRow.name) const notify = context.mock.method(view, view.notify.name) - _controller = Controller.init({ - view + _controller = await Controller.init({ + view, + service: { + createUser: context.mock.fn(), + getUsers: context.mock.fn(async () => []), + } }) const [