Skip to content

Commit 40d4fe4

Browse files
committed
deselect all #7
1 parent 64b4585 commit 40d4fe4

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

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.0.2",
3+
"version": "0.0.3",
44
"description": "Given a list of ids, and an action, return a list of selected items 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/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type Context = {
66
type Command =
77
| { type: "SELECT ONE", id: string }
88
| { type: "TOGGLE SELECTION", id: string }
9+
| { type: "DESELECT ALL" }
910

1011
export function multiselect(context: Context, command: Command): Context {
1112
if (command.type === "SELECT ONE" && context.list.includes(command.id)) {
@@ -30,6 +31,11 @@ export function multiselect(context: Context, command: Command): Context {
3031
...context,
3132
selected: context.selected.concat([command.id])
3233
};
34+
} else if (command.type === "DESELECT ALL") {
35+
return {
36+
...context,
37+
selected: []
38+
}
3339
} else {
3440
return context;
3541
}

src/spec/deselectAll.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import fc from 'fast-check';
2+
import { multiselect, Context } from '../index';
3+
4+
describe('Deselect All', () => {
5+
test('should deselect all', () => {
6+
7+
fc.assert(
8+
fc.property(
9+
fc.set(
10+
fc.string()
11+
)
12+
.filter(list => list.length > 0)
13+
.chain(list =>
14+
fc.record({
15+
list: fc.constant(list),
16+
selected: fc.set(
17+
fc.integer(0, list.length-1)
18+
.map(index => list[index]),
19+
),
20+
})
21+
),
22+
({
23+
list,
24+
selected
25+
}) => {
26+
expect(
27+
multiselect(
28+
{
29+
list,
30+
selected,
31+
},
32+
{
33+
type: "DESELECT ALL",
34+
}
35+
)
36+
)
37+
.toEqual({
38+
list,
39+
selected: []
40+
})
41+
}
42+
)
43+
)
44+
});
45+
})

src/spec/selectOne.ts renamed to src/spec/selectOne.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fc from 'fast-check';
22
import { multiselect } from '../index';
33

4-
describe('Select an Item', () => {
4+
describe('Select One Item', () => {
55
test('should be able to select one item in a non empty list', () => {
66

77
fc.assert(

src/spec/toggleSelection.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fc from 'fast-check';
22
import { multiselect, Context } from '../index';
33

4-
describe('TOGGLE SELECTION', () => {
4+
describe('Toggle Selection', () => {
55
test('should be able to add to selection one item in a non empty list', () => {
66

77
fc.assert(

0 commit comments

Comments
 (0)