8000 test: add more tests · rubythonode/nativescript-vue@03c4d65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03c4d65

Browse files
committed
test: add more tests
1 parent f3ad06e commit 03c4d65

File tree

9 files changed

+221
-5
lines changed

9 files changed

+221
-5
lines changed

.babelrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"presets": ["env"]
2+
"presets": ["env"],
3+
"env": {
4+
"test": {
5+
"presets": ["env"],
6+
"plugins": ["transform-flow-strip-types"]
7+
}
8+
}
39
}

__tests__/element-registry.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as elReg from 'element-registry'
2+
3+
describe('element-registry', () => {
4+
test('works', () => {
5+
})
6+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import CommentNode from 'renderer/CommentNode'
2+
3+
jest.mock('renderer/utils', () => ({
4+
insertChild: jest.fn(),
5+
removeChild: jest.fn()
6+
}))
7+
8+
describe('CommentNode', () => {
9+
test('works', () => {
10+
})
11+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import DocumentNode from 'renderer/DocumentNode'
2+
3+
jest.mock('renderer/utils', () => ({
4+
insertChild: jest.fn(),
5+
removeChild: jest.fn()
6+
}))
7+
8+
describe('DocumentNode', () => {
9+
test('works', () => {
10+
})
11+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ElementNode from 'renderer/ElementNode'
2+
3+
jest.mock('renderer/utils', () => ({
4+
insertChild: jest.fn(),
5+
removeChild: jest.fn()
6+
}))
7+
8+
describe('ElementNode', () => {
9+
test('works', () => {
10+
})
11+
})

__tests__/renderer/TextNode.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import TextNode from 'renderer/TextNode'
2+
3+
jest.mock('renderer/utils', () => ({
4+
insertChild: jest.fn(),
5+
removeChild: jest.fn()
6+
}))
7+
8+
describe('TextNode', () => {
9+
test('works', () => {
10+
})
11+
})

__tests__/renderer/utils.test.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import * as utils from 'renderer/utils'
2+
3+
jest.mock('ui/core/view', () => {
4+
return {
5+
View() {
6+
}
7+
}
8+
}, {virtual: true})
9+
jest.mock('ui/content-view', () => {
10+
return {
11+
ContentView() {
12+
}
13+
}
14+
}, {virtual: true})
15+
jest.mock('ui/layouts/layout-base', () => {
16+
return {
17+
LayoutBase() {
18+
}
19+
}
20+
}, {virtual: true})
21+
22+
const getParentAndChild = (parentType) => {
23+
return {
24+
parentNode: {
25+
nativeView: parentType ? new parentType : {},
26+
meta: {}
27+
},
28+
childNode: {
29+
nativeView: {},
30+
meta: {}
31+
}
32+
}
33+
}
34+
35+
describe('utils', () => {
36+
test('isView', () => {
37+
const View = require('ui/core/view').View;
38+
39+
expect(utils.isView()).toEqual(false)
40+
expect(utils.isView('a')).toEqual(false)
41+
expect(utils.isView(1)).toEqual(false)
42+
expect(utils.isView(new View())).toEqual(true)
43+
})
44+
45+
test('isLayout', () => {
46+
const LayoutBase = require('ui/layouts/layout-base').LayoutBase;
47+
48+
expect(utils.isLayout()).toEqual(false)
49+
expect(utils.isLayout('a')).toEqual(false)
50+
expect(utils.isLayout(1)).toEqual(false)
51+
expect(utils.isLayout(new LayoutBase())).toEqual(true)
52+
})
53+
54+
test('isContentView', () => {
55+
const ContentView = require('ui/content-view').ContentView;
56+
57+
expect(utils.isContentView()).toEqual(false)
58+
expect(utils.isContentView('a')).toEqual(false)
59+
expect(utils.isContentView(1)).toEqual(false)
60+
expect(utils.isContentView(new ContentView())).toEqual(true)
61+
})
62+
63+
test('insertChild returns early if there is no parent or child should not be added to dom', () => {
64+
expect(utils.insertChild()).toBeFalsy();
65+
expect(utils.insertChild(true, {meta: {skipAddToDom: true}})).toBeFalsy();
66+
})
67+
68+
test('insertChild skips adding childNode to unknown parent', () => {
69+
const {parentNode, childNode} = getParentAndChild();
70+
71+
expect(utils.insertChild(parentNode, childNode)).toBeFalsy()
72+
})
73+
74+
75+
test('insertChild adds childNode to Layout parent', () => {
76+
const LayoutBase = require('ui/layouts/layout-base').LayoutBase;
77+
const {parentNode, childNode} = getParentAndChild(LayoutBase);
78+
parentNode.nativeView.addChild = jest.fn();
79+
childNode.nativeView.parent = null;
80+
81+
utils.insertChild(parentNode, childNode);
82+
expect(parentNode.nativeView.addChild.mock.calls.length).toBe(1)
83+
})
84+
85+
86+
test('insertChild adds childNode at index to Layout parent', () => {
87+
const LayoutBase = require('ui/layouts/layout-base').LayoutBase;
88+
const {parentNode, childNode} = getParentAndChild(LayoutBase);
89+
parentNode.nativeView.insertChild = jest.fn();
90+
childNode.nativeView.parent = null;
91+
92+
utils.insertChild(parentNode, childNode, 1);
93+
expect(parentNode.nativeView.insertChild.mock.calls.length).toBe(1)
94+
})
95+
96+
test('insertChild removes childNode if the parent is the same Layout parent', () => {
97+
const LayoutBase = require('ui/layouts/layout-base').LayoutBase;
98+
const {parentNode, childNode} = getParentAndChild(LayoutBase);
99+
parentNode.nativeView.getChildIndex = jest.fn().mockReturnValueOnce(1).mockReturnValueOnce(-1);
100+
parentNode.nativeView.removeChild = jest.fn();
101+
parentNode.nativeView.insertChild = jest.fn();
102+
parentNode.nativeView.addChild = jest.fn();
103+
childNode.nativeView.parent = parentNode.nativeView;
104+
105+
utils.insertChild(parentNode, childNode);
106+
expect(parentNode.nativeView.getChildIndex.mock.calls.length).toBe(1)
107+
expect(parentNode.nativeView.removeChild.mock.calls.length).toBe(1)
108+
109+
//
110+
utils.insertChild(parentNode, childNode);
111+
expect(parentNode.nativeView.getChildIndex.mock.calls.length).toBe(2)
112+
})
113+
114+
test('insertChild adds comment node to ContentView parent', () => {
115+
const ContentView = require('ui/content-view').ContentView;
116+
const {parentNode, childNode} = getParentAndChild(ContentView);
117+
childNode.nodeType = 8;
118+
parentNode.nativeView._addView = jest.fn();
119+
120+
utils.insertChild(parentNode, childNode);
121+
expect(parentNode.nativeView._addView.mock.calls.length).toBe(1);
122+
})
123+
124+
test('insertChild sets content of ContentView parent', () => {
125+
const ContentView = require('ui/content-view').ContentView;
126+
const {parentNode, childNode} = getParentAndChild(ContentView);
127+
128+
utils.insertChild(parentNode, childNode);
129+
expect(parentNode.nativeView.content).toEqual(childNode.nativeView);
130+
})
131+
132+
test('insertChild adds child from builder to unknown parent', () => {
133+
const {parentNode, childNode} = getParentAndChild();
134+
parentNode.nativeView._addChildFromBuilder = jest.fn();
135+
childNode._nativeView = {
136+
constructor: {name: 'test'}
137+
};
138+
139+
utils.insertChild(parentNode, childNode);
140+
expect(parentNode.nativeView._addChildFromBuilder.mock.calls.length).toBe(1);
141+
expect(parentNode.nativeView._addChildFromBuilder.mock.calls[0][0]).toEqual('test')
142+
})
143+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {decode} from 'util/entity-decoder'
2+
3+
describe('entity-decoder', () => {
4+
test('works', () => {
5+
})
6+
})

package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"nativescript",
2525
"integration"
2626
],
27-
"author": "rigor789",
27+
"author": "Igor Randjelovic",
2828
"license": "MIT",
2929
"bugs": {
3030
"url": "https://github.com/rigor789/nativescript-vue/issues"
@@ -47,14 +47,15 @@
4747
"@commitlint/cli": "^5.2.6",
4848
"@commitlint/config-conventional": "^5.2.3",
4949
"babel-jest": "^19.0.0",
50+
"babel-plugin-transform-flow-strip-types": "^6.22.0",
5051
"babel-preset-env": "^1.6.1",
5152
"chalk": "^2.3.0",
5253
"commitizen": "^2.9.6",
5354
"conventional-changelog": "^1.1.7",
5455
"cz-conventional-changelog": "^2.1.0",
5556
"husky": "^0.15.0-beta.16",
5657
"inquirer": "^3.3.0",
57-
"jest": "^19.0.2",
58+
"jest": "^22.0.4",
5859
"jest-junit": "^1.5.1",
5960
"lint-staged": "^6.0.0",
6061
"prettier": "^1.8.2",
@@ -77,8 +78,18 @@
7778
"modulePaths": [
7879
"<rootDir>/platform/nativescript"
7980
],
80-
"collectCoverage": true,
81-
"testResultsProcessor": "./node_modules/jest-junit"
81+
"collectCoverageFrom": [
82+
"**/*.js",
83+
"!**/node_modules/**"
84+
],
85+
"moduleDirectories": [
86+
"node_modules",
87+
"<rootDir>/node_modules/tns-core-modules"
88+
],
89+
"modulePathIgnorePatterns": [
90+
"<rootDir>/samples"
91+
],
92+
"collectCoverage": true
8293
},
8394
"prettier": {
8495
"semi": false,

0 commit comments

Comments
 (0)
0