Skip to content

Commit

Permalink
Merge pull request #6 from navapbc/george/test-blur-detector
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals authored Feb 23, 2024
2 parents a755261 + 9724c8d commit b04a13d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions app/tests/utils/blur-detector.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
afterEach,
beforeEach,
describe,
expect,
it,
jest,
} from "@jest/globals";

import BlurryDetector, {
BlurryDetectorReport,
} from "../../src/utils/blur-detector";

// Adjust the import path accordingly

describe("./src/utils/blur-detector.ts", () => {
let blurryDetector: BlurryDetector;

beforeEach(() => {
blurryDetector = new BlurryDetector(); // Using the default threshold of 300
});

afterEach(() => {
jest.clearAllMocks();
});

it("should detect a clear image", async () => {
// Mock computeLaplacianVariance to return a high variance indicating a clear image
blurryDetector.computeLaplacianVariance = jest.fn(() => {
return Promise.resolve(450);
});

const result: BlurryDetectorReport = await blurryDetector.analyse(
"path/to/clear/image.jpg"
);

expect(result).toEqual({
imagePath: "path/to/clear/image.jpg",
isBlurry: false,
score: 450,
});
});

it("should detect a blurry image", async () => {
// Mock computeLaplacianVariance to return a low variance indicating a blurry image
blurryDetector.computeLaplacianVariance = jest.fn(() => {
return Promise.resolve(220);
});

const result: BlurryDetectorReport = await blurryDetector.analyse(
"path/to/blurry/image.jpg"
);

expect(result).toEqual({
imagePath: "path/to/blurry/image.jpg",
isBlurry: true,
score: 220,
});
});
});

0 comments on commit b04a13d

Please sign in to comment.