mengw15 commented on code in PR #6537:
URL: https://github.com/apache/texera/pull/6537#discussion_r3609565765


##########
frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts:
##########
@@ -54,4 +55,95 @@ describe("UserDatasetFileRendererComponent", () => {
     const result = component.isPreviewSupported(unsupportedMimeType);
     expect(result).toBe(false);
   });
+
+  describe("reloadFileContent", () => {
+    it("flags an unsupported file type without hitting the backend", () => {
+      component.filePath = "archive.bin"; // -> OCTET_STREAM -> unsupported
+
+      component.reloadFileContent();
+
+      expect(component.isFileTypePreviewUnsupported).toBe(true);
+    });

Review Comment:
   Fixed — the test now sets `did`/`dvid` and asserts 
`retrieveDatasetVersionSingleFile` was not called, so it fails if the 
unsupported-type early-return is removed (verified).



##########
frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts:
##########
@@ -54,4 +55,95 @@ describe("UserDatasetFileRendererComponent", () => {
     const result = component.isPreviewSupported(unsupportedMimeType);
     expect(result).toBe(false);
   });
+
+  describe("reloadFileContent", () => {
+    it("flags an unsupported file type without hitting the backend", () => {
+      component.filePath = "archive.bin"; // -> OCTET_STREAM -> unsupported
+
+      component.reloadFileContent();
+
+      expect(component.isFileTypePreviewUnsupported).toBe(true);
+    });
+
+    it("flags an oversized file before loading it", () => {
+      component.filePath = "notes.txt"; // TXT limit is 1 MB
+      component.fileSize = 5 * 1024 * 1024;
+
+      component.reloadFileContent();
+
+      expect(component.isFileSizeUnloadable).toBe(true);
+    });

Review Comment:
   Fixed — same treatment: `did`/`dvid` are set and the service is asserted 
un-called, so it is the oversized early-return that the test verifies.



##########
frontend/src/app/dashboard/component/user/user-dataset/user-dataset-explorer/user-dataset-file-renderer/user-dataset-file-renderer.component.spec.ts:
##########
@@ -54,4 +55,95 @@ describe("UserDatasetFileRendererComponent", () => {
     const result = component.isPreviewSupported(unsupportedMimeType);
     expect(result).toBe(false);
   });
+
+  describe("reloadFileContent", () => {
+    it("flags an unsupported file type without hitting the backend", () => {
+      component.filePath = "archive.bin"; // -> OCTET_STREAM -> unsupported
+
+      component.reloadFileContent();
+
+      expect(component.isFileTypePreviewUnsupported).toBe(true);
+    });
+
+    it("flags an oversized file before loading it", () => {
+      component.filePath = "notes.txt"; // TXT limit is 1 MB
+      component.fileSize = 5 * 1024 * 1024;
+
+      component.reloadFileContent();
+
+      expect(component.isFileSizeUnloadable).toBe(true);
+    });
+
+    it("retrieves a supported file and switches on the matching display", () 
=> {
+      const datasetService = TestBed.inject(DatasetService);
+      const blob = new Blob(["hello"], { type: "text/plain" });
+      const spy = vi.spyOn(datasetService, 
"retrieveDatasetVersionSingleFile").mockReturnValue(of(blob));
+      component.did = 1;
+      component.dvid = 2;
+      component.filePath = "notes.txt";
+      component.isLogin = true;
+      component.fileSize = 100;
+
+      component.reloadFileContent();
+
+      expect(spy).toHaveBeenCalledWith("notes.txt", true);
+      expect(component.displayPlainText).toBe(true);
+      expect(component.isLoading).toBe(false);
+    });
+  });
+
+  describe("error handlers", () => {
+    it("onFileLoadingError sets the loading-error state and clears displays", 
() => {
+      component.displayCSV = true;
+
+      component.onFileLoadingError();
+
+      expect(component.isFileLoadingError).toBe(true);
+      expect(component.displayCSV).toBe(false);
+    });
+
+    it("onFileSizeNotLoadable sets the size-unloadable state", () => {
+      component.onFileSizeNotLoadable();
+
+      expect(component.isFileSizeUnloadable).toBe(true);
+    });
+
+    it("onFileTypePreviewUnsupported sets the unsupported-type state", () => {
+      component.onFileTypePreviewUnsupported();
+
+      expect(component.isFileTypePreviewUnsupported).toBe(true);
+    });
+  });
+
+  describe("display toggles", () => {
+    it("toggleImageModal flips showImageModal", () => {
+      expect(component.showImageModal).toBe(false);
+
+      component.toggleImageModal();
+      expect(component.showImageModal).toBe(true);
+
+      component.toggleImageModal();
+      expect(component.showImageModal).toBe(false);
+    });
+
+    it("turnOffAllDisplay resets every display and error flag", () => {
+      component.displayCSV = true;
+      component.displayImage = true;
+      component.displayJson = true;
+      component.isLoading = true;
+      component.isFileLoadingError = true;
+      component.isFileSizeUnloadable = true;
+      component.isFileTypePreviewUnsupported = true;
+
+      component.turnOffAllDisplay();
+
+      expect(component.displayCSV).toBe(false);
+      expect(component.displayImage).toBe(false);
+      expect(component.displayJson).toBe(false);
+      expect(component.isLoading).toBe(false);
+      expect(component.isFileLoadingError).toBe(false);
+      expect(component.isFileSizeUnloadable).toBe(false);
+      expect(component.isFileTypePreviewUnsupported).toBe(false);
+    });

Review Comment:
   Fixed — the test now sets and asserts all eight display flags (added 
`displayXlsx` / `displayPlainText` / `displayMarkdown` / `displayMP4` / 
`displayMP3`) alongside the error flags.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to