Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/_security-checks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Security Checks
on:
workflow_call:
permissions:
contents: read
jobs:
trivy:
name: Trivy
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_static-checks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Static Checks
on:
workflow_call:
permissions:
contents: read
jobs:
lint:
name: ESLint Check
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/_unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ jobs:

- name: Run tests
run: npm run test:coverage

- name: Send coverage to Coveralls
uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8 #v2.3.4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-istanbul": "^2.1.4",
"@vitest/coverage-istanbul": "^2.1.8",
"@vitest/expect": "^2.1.4",
"@vitest/ui": "^2.1.4",
"autoprefixer": "^10.4.20",
Expand Down
57 changes: 57 additions & 0 deletions src/hooks/__tests__/useBrowserNotification.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { renderHook } from "@testing-library/react";
import { vi } from "vitest";
import { useBrowserNotification } from "../useBrowserNotification";

describe("useBrowserNotification", () => {
let mockRequestPermission: (
deprecatedCallback?: NotificationPermissionCallback | undefined,
) => Promise<NotificationPermission>;
let mockNotification: ReturnType<typeof vi.fn>;

beforeAll(() => {
mockRequestPermission = vi.fn();
mockNotification = vi.fn();

global.Notification = vi.fn(
(title: string, options?: NotificationOptions) => {
mockNotification(title, options);
return {};
},
) as unknown as typeof Notification;

Object.defineProperty(global.Notification, "permission", {
value: "default",
writable: true,
});
global.Notification.requestPermission = mockRequestPermission;
});

it("should request the permission for notification", () => {
renderHook(() => useBrowserNotification());
expect(mockRequestPermission).toHaveBeenCalled();
});

it("should send a notification if permission is granted", () => {
Object.defineProperty(global.Notification, "permission", {
value: "granted",
});

const { result } = renderHook(() => useBrowserNotification());
result.current.sendNotification("title", { body: "body" });

expect(mockNotification).toHaveBeenCalledWith("title", {
body: "body",
});
});

it("should not send a notification if permission is denied", () => {
Object.defineProperty(global.Notification, "permission", {
value: "denied",
});

const { result } = renderHook(() => useBrowserNotification());
result.current.sendNotification("title", { body: "body" });

expect(mockNotification).not.toHaveBeenCalled();
});
});
2 changes: 0 additions & 2 deletions src/hooks/useBrowserNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ export function useBrowserNotification() {
requestPermission();
}, []);



return { sendNotification };
}
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineConfig({
},
enabled: false,
provider: "istanbul",
reporter: ["text", "json", "html", "json-summary", "lcov"],
reporter: ["text", "lcov"],
},
},
});
Loading