From dd24440b73c186ea45950650a9e53b4a58cfdd5a Mon Sep 17 00:00:00 2001 From: Saul Ifshin <97627272+saul1310@users.noreply.github.com> Date: Tue, 26 May 2026 15:28:17 -0700 Subject: [PATCH] test(frontend): cover MIME precedence in non-PDF type detection (#6438) # Description of Changes --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [x] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [x] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [x] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [x] I have run `task check` to verify linters, typechecks, and tests pass - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#7-testing) for more details. --- frontend/editor/src/core/utils/fileUtils.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/editor/src/core/utils/fileUtils.test.ts b/frontend/editor/src/core/utils/fileUtils.test.ts index 8b1a1afd9..fcdb53926 100644 --- a/frontend/editor/src/core/utils/fileUtils.test.ts +++ b/frontend/editor/src/core/utils/fileUtils.test.ts @@ -3,6 +3,7 @@ import { isPdfFile, detectFileExtension, formatFileSize, + detectNonPdfFileType, } from "@app/utils/fileUtils"; describe("fileUtils", () => { @@ -94,4 +95,18 @@ describe("fileUtils", () => { expect(formatFileSize(1024 * 1024 * 1024)).toBe("1 GB"); }); }); + + describe("detectNonPdfFileType", () => { + it("should prioritize MIME type over extension when they conflict", () => { + expect( + detectNonPdfFileType({ + name: "financial-summary.pdf", + type: "text/csv", + }), + ).toBe("csv"); + expect( + detectNonPdfFileType({ name: "diagram.png", type: "application/json" }), + ).toBe("json"); + }); + }); });