Skip to content

Commit 5738c91

Browse files
committed
improve case documentation #26
1 parent ba4d0f4 commit 5738c91

File tree

5 files changed

+72
-6
lines changed

5 files changed

+72
-6
lines changed

documentation/features.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
![demo](./images/select_one_key_scenario_2.gif)
2525

26-
### Should do nothing if selecting an already selected key
26+
### Should deselect all but the selected key
2727
| | |
2828
| --- | ---|
29-
| Implemented | |
30-
| Has tests | |
29+
| Implemented | |
30+
| Has tests | |
3131
| Hot Key | `click` |
3232
| Issue | https://github.com/codingedgar/macos-multi-select/issues/26 |
3333

2.48 MB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macos-multi-select",
3-
"version": "0.2.0-rc.0",
3+
"version": "0.2.0-rc.1",
44
"description": "Given an Index, and an Action, return an array of selected keys with the same behaviour of macOS finder list view selection.",
55
"main": "dist/index.js",
66
"repository": "[email protected]:codingedgar/macos-multi-select.git",

src/spec/arbitraries.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fc from 'fast-check';
2-
import { sort } from 'ramda';
2+
import { sort, uniq } from 'ramda';
33

44
export function subsequentSubarray(arr: string[]) {
55
return fc.tuple(fc.nat(arr.length), fc.nat(arr.length))
@@ -83,3 +83,24 @@ export function indexWithAdjacentConnections() {
8383
})
8484
)
8585
}
86+
87+
export function indexWithSelection() {
88+
return fc.tuple(
89+
fc.set(
90+
fc.string(),
91+
{ minLength: 1 }
92+
),
93+
fc.array(fc.nat(), { minLength: 1 }),
94+
fc.nat()
95+
)
96+
.map(([index, selectedIndices, selectOneIndex]) => {
97+
const selected = uniq(selectedIndices.map(i => index[i % index.length]));
98+
const selectOne = selected[selectOneIndex % selected.length];
99+
100+
return {
101+
index,
102+
selected,
103+
selectOne
104+
}
105+
})
106+
}

src/spec/selectOne.spec.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fc from 'fast-check';
22
import { head } from 'ramda';
3-
import { multiselect } from '../index';
3+
import { Context, multiselect } from '../index';
4+
import { indexWithSelection } from './arbitraries';
45

56
describe('Select One Key', () => {
67
test('should be able to select one key in a non empty index', () => {
@@ -91,4 +92,48 @@ describe('Select One Key', () => {
9192
)
9293
)
9394
});
95+
96+
test('Should deselect all but the selected key', () => {
97+
fc.assert(
98+
fc.property(
99+
indexWithSelection(),
100+
({
101+
index,
102+
selected,
103+
selectOne,
104+
}) => {
105+
const context: Context = selected.reduce(
106+
(ctx, key) =>
107+
multiselect(
108+
ctx,
109+
{
110+
type: "TOGGLE SELECTION",
111+
id: key,
112+
}
113+
),
114+
{
115+
index,
116+
selected: [],
117+
adjacentPivot: undefined,
118+
} as Context
119+
);
120+
121+
expect(
122+
multiselect(
123+
context,
124+
{
125+
type: "SELECT ONE",
126+
id: selectOne,
127+
}
128+
)
129+
)
130+
.toEqual({
131+
index,
132+
selected: [selectOne],
133+
adjacentPivot: selectOne,
134+
})
135+
}
136+
)
137+
)
138+
});
94139
})

0 commit comments

Comments
 (0)