@pie-lib/text-select 1.12.8 → 1.13.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -70
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +8 -6
- package/src/__tests__/__snapshots__/text-select.test.jsx.snap +21 -0
- package/src/__tests__/text-select.test.jsx +34 -0
- package/src/__tests__/utils.test.jsx +27 -0
- package/src/index.js +2 -1
- package/src/token-select/__tests__/__snapshots__/index.test.jsx.snap +49 -0
- package/src/token-select/__tests__/__snapshots__/token.test.jsx.snap +31 -0
- package/src/token-select/__tests__/index.test.jsx +257 -0
- package/src/token-select/__tests__/token.test.jsx +33 -0
- package/src/token-select/index.jsx +3 -1
- package/src/token-select/token.jsx +11 -20
- package/src/tokenizer/__tests__/__snapshots__/controls.test.jsx.snap +59 -0
- package/src/tokenizer/__tests__/__snapshots__/index.test.jsx.snap +31 -0
- package/src/tokenizer/__tests__/__snapshots__/token-text.test.jsx.snap +17 -0
- package/src/tokenizer/__tests__/builder.test.js +256 -0
- package/src/tokenizer/__tests__/controls.test.jsx +25 -0
- package/src/tokenizer/__tests__/index.test.jsx +140 -0
- package/src/tokenizer/__tests__/selection-utils.test.js +26 -0
- package/src/tokenizer/__tests__/token-text.test.jsx +136 -0
- package/src/tokenizer/controls.jsx +20 -1
- package/src/tokenizer/token-text.jsx +9 -0
- package/README.md +0 -3
- package/lib/index.js +0 -68
- package/lib/index.js.map +0 -1
- package/lib/legend.js +0 -99
- package/lib/legend.js.map +0 -1
- package/lib/text-select.js +0 -138
- package/lib/text-select.js.map +0 -1
- package/lib/token-select/index.js +0 -249
- package/lib/token-select/index.js.map +0 -1
- package/lib/token-select/token.js +0 -237
- package/lib/token-select/token.js.map +0 -1
- package/lib/tokenizer/builder.js +0 -311
- package/lib/tokenizer/builder.js.map +0 -1
- package/lib/tokenizer/controls.js +0 -123
- package/lib/tokenizer/controls.js.map +0 -1
- package/lib/tokenizer/index.js +0 -205
- package/lib/tokenizer/index.js.map +0 -1
- package/lib/tokenizer/selection-utils.js +0 -65
- package/lib/tokenizer/selection-utils.js.map +0 -1
- package/lib/tokenizer/token-text.js +0 -200
- package/lib/tokenizer/token-text.js.map +0 -1
- package/lib/utils.js +0 -67
- package/lib/utils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [1.
|
|
6
|
+
## [1.13.1-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.7...@pie-lib/text-select@1.13.1-beta.0) (2025-07-20)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# [1.13.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.7...@pie-lib/text-select@1.13.0-beta.0) (2025-07-20)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
17
17
|
|
|
@@ -19,142 +19,90 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
# [1.14.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.7...@pie-lib/text-select@1.14.0-beta.0) (2025-07-15)
|
|
23
23
|
|
|
24
24
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
25
25
|
|
|
26
|
+
# [1.13.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.7...@pie-lib/text-select@1.13.0-beta.0) (2025-07-15)
|
|
26
27
|
|
|
28
|
+
**Note:** Version bump only for package @pie-lib/text-select
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [1.12.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.4...@pie-lib/text-select@1.12.5) (2023-09-27)
|
|
30
|
+
## [1.12.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.6...@pie-lib/text-select@1.12.7) (2023-10-03)
|
|
31
31
|
|
|
32
32
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
33
33
|
|
|
34
|
+
## [1.12.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.5...@pie-lib/text-select@1.12.6) (2023-10-01)
|
|
34
35
|
|
|
36
|
+
**Note:** Version bump only for package @pie-lib/text-select
|
|
35
37
|
|
|
38
|
+
## [1.12.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.4...@pie-lib/text-select@1.12.5) (2023-09-27)
|
|
36
39
|
|
|
40
|
+
**Note:** Version bump only for package @pie-lib/text-select
|
|
37
41
|
|
|
38
42
|
## [1.12.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.3...@pie-lib/text-select@1.12.4) (2023-09-27)
|
|
39
43
|
|
|
40
44
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
46
|
## [1.12.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.2...@pie-lib/text-select@1.12.3) (2023-09-25)
|
|
47
47
|
|
|
48
48
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
50
|
## [1.12.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.1...@pie-lib/text-select@1.12.2) (2023-09-20)
|
|
55
51
|
|
|
56
52
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
57
53
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
54
|
## [1.12.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.12.0...@pie-lib/text-select@1.12.1) (2023-09-20)
|
|
63
55
|
|
|
64
56
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
58
|
# [1.12.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.11.3...@pie-lib/text-select@1.12.0) (2023-09-18)
|
|
71
59
|
|
|
72
|
-
|
|
73
60
|
### Features
|
|
74
61
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
- **translator, text-select:** add translations for new text-select legend PD-3162 ([20ee2c1](https://github.com/pie-framework/pie-lib/commit/20ee2c17873985fa06b4b58cf781742a5923b532))
|
|
80
63
|
|
|
81
64
|
## [1.11.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.11.2...@pie-lib/text-select@1.11.3) (2023-09-14)
|
|
82
65
|
|
|
83
66
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
84
67
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
68
|
## [1.11.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.11.1...@pie-lib/text-select@1.11.2) (2023-08-29)
|
|
90
69
|
|
|
91
|
-
|
|
92
70
|
### Bug Fixes
|
|
93
71
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
- **text-select:** PD-3117 - avoids tokens overlapping in eval mode ([728c242](https://github.com/pie-framework/pie-lib/commit/728c24274c726907de568600b074305a145320ca))
|
|
73
|
+
- **text-select:** PD-3134 replace typography with span to prevent materialui from overwriting styling ([a9c4860](https://github.com/pie-framework/pie-lib/commit/a9c4860701355e3e6b33145414658da06ba5a5a3))
|
|
100
74
|
|
|
101
75
|
## [1.11.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.11.0...@pie-lib/text-select@1.11.1) (2023-08-21)
|
|
102
76
|
|
|
103
77
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
104
78
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
79
|
# [1.11.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.10.0...@pie-lib/text-select@1.11.0) (2023-08-16)
|
|
110
80
|
|
|
111
|
-
|
|
112
81
|
### Features
|
|
113
82
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
83
|
+
- **text-select:** PD-1163 - add legend for icons used in eval mode ([7b2bac2](https://github.com/pie-framework/pie-lib/commit/7b2bac262d29986db2ce57ff6cee6c04af08472a))
|
|
119
84
|
|
|
120
85
|
# [1.10.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.9.29...@pie-lib/text-select@1.10.0) (2023-08-15)
|
|
121
86
|
|
|
122
|
-
|
|
123
87
|
### Features
|
|
124
88
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
89
|
+
- **text-select:** adjust colors and alignment of the color ([a51ba55](https://github.com/pie-framework/pie-lib/commit/a51ba5547f6e1559915d6ea967d406923831b561))
|
|
90
|
+
- **text-select:** PD-1163 create wrapper component ([b41db39](https://github.com/pie-framework/pie-lib/commit/b41db39ade332d19dca70a06d54acf51b5888c69))
|
|
91
|
+
- **text-select:** PD-1163 update snapshots ([6b8edf8](https://github.com/pie-framework/pie-lib/commit/6b8edf83b763abdd93eee2655be3600cef90586b))
|
|
92
|
+
- **text-select:** PD-1163 updates to tokens in text select ([2535c91](https://github.com/pie-framework/pie-lib/commit/2535c911f378f4cf41c8471bfa1898b996ffacee))
|
|
133
93
|
|
|
134
94
|
## [1.9.29](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.9.28...@pie-lib/text-select@1.9.29) (2023-07-24)
|
|
135
95
|
|
|
136
96
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
137
97
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
98
|
## [1.9.28](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.9.27...@pie-lib/text-select@1.9.28) (2023-06-24)
|
|
143
99
|
|
|
144
100
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
145
101
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
102
|
## [1.9.27](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.9.26...@pie-lib/text-select@1.9.27) (2023-06-13)
|
|
151
103
|
|
|
152
104
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
153
105
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
106
|
## [1.9.26](https://github.com/pie-framework/pie-lib/compare/@pie-lib/text-select@1.9.25...@pie-lib/text-select@1.9.26) (2023-06-12)
|
|
159
107
|
|
|
160
108
|
**Note:** Version bump only for package @pie-lib/text-select
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.13.1-beta.0",
|
|
7
7
|
"description": "Some react components for text selection",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@material-ui/icons": "^3.0.2",
|
|
20
21
|
"@pie-framework/parse-english": "^1.0.0",
|
|
21
|
-
"@pie-lib/render-ui": "^4.
|
|
22
|
-
"@pie-lib/style-utils": "^0.1.
|
|
23
|
-
"@pie-lib/translator": "^2.
|
|
22
|
+
"@pie-lib/render-ui": "^4.16.1-beta.0",
|
|
23
|
+
"@pie-lib/style-utils": "^0.2.1-beta.0",
|
|
24
|
+
"@pie-lib/translator": "^2.4.1-beta.0",
|
|
24
25
|
"classnames": "^2.2.6",
|
|
25
26
|
"debug": "^4.1.1",
|
|
26
27
|
"invariant": "^2.2.4",
|
|
@@ -30,7 +31,8 @@
|
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@material-ui/core": "^3.8.3",
|
|
33
|
-
"@pie-
|
|
34
|
+
"@pie-framework/parse-english": "^1.0.0",
|
|
35
|
+
"@pie-lib/test-utils": "^0.3.1-beta.0",
|
|
34
36
|
"natural": "^0.6.3",
|
|
35
37
|
"react": "^16.8.1",
|
|
36
38
|
"react-dom": "^16.9.0"
|
|
@@ -39,6 +41,6 @@
|
|
|
39
41
|
"@material-ui/core": "^3.8.3",
|
|
40
42
|
"react": "^16.8.1"
|
|
41
43
|
},
|
|
42
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453",
|
|
43
45
|
"scripts": {}
|
|
44
46
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`text-select snapshot renders 1`] = `
|
|
4
|
+
<WithStyles(TokenSelect)
|
|
5
|
+
maxNoOfSelections={4}
|
|
6
|
+
onChange={[Function]}
|
|
7
|
+
tokens={
|
|
8
|
+
Array [
|
|
9
|
+
Object {
|
|
10
|
+
"correct": undefined,
|
|
11
|
+
"end": 3,
|
|
12
|
+
"isMissing": undefined,
|
|
13
|
+
"selectable": undefined,
|
|
14
|
+
"selected": false,
|
|
15
|
+
"start": 0,
|
|
16
|
+
"text": "foo",
|
|
17
|
+
},
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
/>
|
|
21
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import TextSelect from '../text-select';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import toJson from 'enzyme-to-json';
|
|
5
|
+
describe('text-select', () => {
|
|
6
|
+
describe('snapshot', () => {
|
|
7
|
+
it('renders', () => {
|
|
8
|
+
const w = shallow(
|
|
9
|
+
<TextSelect text="foo" tokens={[]} selectedTokens={[]} onChange={jest.fn()} maxNoOfSelections={4} />,
|
|
10
|
+
);
|
|
11
|
+
expect(w).toMatchSnapshot();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('logic', () => {
|
|
16
|
+
let w, onChange;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
onChange = jest.fn();
|
|
19
|
+
w = shallow(<TextSelect text="foo" tokens={[]} selectedTokens={[]} onChange={onChange} />);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('change', () => {
|
|
23
|
+
it('calls onChange', () => {
|
|
24
|
+
const changeArgs = [
|
|
25
|
+
{ start: 0, end: 1, selected: true },
|
|
26
|
+
{ start: 1, end: 2 },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
w.instance().change(changeArgs);
|
|
30
|
+
expect(onChange).toBeCalledWith([{ start: 0, end: 1 }]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { prepareText } from '../utils';
|
|
2
|
+
|
|
3
|
+
describe('logic', () => {
|
|
4
|
+
it('returns text if no html elements', () => {
|
|
5
|
+
const formattedText = prepareText(`foo bar`);
|
|
6
|
+
|
|
7
|
+
expect(formattedText).toEqual('foo bar');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('replaces br with new lines', () => {
|
|
11
|
+
const formattedText = prepareText(`<p>foo<br>bar</p>`);
|
|
12
|
+
|
|
13
|
+
expect(formattedText).toEqual('foo\nbar');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('replaces p with 2 new lines', () => {
|
|
17
|
+
const formattedText = prepareText(`<p>foo<br>bar</p><p>bar<br>foo</p>`);
|
|
18
|
+
|
|
19
|
+
expect(formattedText).toEqual('foo\nbar\n\nbar\nfoo');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('adds p if there are no paragraphs', () => {
|
|
23
|
+
const formattedText = prepareText(`foo<br>bar<br>foo`);
|
|
24
|
+
|
|
25
|
+
expect(formattedText).toEqual('foo\nbar\nfoo');
|
|
26
|
+
});
|
|
27
|
+
});
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Controls from './tokenizer/controls';
|
|
1
2
|
import Tokenizer from './tokenizer';
|
|
2
3
|
import TokenSelect, { TokenTypes } from './token-select';
|
|
3
4
|
import TextSelect from './text-select';
|
|
@@ -5,4 +6,4 @@ import { Legend } from './legend';
|
|
|
5
6
|
import Token from './token-select/token';
|
|
6
7
|
import { prepareText } from './utils';
|
|
7
8
|
|
|
8
|
-
export { TextSelect, TokenTypes, Tokenizer, TokenSelect, Token, prepareText, Legend };
|
|
9
|
+
export { Controls, TextSelect, TokenTypes, Tokenizer, TokenSelect, Token, prepareText, Legend };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`token-select snapshot renders 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className=""
|
|
6
|
+
dangerouslySetInnerHTML={
|
|
7
|
+
Object {
|
|
8
|
+
"__html": "<p><span class=\\"tokenRootClass Token-token-1 Token-selectable-5\\" data-indexkey=\\"0\\" data-reactroot=\\"\\">foo bar</span></p>",
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
onClick={[Function]}
|
|
12
|
+
/>
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
exports[`token-select snapshot renders in view mode with selected tokens 1`] = `
|
|
16
|
+
<div
|
|
17
|
+
className=""
|
|
18
|
+
dangerouslySetInnerHTML={
|
|
19
|
+
Object {
|
|
20
|
+
"__html": "<p><span class=\\"Token-token-1 Token-selected-6 Token-disabledBlack-3\\" data-indexkey=\\"0\\" data-reactroot=\\"\\">foo,</span><br><span class=\\"Token-token-1 Token-selected-6 Token-disabledBlack-3\\" data-indexkey=\\"2\\" data-reactroot=\\"\\">bar</span></p>",
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
onClick={[Function]}
|
|
24
|
+
/>
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
exports[`token-select snapshot renders paragraphs properly 1`] = `
|
|
28
|
+
<div
|
|
29
|
+
className=""
|
|
30
|
+
dangerouslySetInnerHTML={
|
|
31
|
+
Object {
|
|
32
|
+
"__html": "<p><span class=\\"tokenRootClass Token-token-1 Token-selectable-5\\" data-indexkey=\\"0\\" data-reactroot=\\"\\">foo,</span></p><p><span class=\\"tokenRootClass Token-token-1 Token-selectable-5\\" data-indexkey=\\"2\\" data-reactroot=\\"\\">bar</span></p>",
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
onClick={[Function]}
|
|
36
|
+
/>
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
exports[`token-select snapshot renders sentences properly 1`] = `
|
|
40
|
+
<div
|
|
41
|
+
className=""
|
|
42
|
+
dangerouslySetInnerHTML={
|
|
43
|
+
Object {
|
|
44
|
+
"__html": "<p><span class=\\"tokenRootClass Token-token-1 Token-selectable-5\\" data-indexkey=\\"0\\" data-reactroot=\\"\\">foo,</span><br><span class=\\"tokenRootClass Token-token-1 Token-selectable-5\\" data-indexkey=\\"2\\" data-reactroot=\\"\\">bar</span></p>",
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
onClick={[Function]}
|
|
48
|
+
/>
|
|
49
|
+
`;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`token snapshot renders 1`] = `
|
|
4
|
+
<Wrapper
|
|
5
|
+
useWrapper={false}
|
|
6
|
+
>
|
|
7
|
+
<span
|
|
8
|
+
className="tokenRootClass token"
|
|
9
|
+
dangerouslySetInnerHTML={
|
|
10
|
+
Object {
|
|
11
|
+
"__html": "foo bar",
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/>
|
|
15
|
+
</Wrapper>
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
exports[`token snapshot renders with brs 1`] = `
|
|
19
|
+
<Wrapper
|
|
20
|
+
useWrapper={false}
|
|
21
|
+
>
|
|
22
|
+
<span
|
|
23
|
+
className="tokenRootClass token"
|
|
24
|
+
dangerouslySetInnerHTML={
|
|
25
|
+
Object {
|
|
26
|
+
"__html": "foo <br>bar",
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/>
|
|
30
|
+
</Wrapper>
|
|
31
|
+
`;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { TokenSelect } from '../index';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { shallow } from 'enzyme';
|
|
4
|
+
|
|
5
|
+
describe('token-select', () => {
|
|
6
|
+
describe('snapshot', () => {
|
|
7
|
+
it('renders', () => {
|
|
8
|
+
const w = shallow(
|
|
9
|
+
<TokenSelect
|
|
10
|
+
tokens={[
|
|
11
|
+
{
|
|
12
|
+
text: 'foo bar',
|
|
13
|
+
start: 0,
|
|
14
|
+
end: 7,
|
|
15
|
+
predefined: true,
|
|
16
|
+
selectable: true,
|
|
17
|
+
selected: false,
|
|
18
|
+
},
|
|
19
|
+
]}
|
|
20
|
+
classes={{}}
|
|
21
|
+
onChange={jest.fn()}
|
|
22
|
+
/>,
|
|
23
|
+
);
|
|
24
|
+
expect(w).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders sentences properly', () => {
|
|
28
|
+
const w = shallow(
|
|
29
|
+
<TokenSelect
|
|
30
|
+
tokens={[
|
|
31
|
+
{
|
|
32
|
+
text: 'foo,',
|
|
33
|
+
start: 0,
|
|
34
|
+
end: 4,
|
|
35
|
+
predefined: true,
|
|
36
|
+
selectable: true,
|
|
37
|
+
selected: false,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
text: '\n',
|
|
41
|
+
start: 4,
|
|
42
|
+
end: 5,
|
|
43
|
+
selected: false,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
text: 'bar',
|
|
47
|
+
start: 5,
|
|
48
|
+
end: 8,
|
|
49
|
+
predefined: true,
|
|
50
|
+
selectable: true,
|
|
51
|
+
selected: false,
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
classes={{}}
|
|
55
|
+
onChange={jest.fn()}
|
|
56
|
+
/>,
|
|
57
|
+
);
|
|
58
|
+
expect(w).toMatchSnapshot();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('renders paragraphs properly', () => {
|
|
62
|
+
const w = shallow(
|
|
63
|
+
<TokenSelect
|
|
64
|
+
tokens={[
|
|
65
|
+
{
|
|
66
|
+
text: 'foo,',
|
|
67
|
+
start: 0,
|
|
68
|
+
end: 4,
|
|
69
|
+
predefined: true,
|
|
70
|
+
selectable: true,
|
|
71
|
+
selected: false,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
text: '\n\n',
|
|
75
|
+
start: 4,
|
|
76
|
+
end: 5,
|
|
77
|
+
selected: false,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
text: 'bar',
|
|
81
|
+
start: 5,
|
|
82
|
+
end: 8,
|
|
83
|
+
predefined: true,
|
|
84
|
+
selectable: true,
|
|
85
|
+
selected: false,
|
|
86
|
+
},
|
|
87
|
+
]}
|
|
88
|
+
classes={{}}
|
|
89
|
+
onChange={jest.fn()}
|
|
90
|
+
/>,
|
|
91
|
+
);
|
|
92
|
+
expect(w).toMatchSnapshot();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('renders in view mode with selected tokens', () => {
|
|
96
|
+
const w = shallow(
|
|
97
|
+
<TokenSelect
|
|
98
|
+
disabled
|
|
99
|
+
tokens={[
|
|
100
|
+
{
|
|
101
|
+
text: 'foo,',
|
|
102
|
+
start: 0,
|
|
103
|
+
end: 4,
|
|
104
|
+
predefined: true,
|
|
105
|
+
selectable: true,
|
|
106
|
+
selected: true,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
text: '\n',
|
|
110
|
+
start: 4,
|
|
111
|
+
end: 5,
|
|
112
|
+
selected: false,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
text: 'bar',
|
|
116
|
+
start: 5,
|
|
117
|
+
end: 8,
|
|
118
|
+
predefined: true,
|
|
119
|
+
selectable: true,
|
|
120
|
+
selected: true,
|
|
121
|
+
},
|
|
122
|
+
]}
|
|
123
|
+
classes={{}}
|
|
124
|
+
onChange={jest.fn()}
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
expect(w).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('logic', () => {
|
|
132
|
+
let w, onChange;
|
|
133
|
+
beforeEach(() => {
|
|
134
|
+
onChange = jest.fn();
|
|
135
|
+
w = shallow(
|
|
136
|
+
<TokenSelect
|
|
137
|
+
tokens={[
|
|
138
|
+
{
|
|
139
|
+
text: 'foo',
|
|
140
|
+
start: 0,
|
|
141
|
+
end: 3,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
text: 'bar',
|
|
145
|
+
start: 4,
|
|
146
|
+
end: 7,
|
|
147
|
+
},
|
|
148
|
+
]}
|
|
149
|
+
classes={{}}
|
|
150
|
+
onChange={onChange}
|
|
151
|
+
/>,
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
describe('selectedCount', () => {
|
|
155
|
+
it('returns the correct count', () => {
|
|
156
|
+
expect(w.instance().selectedCount()).toEqual(0);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('returns the correct count for 1 selected', () => {
|
|
160
|
+
w.setProps({ tokens: [{ selected: true }] });
|
|
161
|
+
expect(w.instance().selectedCount()).toEqual(1);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('canSelectMore', () => {
|
|
166
|
+
it('returns true for undefined max selections', () => {
|
|
167
|
+
w.setProps({ maxNoOfSelections: undefined });
|
|
168
|
+
expect(w.instance().canSelectMore(10)).toEqual(true);
|
|
169
|
+
});
|
|
170
|
+
it('returns true for 0 max selections', () => {
|
|
171
|
+
w.setProps({ maxNoOfSelections: 0 });
|
|
172
|
+
expect(w.instance().canSelectMore(10)).toEqual(true);
|
|
173
|
+
});
|
|
174
|
+
it('returns true for -1 max selections', () => {
|
|
175
|
+
w.setProps({ maxNoOfSelections: -1 });
|
|
176
|
+
expect(w.instance().canSelectMore(10)).toEqual(true);
|
|
177
|
+
});
|
|
178
|
+
it('returns true for 5 max selections and count 4', () => {
|
|
179
|
+
w.setProps({ maxNoOfSelections: 5 });
|
|
180
|
+
expect(w.instance().canSelectMore(4)).toEqual(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('returns true for 5 max selections and count 5', () => {
|
|
184
|
+
w.setProps({ maxNoOfSelections: 5 });
|
|
185
|
+
expect(w.instance().canSelectMore(5)).toEqual(false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('returns false for 5 max selections and count 6', () => {
|
|
189
|
+
w.setProps({ maxNoOfSelections: 5 });
|
|
190
|
+
expect(w.instance().canSelectMore(6)).toEqual(false);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('returns true for 1 max selections and count 1', () => {
|
|
194
|
+
w.setProps({ maxNoOfSelections: 1 });
|
|
195
|
+
expect(w.instance().canSelectMore(1)).toEqual(true);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('toggleToken', () => {
|
|
200
|
+
it('return if clicked target is not selectable', () => {
|
|
201
|
+
w.setProps({ maxNoOfSelections: 1, tokens: [{ selected: true }] });
|
|
202
|
+
|
|
203
|
+
const closest = jest.fn().mockReturnValue(null);
|
|
204
|
+
const mockedEvent = { target: { closest } };
|
|
205
|
+
|
|
206
|
+
w.instance().toggleToken(mockedEvent);
|
|
207
|
+
|
|
208
|
+
expect(onChange).not.toBeCalled();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('calls onChange', () => {
|
|
212
|
+
w.setProps({ maxNoOfSelections: 0, tokens: [{ selected: true }] });
|
|
213
|
+
|
|
214
|
+
const closest = jest.fn().mockReturnValue({
|
|
215
|
+
dataset: {
|
|
216
|
+
indexkey: '0',
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
const mockedEvent = { target: { closest } };
|
|
220
|
+
|
|
221
|
+
w.instance().toggleToken(mockedEvent);
|
|
222
|
+
|
|
223
|
+
expect(onChange).toBeCalled();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('returns if max tokens have been selected', () => {
|
|
227
|
+
w.setProps({ maxNoOfSelections: 0, tokens: [{ selected: true }] });
|
|
228
|
+
|
|
229
|
+
const closest = jest.fn().mockReturnValue({
|
|
230
|
+
dataset: {
|
|
231
|
+
indexkey: '0',
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
const mockedEvent = { target: { closest } };
|
|
235
|
+
|
|
236
|
+
w.instance().toggleToken(mockedEvent);
|
|
237
|
+
|
|
238
|
+
expect(onChange).not.toBeCalledWith([{ selected: true }]);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('calls onChange if maxNoOfSelections is 1 and selectedCount is 1', () => {
|
|
242
|
+
w.setProps({ maxNoOfSelections: 1, tokens: [{ selected: true }] });
|
|
243
|
+
|
|
244
|
+
const closest = jest.fn().mockReturnValue({
|
|
245
|
+
dataset: {
|
|
246
|
+
indexkey: '0',
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
const mockedEvent = { target: { closest } };
|
|
250
|
+
|
|
251
|
+
w.instance().toggleToken(mockedEvent);
|
|
252
|
+
|
|
253
|
+
expect(onChange).toBeCalled();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|