Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion client/src/components/Form/Elements/FormDirectory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function init(wrapper, data) {
expect(filesDialogComponent.exists()).toBe(true);
filesDialogComponent.vm.callback({ url: data.url });
// HACK: URL implementation in test environment is not the same as global node
wrapper.vm.pathChunks = data.pathChunks;
wrapper.vm.pathChunks = [...data.pathChunks];
await flushPromises();
await validateLatestEmittedPath(wrapper, data.url);
}
Expand Down Expand Up @@ -175,4 +175,20 @@ describe("DirectoryPathEditableBreadcrumb", () => {
// retain special characters in the url
await init(wrapper, testingDataWithSpecialChars);
});

it("should save on blur", async () => {
await init(wrapper, testingData);
// enter a new path chunk
const input = wrapper.find("#path-input-breadcrumb");
await input.setValue(validPath);
expect(input.element.value).toBe(validPath);

await input.trigger("blur");
await flushPromises();

expect(spyOnAddPath).toHaveBeenCalled();
expect(input.element.value).toBe("");
expect(wrapper.findAll("li.breadcrumb-item").length).toBe(testingData.expectedNumberOfPaths + 1);
await validateLatestEmittedPath(wrapper, `${testingData.url}/${validPath}`);
});
});
20 changes: 16 additions & 4 deletions client/src/components/Form/Elements/FormDirectory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
trim
@keyup.enter="addPath"
@keydown.191.capture.prevent.stop="addPath"
@keydown.8.capture="removeLastPath" />
@keydown.8.capture="removeLastPath"
@blur="handleBlur" />
</b-breadcrumb-item>
</b-breadcrumb>

Expand Down Expand Up @@ -139,12 +140,23 @@ export default {
},
addPath({ key }) {
if ((key === "Enter" || key === "/") && this.isValidName) {
const newFolder = this.currentDirectoryName;
this.pathChunks.push({ pathChunk: newFolder, editable: true });
this.currentDirectoryName = "";
this.addDirectoryToPath();
}
},
handleBlur() {
if (this.currentDirectoryName && this.isValidName) {
this.addDirectoryToPath();
} else {
// If the input was touched let's propagate the change either way.
this.updateURL();
}
},
addDirectoryToPath() {
const newFolder = this.currentDirectoryName;
this.pathChunks.push({ pathChunk: newFolder, editable: true });
this.currentDirectoryName = "";
this.updateURL();
},
updateURL(isReset = false) {
let url = undefined;
if (!isReset) {
Expand Down
Loading