-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #707 from madeindjs/WF-148
feat(ui): handle components multiselection - Wf-148
- Loading branch information
Showing
23 changed files
with
573 additions
and
133 deletions.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { generateBuilderManager, SelectionStatus } from "./builderManager"; | ||
|
||
describe(generateBuilderManager.name, () => { | ||
describe("selection", () => { | ||
it("should select an element", () => { | ||
const { | ||
setSelection, | ||
isComponentIdSelected, | ||
selectionStatus, | ||
firstSelectedId, | ||
} = generateBuilderManager(); | ||
|
||
setSelection("componentId", "instancePath", "click"); | ||
|
||
expect(firstSelectedId.value).toBe("componentId"); | ||
expect(isComponentIdSelected("componentId")).toBeTruthy(); | ||
expect(selectionStatus.value).toBe(SelectionStatus.Single); | ||
}); | ||
|
||
it("should select multiple element", () => { | ||
const { | ||
setSelection, | ||
appendSelection, | ||
isComponentIdSelected, | ||
selectionStatus, | ||
firstSelectedId, | ||
} = generateBuilderManager(); | ||
|
||
setSelection("componentId", "instancePath", "click"); | ||
appendSelection("componentId2", "instancePath2", "click"); | ||
|
||
expect(firstSelectedId.value).toBe("componentId"); | ||
expect(isComponentIdSelected("componentId")).toBeTruthy(); | ||
expect(isComponentIdSelected("componentId2")).toBeTruthy(); | ||
expect(selectionStatus.value).toBe(SelectionStatus.Multiple); | ||
}); | ||
|
||
it("should clear the selection an element", () => { | ||
const { | ||
setSelection, | ||
isComponentIdSelected, | ||
selectionStatus, | ||
firstSelectedId, | ||
} = generateBuilderManager(); | ||
|
||
setSelection("componentId", "instancePath", "click"); | ||
setSelection(null); | ||
|
||
expect(firstSelectedId.value).toBeUndefined(); | ||
expect(isComponentIdSelected("componentId")).toBeFalsy(); | ||
expect(selectionStatus.value).toBe(SelectionStatus.None); | ||
}); | ||
|
||
it("should handle click events", () => { | ||
const { | ||
handleSelectionFromEvent, | ||
isComponentIdSelected, | ||
selectionStatus, | ||
} = generateBuilderManager(); | ||
|
||
handleSelectionFromEvent( | ||
{ ctrlKey: true } as KeyboardEvent, | ||
"1", | ||
"path", | ||
); | ||
|
||
expect(selectionStatus.value).toBe(SelectionStatus.Single); | ||
expect(isComponentIdSelected("1")).toBeTruthy(); | ||
|
||
handleSelectionFromEvent( | ||
{ ctrlKey: true } as KeyboardEvent, | ||
"2", | ||
"path", | ||
); | ||
|
||
expect(selectionStatus.value).toBe(SelectionStatus.Multiple); | ||
expect(isComponentIdSelected("1")).toBeTruthy(); | ||
expect(isComponentIdSelected("2")).toBeTruthy(); | ||
|
||
handleSelectionFromEvent( | ||
{ ctrlKey: true } as KeyboardEvent, | ||
"2", | ||
"path", | ||
); | ||
|
||
expect(selectionStatus.value).toBe(SelectionStatus.Single); | ||
expect(isComponentIdSelected("1")).toBeTruthy(); | ||
expect(isComponentIdSelected("2")).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.