-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fuqiang15
committed
Jul 21, 2021
1 parent
bb0c566
commit 1e45ee7
Showing
13 changed files
with
4,139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ npm-debug.log | |
**/dist | ||
**/variables.* | ||
**/test/snapshots | ||
**/coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# `shared-utils` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { mapDatasource } from '../../src/basic/datasource' | ||
|
||
const treeData = [ | ||
{ | ||
value: 1 | ||
}, | ||
{ | ||
value: 2, | ||
children: [ | ||
{ | ||
value: 20, | ||
children: [ | ||
{ | ||
value: 201, | ||
}, | ||
{ | ||
value: 202, | ||
} | ||
] | ||
}, | ||
{ | ||
value: 21 | ||
} | ||
] | ||
}, | ||
{ | ||
value: 3 | ||
} | ||
] | ||
|
||
describe('utils/datasource', () => { | ||
it('should map datasource correctly', () => { | ||
expect(mapDatasource(treeData, item => ({ | ||
...item, | ||
value: `${item.value}a` | ||
}))).toEqual([ | ||
{ | ||
value: '1a' | ||
}, | ||
{ | ||
value: '2a', | ||
children: [ | ||
{ | ||
value: '20a', | ||
children: [ | ||
{ | ||
value: '201a', | ||
}, | ||
{ | ||
value: '202a', | ||
} | ||
] | ||
}, | ||
{ | ||
value: '21a' | ||
} | ||
] | ||
}, | ||
{ | ||
value: '3a' | ||
} | ||
]) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { toggleClass } from '../../src/basic/dom' | ||
|
||
describe('utils/dom', () => { | ||
it('should toggle classes correctly', () => { | ||
let el = document.createElement('div') | ||
el.className = 'a b c d ' | ||
document.body.appendChild(el) | ||
|
||
toggleClass(el, 'a') | ||
toggleClass(el, 'b', true) | ||
toggleClass(el, 'c') | ||
toggleClass(el, 'd') | ||
toggleClass(el, 'e') | ||
toggleClass(el, 'f', true) | ||
toggleClass(el, 'g', false) | ||
expect(el.classList.contains('a')).toBe(false) | ||
expect(el.classList.contains('b')).toBe(true) | ||
expect(el.classList.contains('c')).toBe(false) | ||
expect(el.classList.contains('d')).toBe(false) | ||
expect(el.classList.contains('e')).toBe(true) | ||
expect(el.classList.contains('f')).toBe(true) | ||
expect(el.classList.contains('g')).toBe(false) | ||
|
||
el.parentNode!.removeChild(el) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getCheckedSubTree } from '../src/tree' | ||
|
||
|
||
const treeData = [ | ||
{ | ||
value: 1 | ||
}, | ||
{ | ||
value: 2, | ||
children: [ | ||
{ | ||
value: 20, | ||
children: [ | ||
{ | ||
value: 201, | ||
}, | ||
{ | ||
value: 202, | ||
} | ||
] | ||
}, | ||
{ | ||
value: 21 | ||
} | ||
] | ||
}, | ||
{ | ||
value: 3 | ||
} | ||
] | ||
|
||
describe('tree', () => { | ||
it('getCheckedSubtree should extract checked subtree correctly', () => { | ||
expect(getCheckedSubTree(treeData, [1])).toEqual([treeData[0]]) | ||
expect(getCheckedSubTree(treeData, [201, 202])).toEqual([{ | ||
value: 2, | ||
children: [ | ||
treeData[1].children![0] | ||
] | ||
}]) | ||
expect(getCheckedSubTree(treeData, [201])).toEqual([{ | ||
value: 2, | ||
children: [ | ||
{ | ||
value: 20, | ||
children: [ | ||
{ | ||
value: 201, | ||
} | ||
] | ||
} | ||
] | ||
}]) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* For a detailed explanation regarding each configuration property and type check, visit: | ||
* https://jestjs.io/docs/configuration | ||
*/ | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
clearMocks: true, | ||
|
||
// Indicates whether the coverage information should be collected while executing the test | ||
collectCoverage: true, | ||
|
||
// The directory where Jest should output its coverage files | ||
coverageDirectory: "coverage", | ||
}; |
Oops, something went wrong.