Skip to content

Commit

Permalink
added unit test for the change
Browse files Browse the repository at this point in the history
  • Loading branch information
Junjiequan committed Nov 20, 2024
1 parent 9cbb738 commit 7cee42d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/shared/services/attachment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ describe("AttachmentService", () => {
});

it("should return null for non-string input", () => {
const mimeType = service.base64MimeType(null as any);
const mimeType = service.base64MimeType(null);
expect(mimeType).toBeNull();
});
});

describe("getImageUrl", () => {
it("should return the pdf icon if the file is pdf", () => {
const encoded = "data:application/pdf;base64,SGVsbG8sIFdvcmxkIQ==";
const imageUrl = service.getImageUrl(encoded);
expect(imageUrl).toBe("assets/images/pdf-icon.svg");
});

it("should return the encoded string if the file is not pdf", () => {
const encoded = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA";
const imageUrl = service.getImageUrl(encoded);
expect(imageUrl).toBe(encoded);
});
});

describe("openAttachment", () => {
it("should open a new window with the correct object URL", () => {
const encoded = "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==";
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/services/thumbnail.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ThumbnailService } from "./thumbnail.service";
import { selectDatasetsPerPage } from "state-management/selectors/datasets.selectors";
import { MockStore, provideMockStore } from "@ngrx/store/testing";
import { of, throwError } from "rxjs";
import { AttachmentService } from "./attachment.service";

describe("ThumbnailService", () => {
let service: ThumbnailService;
Expand All @@ -27,6 +28,9 @@ describe("ThumbnailService", () => {
provide: AppConfigService,
useValue: { getConfig },
},
{
provide: AttachmentService,
},
provideMockStore({
selectors: [
{
Expand Down

0 comments on commit 7cee42d

Please sign in to comment.