web-atoms-mvvm-todo
v1.0.3
Published
Web Atoms MVVM Todo Sample
Downloads
3
Readme
Installation
npm install web-atoms-generator typescript -g
Web Atoms MVVM Sample
Sample Todo Application using Web Atoms MVVM contains following features.
- REST Service and Mock
- Small and Minimal Dependency Injection
- View Model and Reusable Components
- Unit Tests
Components
Components are organized in app/views
folder. Component generator uses
waconfig.json
to convert HTML components into views.js
, it also contains
views.js.d.ts
so you can statically reference them in your typescript files.
TaskStatusCombo
dropdown is reusable dropdown that loads values fromConfigService
TaskListView
is a main view that hosts list of tasks and button to add/remove tasks.NewTaskWindow
is window components that will allow you to validate/edit and save task.
Services
REST Services are kept in app/services
folder. They are decorated with HTTP methods and
parameter bindings.
TaskService
provides CRUD operations on tasks.ConfigSerice
provides configuration lists such as status list etc.
Models
In this folder, Task
and ConfigItem
models are stored, Task is a class where else ConfigItem is
just a type.
View Models
Components have corresponding View Model in app/view-models
folder. Not every component needs ViewModel.
TaskListViewModel
TaskListViewModel
provides list of tasks, which are loaded asynchronously fromTaskService
ininit
method.- It provides
add/remove
method for task. - In
add
method it opens new task window and awaits for result asynchronously.
NewTaskWindowViewModel
NewTaskWindowViewModel
provides task model and validation for the model.- Validations are added as inline lambda expressions. Validation expression is evaluated automatically when any referenced property is modified.
- When you call
this.close(task)
method, parametertask
is resolved in promise that was created when the task list opened a window.
Unit Tests
We have created two unit tests.
Test for Task List View Model
- We will call
expectWindow
onMockWindowService.instance
to register what window should open when we call a method. We will also provide result that we will expect to resolve in promise. - We will verify that second task in the list is the new task we were expecting from the window.
NewTaskWindow Test
- We will call
expectAlert
to notify test manager that we will expect an alert when we will try to save empty task. - We will call
expectAlert
again after setting label. - In end of test we will call
MockWindowService.instance.assert()
, that will throw an error if any of expected alert/window was never called from the target methods.