@dhis2-ui/transfer 10.13.1 → 10.14.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/build/cjs/__e2e__/reorder-with-buttons.e2e.stories.js +15 -4
- package/build/cjs/__tests__/helper/default-filter-callback.test.js +6 -0
- package/build/cjs/__tests__/helper/is-reorder-down-disabled.test.js +50 -11
- package/build/cjs/__tests__/helper/is-reorder-up-disabled.test.js +50 -11
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-down.test.js +65 -11
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-to-bottom.test.js +85 -0
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-to-top.test.js +85 -0
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-up.test.js +65 -11
- package/build/cjs/__tests__/reordering-actions.test.js +104 -0
- package/build/cjs/features/reorder-with-buttons/index.js +70 -2
- package/build/cjs/features/reorder-with-buttons.feature +97 -5
- package/build/cjs/icons.js +53 -13
- package/build/cjs/locales/en/translations.json +7 -0
- package/build/cjs/locales/index.js +21 -0
- package/build/cjs/reordering-actions.js +93 -27
- package/build/cjs/transfer/default-filter-callback.js +17 -6
- package/build/cjs/transfer/get-highlighted-picked-indices.js +34 -0
- package/build/cjs/transfer/index.js +33 -0
- package/build/cjs/transfer/is-reorder-down-disabled.js +19 -8
- package/build/cjs/transfer/is-reorder-up-disabled.js +18 -8
- package/build/cjs/transfer/move-highlighted-picked-option-down.js +23 -6
- package/build/cjs/transfer/move-highlighted-picked-option-to-bottom.js +45 -0
- package/build/cjs/transfer/move-highlighted-picked-option-to-top.js +44 -0
- package/build/cjs/transfer/move-highlighted-picked-option-up.js +21 -6
- package/build/cjs/transfer.js +58 -6
- package/build/cjs/transfer.prod.stories.js +89 -19
- package/build/es/__e2e__/reorder-with-buttons.e2e.stories.js +14 -2
- package/build/es/__tests__/helper/default-filter-callback.test.js +6 -0
- package/build/es/__tests__/helper/is-reorder-down-disabled.test.js +50 -11
- package/build/es/__tests__/helper/is-reorder-up-disabled.test.js +50 -11
- package/build/es/__tests__/helper/move-highlighted-picked-option-down.test.js +65 -11
- package/build/es/__tests__/helper/move-highlighted-picked-option-to-bottom.test.js +83 -0
- package/build/es/__tests__/helper/move-highlighted-picked-option-to-top.test.js +83 -0
- package/build/es/__tests__/helper/move-highlighted-picked-option-up.test.js +65 -11
- package/build/es/__tests__/reordering-actions.test.js +101 -0
- package/build/es/features/reorder-with-buttons/index.js +70 -2
- package/build/es/features/reorder-with-buttons.feature +97 -5
- package/build/es/icons.js +51 -13
- package/build/es/locales/en/translations.json +7 -0
- package/build/es/locales/index.js +13 -0
- package/build/es/reordering-actions.js +94 -28
- package/build/es/transfer/default-filter-callback.js +17 -6
- package/build/es/transfer/get-highlighted-picked-indices.js +27 -0
- package/build/es/transfer/index.js +3 -0
- package/build/es/transfer/is-reorder-down-disabled.js +20 -8
- package/build/es/transfer/is-reorder-up-disabled.js +19 -8
- package/build/es/transfer/move-highlighted-picked-option-down.js +24 -6
- package/build/es/transfer/move-highlighted-picked-option-to-bottom.js +39 -0
- package/build/es/transfer/move-highlighted-picked-option-to-top.js +38 -0
- package/build/es/transfer/move-highlighted-picked-option-up.js +22 -6
- package/build/es/transfer.js +60 -8
- package/build/es/transfer.prod.stories.js +88 -18
- package/package.json +9 -7
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.HasSomeSelected = void 0;
|
|
6
|
+
exports.default = exports.HasThreeSelected = exports.HasSomeSelected = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _transfer = require("../transfer.js");
|
|
9
9
|
var _options = require("./common/options.js");
|
|
@@ -12,7 +12,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
12
12
|
var _default = exports.default = {
|
|
13
13
|
title: 'Transfer Reorder Buttons'
|
|
14
14
|
};
|
|
15
|
-
const
|
|
15
|
+
const renderReorderTransfer = (_, _ref) => {
|
|
16
16
|
let {
|
|
17
17
|
selected,
|
|
18
18
|
onChange
|
|
@@ -24,14 +24,25 @@ const HasSomeSelected = (_, _ref) => {
|
|
|
24
24
|
options: _options.options
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
|
-
exports.HasSomeSelected =
|
|
27
|
+
const HasSomeSelected = exports.HasSomeSelected = renderReorderTransfer.bind({});
|
|
28
28
|
HasSomeSelected.story = {
|
|
29
29
|
decorators: [(0, _statefulDecorator.statefulDecorator)({
|
|
30
|
-
initialState: _options.options.slice(0,
|
|
30
|
+
initialState: _options.options.slice(0, 8).map(_ref2 => {
|
|
31
31
|
let {
|
|
32
32
|
value
|
|
33
33
|
} = _ref2;
|
|
34
34
|
return value;
|
|
35
35
|
})
|
|
36
36
|
})]
|
|
37
|
+
};
|
|
38
|
+
const HasThreeSelected = exports.HasThreeSelected = renderReorderTransfer.bind({});
|
|
39
|
+
HasThreeSelected.story = {
|
|
40
|
+
decorators: [(0, _statefulDecorator.statefulDecorator)({
|
|
41
|
+
initialState: _options.options.slice(0, 3).map(_ref3 => {
|
|
42
|
+
let {
|
|
43
|
+
value
|
|
44
|
+
} = _ref3;
|
|
45
|
+
return value;
|
|
46
|
+
})
|
|
47
|
+
})]
|
|
37
48
|
};
|
|
@@ -39,4 +39,10 @@ describe('Transfer - defaultFilterCallback', () => {
|
|
|
39
39
|
const actual = (0, _defaultFilterCallback.defaultFilterCallback)(options, filter);
|
|
40
40
|
expect(actual).toEqual(expected);
|
|
41
41
|
});
|
|
42
|
+
it('should return all options when the filter is invalid regexp', () => {
|
|
43
|
+
const filter = '(';
|
|
44
|
+
const expected = options;
|
|
45
|
+
const actual = (0, _defaultFilterCallback.defaultFilterCallback)(options, filter);
|
|
46
|
+
expect(actual).toEqual(expected);
|
|
47
|
+
});
|
|
42
48
|
});
|
|
@@ -4,35 +4,74 @@ var _isReorderDownDisabled = require("../../transfer/is-reorder-down-disabled.js
|
|
|
4
4
|
describe('Transfer - isReorderDownDisabled', () => {
|
|
5
5
|
const selected = ['foo', 'bar', 'baz'];
|
|
6
6
|
it('should return true when there are no highlighted picked options', () => {
|
|
7
|
-
const highlightedPickedOptions = [];
|
|
8
7
|
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
9
|
-
highlightedPickedOptions,
|
|
8
|
+
highlightedPickedOptions: [],
|
|
10
9
|
selected
|
|
11
10
|
});
|
|
12
11
|
expect(actual).toBe(true);
|
|
13
12
|
});
|
|
14
|
-
it('should return true
|
|
15
|
-
const highlightedPickedOptions = ['bar', 'foo'];
|
|
13
|
+
it('should return true if the last picked option is the only highlighted one', () => {
|
|
16
14
|
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
17
|
-
highlightedPickedOptions,
|
|
15
|
+
highlightedPickedOptions: ['baz'],
|
|
18
16
|
selected
|
|
19
17
|
});
|
|
20
18
|
expect(actual).toBe(true);
|
|
21
19
|
});
|
|
22
|
-
it('should return
|
|
23
|
-
const
|
|
20
|
+
it('should return false when one picked option is highlighted which is not the last one', () => {
|
|
21
|
+
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
22
|
+
highlightedPickedOptions: ['bar'],
|
|
23
|
+
selected
|
|
24
|
+
});
|
|
25
|
+
expect(actual).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
it('should return false for a contiguous multi-select not flush to the bottom', () => {
|
|
28
|
+
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
29
|
+
highlightedPickedOptions: ['foo', 'bar'],
|
|
30
|
+
selected
|
|
31
|
+
});
|
|
32
|
+
expect(actual).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
it('should return true for a contiguous multi-select flush to the bottom', () => {
|
|
24
35
|
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
25
|
-
highlightedPickedOptions,
|
|
36
|
+
highlightedPickedOptions: ['bar', 'baz'],
|
|
26
37
|
selected
|
|
27
38
|
});
|
|
28
39
|
expect(actual).toBe(true);
|
|
29
40
|
});
|
|
30
|
-
it('should return
|
|
31
|
-
const highlightedPickedOptions = ['bar'];
|
|
41
|
+
it('should return true when all items are highlighted', () => {
|
|
32
42
|
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
33
|
-
highlightedPickedOptions,
|
|
43
|
+
highlightedPickedOptions: ['foo', 'bar', 'baz'],
|
|
44
|
+
selected
|
|
45
|
+
});
|
|
46
|
+
expect(actual).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('should return false for a non-contiguous selection containing the last item', () => {
|
|
49
|
+
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
50
|
+
highlightedPickedOptions: ['foo', 'baz'],
|
|
51
|
+
selected
|
|
52
|
+
});
|
|
53
|
+
expect(actual).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
it('should ignore highlighted values that do not exist in selected', () => {
|
|
56
|
+
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
57
|
+
highlightedPickedOptions: ['ghost', 'foo'],
|
|
34
58
|
selected
|
|
35
59
|
});
|
|
36
60
|
expect(actual).toBe(false);
|
|
37
61
|
});
|
|
62
|
+
it('should return true when all highlighted values are missing from selected', () => {
|
|
63
|
+
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
64
|
+
highlightedPickedOptions: ['ghost'],
|
|
65
|
+
selected
|
|
66
|
+
});
|
|
67
|
+
expect(actual).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('should return true when a filter is active on the picked side', () => {
|
|
70
|
+
const actual = (0, _isReorderDownDisabled.isReorderDownDisabled)({
|
|
71
|
+
highlightedPickedOptions: ['foo'],
|
|
72
|
+
selected,
|
|
73
|
+
filterActivePicked: true
|
|
74
|
+
});
|
|
75
|
+
expect(actual).toBe(true);
|
|
76
|
+
});
|
|
38
77
|
});
|
|
@@ -4,35 +4,74 @@ var _isReorderUpDisabled = require("../../transfer/is-reorder-up-disabled.js");
|
|
|
4
4
|
describe('Transfer - isReorderUpDisabled', () => {
|
|
5
5
|
const selected = ['foo', 'bar', 'baz'];
|
|
6
6
|
it('should return true when there are no highlighted picked options', () => {
|
|
7
|
-
const highlightedPickedOptions = [];
|
|
8
7
|
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
9
|
-
highlightedPickedOptions,
|
|
8
|
+
highlightedPickedOptions: [],
|
|
10
9
|
selected
|
|
11
10
|
});
|
|
12
11
|
expect(actual).toBe(true);
|
|
13
12
|
});
|
|
14
|
-
it('should return true
|
|
15
|
-
const highlightedPickedOptions = ['bar', 'baz'];
|
|
13
|
+
it('should return true if the first picked option is the only highlighted one', () => {
|
|
16
14
|
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
17
|
-
highlightedPickedOptions,
|
|
15
|
+
highlightedPickedOptions: ['foo'],
|
|
18
16
|
selected
|
|
19
17
|
});
|
|
20
18
|
expect(actual).toBe(true);
|
|
21
19
|
});
|
|
22
|
-
it('should return
|
|
23
|
-
const highlightedPickedOptions = ['foo'];
|
|
20
|
+
it('should return false when one picked option is highlighted which is not the first one', () => {
|
|
24
21
|
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
25
|
-
highlightedPickedOptions,
|
|
22
|
+
highlightedPickedOptions: ['baz'],
|
|
23
|
+
selected
|
|
24
|
+
});
|
|
25
|
+
expect(actual).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
it('should return false for a contiguous multi-select not flush to the top', () => {
|
|
28
|
+
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
29
|
+
highlightedPickedOptions: ['bar', 'baz'],
|
|
30
|
+
selected
|
|
31
|
+
});
|
|
32
|
+
expect(actual).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
it('should return true for a contiguous multi-select flush to the top', () => {
|
|
35
|
+
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
36
|
+
highlightedPickedOptions: ['foo', 'bar'],
|
|
37
|
+
selected
|
|
38
|
+
});
|
|
39
|
+
expect(actual).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('should return true when all items are highlighted', () => {
|
|
42
|
+
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
43
|
+
highlightedPickedOptions: ['foo', 'bar', 'baz'],
|
|
26
44
|
selected
|
|
27
45
|
});
|
|
28
46
|
expect(actual).toBe(true);
|
|
29
47
|
});
|
|
30
|
-
it('should return false
|
|
31
|
-
const highlightedPickedOptions = ['baz'];
|
|
48
|
+
it('should return false for a non-contiguous selection containing the first item', () => {
|
|
32
49
|
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
33
|
-
highlightedPickedOptions,
|
|
50
|
+
highlightedPickedOptions: ['foo', 'baz'],
|
|
34
51
|
selected
|
|
35
52
|
});
|
|
36
53
|
expect(actual).toBe(false);
|
|
37
54
|
});
|
|
55
|
+
it('should ignore highlighted values that do not exist in selected', () => {
|
|
56
|
+
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
57
|
+
highlightedPickedOptions: ['ghost', 'baz'],
|
|
58
|
+
selected
|
|
59
|
+
});
|
|
60
|
+
expect(actual).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
it('should return true when all highlighted values are missing from selected', () => {
|
|
63
|
+
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
64
|
+
highlightedPickedOptions: ['ghost'],
|
|
65
|
+
selected
|
|
66
|
+
});
|
|
67
|
+
expect(actual).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('should return true when a filter is active on the picked side', () => {
|
|
70
|
+
const actual = (0, _isReorderUpDisabled.isReorderUpDisabled)({
|
|
71
|
+
highlightedPickedOptions: ['baz'],
|
|
72
|
+
selected,
|
|
73
|
+
filterActivePicked: true
|
|
74
|
+
});
|
|
75
|
+
expect(actual).toBe(true);
|
|
76
|
+
});
|
|
38
77
|
});
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
var _moveHighlightedPickedOptionDown = require("../../transfer/move-highlighted-picked-option-down.js");
|
|
4
4
|
describe('Transfer - moveHighlightedPickedOptionDown', () => {
|
|
5
5
|
const onChange = jest.fn();
|
|
6
|
-
const selected = ['foo', 'bar', 'baz'];
|
|
7
6
|
afterEach(() => {
|
|
8
7
|
onChange.mockClear();
|
|
9
8
|
});
|
|
10
|
-
it('should move
|
|
11
|
-
const highlighted = ['bar'];
|
|
9
|
+
it('should move a single highlighted option down', () => {
|
|
12
10
|
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
13
|
-
selected,
|
|
14
|
-
highlightedPickedOptions:
|
|
11
|
+
selected: ['foo', 'bar', 'baz'],
|
|
12
|
+
highlightedPickedOptions: ['bar'],
|
|
15
13
|
onChange
|
|
16
14
|
});
|
|
17
15
|
expect(onChange).toHaveBeenCalledWith({
|
|
@@ -19,21 +17,77 @@ describe('Transfer - moveHighlightedPickedOptionDown', () => {
|
|
|
19
17
|
});
|
|
20
18
|
});
|
|
21
19
|
it('should do nothing when trying to move down the last option', () => {
|
|
22
|
-
const highlighted = ['baz'];
|
|
23
20
|
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
24
|
-
selected,
|
|
25
|
-
highlightedPickedOptions:
|
|
21
|
+
selected: ['foo', 'bar', 'baz'],
|
|
22
|
+
highlightedPickedOptions: ['baz'],
|
|
26
23
|
onChange
|
|
27
24
|
});
|
|
28
25
|
expect(onChange).toHaveBeenCalledTimes(0);
|
|
29
26
|
});
|
|
30
27
|
it('should do nothing when trying to move down a non-existing option', () => {
|
|
31
|
-
const highlighted = ['foobar'];
|
|
32
28
|
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
33
|
-
selected,
|
|
34
|
-
highlightedPickedOptions:
|
|
29
|
+
selected: ['foo', 'bar', 'baz'],
|
|
30
|
+
highlightedPickedOptions: ['ghost'],
|
|
35
31
|
onChange
|
|
36
32
|
});
|
|
37
33
|
expect(onChange).toHaveBeenCalledTimes(0);
|
|
38
34
|
});
|
|
35
|
+
it('should shift a contiguous block of highlighted options down as a group', () => {
|
|
36
|
+
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
37
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
38
|
+
highlightedPickedOptions: ['b', 'c'],
|
|
39
|
+
onChange
|
|
40
|
+
});
|
|
41
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
42
|
+
selected: ['a', 'd', 'b', 'c', 'e']
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('should collapse and shift a non-contiguous selection down in one call', () => {
|
|
46
|
+
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
47
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
48
|
+
highlightedPickedOptions: ['b', 'd'],
|
|
49
|
+
onChange
|
|
50
|
+
});
|
|
51
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
52
|
+
selected: ['a', 'c', 'e', 'b', 'd']
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it('should preserve the relative order of highlighted items regardless of input order', () => {
|
|
56
|
+
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
57
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
58
|
+
highlightedPickedOptions: ['d', 'b'],
|
|
59
|
+
onChange
|
|
60
|
+
});
|
|
61
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
62
|
+
selected: ['a', 'c', 'e', 'b', 'd']
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('should collapse a non-contiguous selection containing the last item without shifting past the end', () => {
|
|
66
|
+
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
67
|
+
selected: ['a', 'b', 'c'],
|
|
68
|
+
highlightedPickedOptions: ['a', 'c'],
|
|
69
|
+
onChange
|
|
70
|
+
});
|
|
71
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
72
|
+
selected: ['b', 'a', 'c']
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('should do nothing when the highlighted block is already flush to the bottom', () => {
|
|
76
|
+
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
77
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
78
|
+
highlightedPickedOptions: ['c', 'd'],
|
|
79
|
+
onChange
|
|
80
|
+
});
|
|
81
|
+
expect(onChange).toHaveBeenCalledTimes(0);
|
|
82
|
+
});
|
|
83
|
+
it('should ignore highlighted values that do not exist in selected', () => {
|
|
84
|
+
(0, _moveHighlightedPickedOptionDown.moveHighlightedPickedOptionDown)({
|
|
85
|
+
selected: ['a', 'b', 'c'],
|
|
86
|
+
highlightedPickedOptions: ['ghost', 'a'],
|
|
87
|
+
onChange
|
|
88
|
+
});
|
|
89
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
90
|
+
selected: ['b', 'a', 'c']
|
|
91
|
+
});
|
|
92
|
+
});
|
|
39
93
|
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _moveHighlightedPickedOptionToBottom = require("../../transfer/move-highlighted-picked-option-to-bottom.js");
|
|
4
|
+
describe('Transfer - moveHighlightedPickedOptionToBottom', () => {
|
|
5
|
+
const onChange = jest.fn();
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
onChange.mockClear();
|
|
8
|
+
});
|
|
9
|
+
it('should move a single highlighted option to the bottom', () => {
|
|
10
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
11
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
12
|
+
highlightedPickedOptions: ['b'],
|
|
13
|
+
onChange
|
|
14
|
+
});
|
|
15
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
16
|
+
selected: ['a', 'c', 'd', 'b']
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('should move a contiguous block to the bottom as a group', () => {
|
|
20
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
21
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
22
|
+
highlightedPickedOptions: ['b', 'c'],
|
|
23
|
+
onChange
|
|
24
|
+
});
|
|
25
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
26
|
+
selected: ['a', 'd', 'e', 'b', 'c']
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('should collapse a non-contiguous selection to the bottom preserving relative order', () => {
|
|
30
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
31
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
32
|
+
highlightedPickedOptions: ['b', 'd'],
|
|
33
|
+
onChange
|
|
34
|
+
});
|
|
35
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
36
|
+
selected: ['a', 'c', 'e', 'b', 'd']
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('should preserve relative order regardless of highlight input order', () => {
|
|
40
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
41
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
42
|
+
highlightedPickedOptions: ['d', 'b'],
|
|
43
|
+
onChange
|
|
44
|
+
});
|
|
45
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
46
|
+
selected: ['a', 'c', 'e', 'b', 'd']
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it('should do nothing when the highlighted block is already flush to the bottom', () => {
|
|
50
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
51
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
52
|
+
highlightedPickedOptions: ['c', 'd'],
|
|
53
|
+
onChange
|
|
54
|
+
});
|
|
55
|
+
expect(onChange).toHaveBeenCalledTimes(0);
|
|
56
|
+
});
|
|
57
|
+
it('should still run when the selection includes the bottom item but has a gap', () => {
|
|
58
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
59
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
60
|
+
highlightedPickedOptions: ['b', 'd'],
|
|
61
|
+
onChange
|
|
62
|
+
});
|
|
63
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
64
|
+
selected: ['a', 'c', 'b', 'd']
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('should do nothing when no highlighted options exist in selected', () => {
|
|
68
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
69
|
+
selected: ['a', 'b', 'c'],
|
|
70
|
+
highlightedPickedOptions: ['ghost'],
|
|
71
|
+
onChange
|
|
72
|
+
});
|
|
73
|
+
expect(onChange).toHaveBeenCalledTimes(0);
|
|
74
|
+
});
|
|
75
|
+
it('should ignore highlighted values that do not exist in selected', () => {
|
|
76
|
+
(0, _moveHighlightedPickedOptionToBottom.moveHighlightedPickedOptionToBottom)({
|
|
77
|
+
selected: ['a', 'b', 'c'],
|
|
78
|
+
highlightedPickedOptions: ['ghost', 'a'],
|
|
79
|
+
onChange
|
|
80
|
+
});
|
|
81
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
82
|
+
selected: ['b', 'c', 'a']
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _moveHighlightedPickedOptionToTop = require("../../transfer/move-highlighted-picked-option-to-top.js");
|
|
4
|
+
describe('Transfer - moveHighlightedPickedOptionToTop', () => {
|
|
5
|
+
const onChange = jest.fn();
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
onChange.mockClear();
|
|
8
|
+
});
|
|
9
|
+
it('should move a single highlighted option to the top', () => {
|
|
10
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
11
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
12
|
+
highlightedPickedOptions: ['c'],
|
|
13
|
+
onChange
|
|
14
|
+
});
|
|
15
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
16
|
+
selected: ['c', 'a', 'b', 'd']
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('should move a contiguous block to the top as a group', () => {
|
|
20
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
21
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
22
|
+
highlightedPickedOptions: ['c', 'd'],
|
|
23
|
+
onChange
|
|
24
|
+
});
|
|
25
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
26
|
+
selected: ['c', 'd', 'a', 'b', 'e']
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('should collapse a non-contiguous selection to the top preserving relative order', () => {
|
|
30
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
31
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
32
|
+
highlightedPickedOptions: ['b', 'd'],
|
|
33
|
+
onChange
|
|
34
|
+
});
|
|
35
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
36
|
+
selected: ['b', 'd', 'a', 'c', 'e']
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it('should preserve relative order regardless of highlight input order', () => {
|
|
40
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
41
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
42
|
+
highlightedPickedOptions: ['d', 'b'],
|
|
43
|
+
onChange
|
|
44
|
+
});
|
|
45
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
46
|
+
selected: ['b', 'd', 'a', 'c', 'e']
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
it('should do nothing when the highlighted block is already flush to the top', () => {
|
|
50
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
51
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
52
|
+
highlightedPickedOptions: ['a', 'b'],
|
|
53
|
+
onChange
|
|
54
|
+
});
|
|
55
|
+
expect(onChange).toHaveBeenCalledTimes(0);
|
|
56
|
+
});
|
|
57
|
+
it('should still run when the selection includes the top item but has a gap', () => {
|
|
58
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
59
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
60
|
+
highlightedPickedOptions: ['a', 'c'],
|
|
61
|
+
onChange
|
|
62
|
+
});
|
|
63
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
64
|
+
selected: ['a', 'c', 'b', 'd']
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('should do nothing when no highlighted options exist in selected', () => {
|
|
68
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
69
|
+
selected: ['a', 'b', 'c'],
|
|
70
|
+
highlightedPickedOptions: ['ghost'],
|
|
71
|
+
onChange
|
|
72
|
+
});
|
|
73
|
+
expect(onChange).toHaveBeenCalledTimes(0);
|
|
74
|
+
});
|
|
75
|
+
it('should ignore highlighted values that do not exist in selected', () => {
|
|
76
|
+
(0, _moveHighlightedPickedOptionToTop.moveHighlightedPickedOptionToTop)({
|
|
77
|
+
selected: ['a', 'b', 'c'],
|
|
78
|
+
highlightedPickedOptions: ['ghost', 'c'],
|
|
79
|
+
onChange
|
|
80
|
+
});
|
|
81
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
82
|
+
selected: ['c', 'a', 'b']
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
var _moveHighlightedPickedOptionUp = require("../../transfer/move-highlighted-picked-option-up.js");
|
|
4
4
|
describe('Transfer - moveHighlightedPickedOptionUp', () => {
|
|
5
5
|
const onChange = jest.fn();
|
|
6
|
-
const selected = ['foo', 'bar', 'baz'];
|
|
7
6
|
afterEach(() => {
|
|
8
7
|
onChange.mockClear();
|
|
9
8
|
});
|
|
10
|
-
it('should move
|
|
11
|
-
const highlighted = ['bar'];
|
|
9
|
+
it('should move a single highlighted option up', () => {
|
|
12
10
|
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
13
|
-
selected,
|
|
14
|
-
highlightedPickedOptions:
|
|
11
|
+
selected: ['foo', 'bar', 'baz'],
|
|
12
|
+
highlightedPickedOptions: ['bar'],
|
|
15
13
|
onChange
|
|
16
14
|
});
|
|
17
15
|
expect(onChange).toHaveBeenCalledWith({
|
|
@@ -19,21 +17,77 @@ describe('Transfer - moveHighlightedPickedOptionUp', () => {
|
|
|
19
17
|
});
|
|
20
18
|
});
|
|
21
19
|
it('should do nothing when trying to move up the first option', () => {
|
|
22
|
-
const highlighted = ['foo'];
|
|
23
20
|
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
24
|
-
selected,
|
|
25
|
-
highlightedPickedOptions:
|
|
21
|
+
selected: ['foo', 'bar', 'baz'],
|
|
22
|
+
highlightedPickedOptions: ['foo'],
|
|
26
23
|
onChange
|
|
27
24
|
});
|
|
28
25
|
expect(onChange).toHaveBeenCalledTimes(0);
|
|
29
26
|
});
|
|
30
27
|
it('should do nothing when trying to move up a non-existing option', () => {
|
|
31
|
-
const highlighted = ['foobar'];
|
|
32
28
|
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
33
|
-
selected,
|
|
34
|
-
highlightedPickedOptions:
|
|
29
|
+
selected: ['foo', 'bar', 'baz'],
|
|
30
|
+
highlightedPickedOptions: ['ghost'],
|
|
35
31
|
onChange
|
|
36
32
|
});
|
|
37
33
|
expect(onChange).toHaveBeenCalledTimes(0);
|
|
38
34
|
});
|
|
35
|
+
it('should shift a contiguous block of highlighted options up as a group', () => {
|
|
36
|
+
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
37
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
38
|
+
highlightedPickedOptions: ['c', 'd'],
|
|
39
|
+
onChange
|
|
40
|
+
});
|
|
41
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
42
|
+
selected: ['a', 'c', 'd', 'b', 'e']
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('should collapse and shift a non-contiguous selection up in one call', () => {
|
|
46
|
+
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
47
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
48
|
+
highlightedPickedOptions: ['b', 'd'],
|
|
49
|
+
onChange
|
|
50
|
+
});
|
|
51
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
52
|
+
selected: ['b', 'd', 'a', 'c', 'e']
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it('should preserve the relative order of highlighted items regardless of input order', () => {
|
|
56
|
+
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
57
|
+
selected: ['a', 'b', 'c', 'd', 'e'],
|
|
58
|
+
highlightedPickedOptions: ['d', 'b'],
|
|
59
|
+
onChange
|
|
60
|
+
});
|
|
61
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
62
|
+
selected: ['b', 'd', 'a', 'c', 'e']
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('should collapse a non-contiguous selection containing the first item without shifting past index 0', () => {
|
|
66
|
+
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
67
|
+
selected: ['a', 'b', 'c'],
|
|
68
|
+
highlightedPickedOptions: ['a', 'c'],
|
|
69
|
+
onChange
|
|
70
|
+
});
|
|
71
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
72
|
+
selected: ['a', 'c', 'b']
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('should do nothing when the highlighted block is already flush to the top', () => {
|
|
76
|
+
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
77
|
+
selected: ['a', 'b', 'c', 'd'],
|
|
78
|
+
highlightedPickedOptions: ['a', 'b'],
|
|
79
|
+
onChange
|
|
80
|
+
});
|
|
81
|
+
expect(onChange).toHaveBeenCalledTimes(0);
|
|
82
|
+
});
|
|
83
|
+
it('should ignore highlighted values that do not exist in selected', () => {
|
|
84
|
+
(0, _moveHighlightedPickedOptionUp.moveHighlightedPickedOptionUp)({
|
|
85
|
+
selected: ['a', 'b', 'c'],
|
|
86
|
+
highlightedPickedOptions: ['ghost', 'c'],
|
|
87
|
+
onChange
|
|
88
|
+
});
|
|
89
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
90
|
+
selected: ['a', 'c', 'b']
|
|
91
|
+
});
|
|
92
|
+
});
|
|
39
93
|
});
|