Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @ice/store Unit Test #84

Merged
merged 42 commits into from
Apr 18, 2020
Merged

Add @ice/store Unit Test #84

merged 42 commits into from
Apr 18, 2020

Conversation

luhc228
Copy link
Member

@luhc228 luhc228 commented Apr 2, 2020

增加 @ice/store单元测试(基于 icestore 1.3.x 版本)

Utils

  • appendReducers
  • coverter
  • validate

Basic API

  • Provider
  • useModel
  • getModel
  • withModel
  • useModelDispatchers
  • withModelDispatchers
  • useModelEffectsState
  • withModelEffectsState
  • getModelState
  • getModelDispatchers

@luhc228 luhc228 changed the title Unit test Add @ice/store Unit Test Apr 2, 2020
@luhc228 luhc228 changed the title Add @ice/store Unit Test [WIP] Add @ice/store Unit Test Apr 2, 2020
@alvinhui
Copy link
Member

reviewed

@luhc228
Copy link
Member Author

luhc228 commented Apr 16, 2020

当前的单元测试报告如下图:
image

@luhc228
Copy link
Member Author

luhc228 commented Apr 16, 2020

我在这个PR中已经更新了 codecov.yml

comment:
  layout: "reach, diff, flags, files"
  behavior: default
  require_changes: false
  require_base: no
  require_head: yes
  branches:
    - "master"

不过这里面的PR还没有出来。应该是这个 .yml 文件没有更新到 master 分支上。具体如下面的链接
ref: https://codecov.io/gh/ice-lab/icestore/settings/yaml
image

@luhc228 luhc228 requested a review from alvinhui April 16, 2020 11:26
@alvinhui
Copy link
Member

alvinhui commented Apr 17, 2020

index.spec.ts 的测试挺全面。

这里提两个问题:

  • 「单元测试」是否应只关注单个功能点进行测试而不需要关注其内部的操作过程?
  • 单测的迭代过程是否应先编写基础函数的测试用例,再编写入口文件的测试用例?

举个例子。测试 effect state,当前的实现是编写了用例 "get model effects state"。

我们是否可以:

  • 编写 plugin-loading 的测试用例:关注 loading 的变更
  • 编写 plugin-error 的测试用例:关注 error 的变更
  • 编写 plugin-effectsStateApis 的测试用例:
    • 关注是否有 useModelEffectsState 这个 API ,
    • 其返回值是否正确 {error: Error, isLoading: Boolean}(其变更过程由 plugin-loading && plugin-error 以及 react-hooks 的单测保障)
  • 编写 index 的测试用例,关注返回值中是否有 useModelEffectsState 这个 API

可以对比一下这个思路和当前的做法间有哪些优缺点。

@alvinhui
Copy link
Member

第二轮 reviewed

@@ -29,15 +29,15 @@ const todos = {
},

effects: (dispatch) => ({
add({ todo, currentLength }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add(todo, rootState, { store }) {
this.addTodo(todo);
dispatch.user.setTodos(store.getModelState('todos').dataSource.length + 1);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意 rootState 是一个不可变数据,this.addTodo 后,rootState 不会发生变化。

index: 0,
currentLength: result.current.state.dataSource.length,
});
result.current.dispatchers.delete(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      result.current.dispatchers.delete(0, { store });

@alvinhui alvinhui changed the base branch from master to release/1.4.0 April 18, 2020 14:34
@alvinhui alvinhui merged commit 71bf945 into ice-lab:release/1.4.0 Apr 18, 2020
@alvinhui alvinhui mentioned this pull request Apr 24, 2020
alvinhui added a commit that referenced this pull request Apr 24, 2020
* chore: new version

* fix: add meta type in ModelEffects (#102)

* Add @ice/store Unit Test (#84)

* chore: add dependency

* test: add helper and init test

* test: add createStore test

* test: add withModel withModelActions withModelEffectsState test

* test: add throw error when getting unexist model

* chore: new version

* test: add global actions test

* test: add createModel test

* test: add createUseContainer test

* chore: createModel

* test: add createContainer test

* test: update test cases

* test: add useModel test

* test: add class component test

* test: update class component test

* test: add createStore options test

* test: add appendReducer test

* test: add appendReducer test

* chore: lint

* test: add utils test

* docs: add badge

* chore: remove unnecessary comment

* test: update converter test

* feat: add comment to pr

* fix: fix by the comments

* chore: update codecov config

* test: update test

* test: update converter test case

* test: update examples

* test: update todos example

* chore: update modelEffects type

Co-authored-by: alvinhui <alvin.hui@qq.com>

* fix: effects should return an object (#105)

* fix: effects should return an object

* chore: lint

* Better example (#106)

* chore: add classComponent example

* chore: rename async function

* chore: visibility logic

* docs: add examples section

* feat: withModel (#104)

* feat: withModel init

* refactor: model apis

* feat: model for withModel

* feat: ts support for withModel

* chore: typo

* chore: lint

* test: disable loading and error

* test: mock value

* chore: playload && meta is option

* chore: typo

* docs: withModel

* refactor: class and function component demo

* chore: class component support

* chore: remove console

* chore: lint

* chore: withModel example

* chore: remove product

* chore: undo

* chore: typo

* Docs: Migrating From Redux  (#108)

* chore: example @ice/store version

Co-authored-by: Hengchang Lu <44047106+luhc228@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants