Skip to content

Build your personal knowledge base with Trilium Notes

fix(desktop): upload the watched file whatever the message says

Elian Doran40f5860488ba
diff --git a/apps/client/src/widgets/watched_file_update_status.spec.ts b/apps/client/src/widgets/watched_file_update_status.spec.ts
new file mode 100644
index 0000000000..4a0241a731
--- /dev/null
+++ b/apps/client/src/widgets/watched_file_update_status.spec.ts
@@ -0,0 +1,33 @@
+import { describe, expect, it, vi } from "vitest";
+
+import fileWatcher from "../services/file_watcher.js";
+import server from "../services/server.js";
+import WatchedFileUpdateStatusWidget from "./watched_file_update_status.js";
+
+describe("WatchedFileUpdateStatusWidget", () => {
+ it("uploads the file recorded by the watcher, whatever the message renders", async () => {
+ vi.spyOn(fileWatcher, "getFileModificationStatus").mockReturnValue({
+ entityType: "notes",
+ entityId: "n1",
+ lastModifiedMs: 0,
+ filePath: "/tmp/tmp-1-abc-New note.html"
+ });
+ const uploaded = vi.spyOn(fileWatcher, "fileModificationUploaded");
+ const post = vi.spyOn(server, "post").mockResolvedValue(undefined);
+
+ const widget = new WatchedFileUpdateStatusWidget();
+ vi.spyOn(widget, "getEntity").mockReturnValue({ entityType: "notes", entityId: "n1" });
+ vi.spyOn(widget, "refresh").mockResolvedValue();
+ widget.render();
+ widget.$widget.find(".file-path").remove();
+
+ const button = widget.$widget.find(".file-upload-button");
+ expect(button).toHaveLength(1);
+ button.trigger("click");
+
+ await vi.waitFor(() => expect(uploaded).toHaveBeenCalledWith("notes", "n1"));
+ expect(post).toHaveBeenCalledWith("notes/n1/upload-modified-file", {
+ filePath: "/tmp/tmp-1-abc-New note.html"
+ });
+ });
+});
diff --git a/apps/client/src/widgets/watched_file_update_status.ts b/apps/client/src/widgets/watched_file_update_status.ts
index b5c269680b..3bb2f5091f 100644
--- a/apps/client/src/widgets/watched_file_update_status.ts
+++ b/apps/client/src/widgets/watched_file_update_status.ts
@@ -49,14 +49,13 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidge
this.$fileUploadButton.on("click", async () => {
const { entityType, entityId } = this.getEntity();
+ if (!entityType || !entityId) return;
await server.post(`${entityType}/${entityId}/upload-modified-file`, {
- filePath: this.$filePath.text()
+ filePath: fileWatcher.getFileModificationStatus(entityType, entityId).filePath
});
- if (entityType && entityId) {
- fileWatcher.fileModificationUploaded(entityType, entityId);
- }
+ fileWatcher.fileModificationUploaded(entityType, entityId);
this.refresh();
});
@@ -103,7 +102,6 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidge
}
openedFileUpdatedEvent(data: EventData<"openedFileUpdated">) {
- console.log(data);
const { entityType, entityId } = this.getEntity();
if (data.entityType === entityType && data.entityId === entityId) {