-
Notifications
You must be signed in to change notification settings - Fork 0
feat(phase5): Cluster C — Broadcast + Intelligence #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6471065
feat(prc1): maintain hasFcmToken flag on token registration and inval…
claude 125ca22
test(prc1): cover hasFcmToken clearing on all-invalid and preservatio…
claude d839b30
feat(prc2): add followUpConsent to report_sms_consent materialization
claude 7d2c7b0
feat(prc3): expand massAlertRequestDoc status enum; add rules for ndr…
claude b9001b2
feat(c1): add mass_alert SMS template + renderBroadcastTemplate + enq…
claude 717ec99
feat(c1): sendMassAlertFcm — batched FCM multicast with 500-token bat…
claude 36bc947
feat(c1): massAlertReachPlanPreview + sendMassAlert + escalation + fo…
claude 31a8a39
fix(c1): use .count().get() aggregate in massAlertReachPlanPreviewCore
claude 2860f0a
fix(c1): add canActOnScope to escalation, strengthen FCM test asserti…
claude d76cf42
feat(c1): MassAlertModal — reach preview, direct send, NDRRMC escalat…
claude a3ce484
feat(shared-data): add CAMARINES_NORTE_MUNICIPALITY_IDS for analytics…
claude 67382da
feat(c2): analyticsSnapshotWriter — daily Firestore count() aggregate…
claude 002895a
feat(c2): AnalyticsDashboardPage — live count + 7-day SVG trend chart…
claude 663da6e
chore: Cluster C + PRE-C verification gate — all tests pass, lint+typ…
claude 1e183f7
docs: update progress + learnings for Phase 5 Cluster C completion
claude 7bd9301
fix(ci): add `as any` cast to vi.spyOn where mocks in mass-alert test…
claude 71d6b46
fix(backend): address PR #66 review comments on mass-alert, fcm, sms
claude b46b5fb
fix(frontend): address PR #66 review comments on admin-desktop
claude 30cbb5d
test: add coverage for PR #66 review fixes
claude 946abda
fix(rules+templates): address PR #66 security and encoding comments
claude 23e7a3d
docs: fix typo in learnings.md per PR #66 nitpick
claude ca3acd2
fix(rules+templates): address PR #66 security and encoding comments
claude 3b7ccae
fix: address PR #66 code review comments
claude 1dfb206
fix: address PR #66 second round review comments
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
apps/admin-desktop/src/__tests__/analytics-dashboard.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
|
|
||
| vi.mock('../app/firebase', () => ({ db: {} })) | ||
| vi.mock('@bantayog/shared-ui', () => ({ | ||
| useAuth: () => ({ | ||
| claims: { municipalityId: 'daet', role: 'municipal_admin' }, | ||
| signOut: vi.fn(), | ||
| }), | ||
| })) | ||
|
|
||
| const { mockGetCountFromServer, mockGetDocs, mockGetDoc, mockDoc, mockWhere } = vi.hoisted(() => ({ | ||
| mockGetCountFromServer: vi.fn(), | ||
| mockGetDocs: vi.fn(), | ||
| mockGetDoc: vi.fn(), | ||
| mockDoc: vi.fn(() => ({})), | ||
| mockWhere: vi.fn(() => ({})), | ||
| })) | ||
|
|
||
| vi.mock('firebase/firestore', () => ({ | ||
| getFirestore: vi.fn(() => ({})), | ||
| getCountFromServer: mockGetCountFromServer, | ||
| collection: vi.fn(() => ({})), | ||
| query: vi.fn(() => ({})), | ||
| where: mockWhere, | ||
| orderBy: vi.fn(() => ({})), | ||
| limit: vi.fn(() => ({})), | ||
| getDocs: mockGetDocs, | ||
| getDoc: mockGetDoc, | ||
| doc: mockDoc, | ||
| })) | ||
|
|
||
| import { AnalyticsDashboardPage } from '../pages/AnalyticsDashboardPage' | ||
|
|
||
| function wrapper({ children }: { children: React.ReactNode }) { | ||
| const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } }) | ||
| return <QueryClientProvider client={qc}>{children}</QueryClientProvider> | ||
| } | ||
|
|
||
| describe('AnalyticsDashboardPage', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockGetCountFromServer.mockResolvedValue({ data: () => ({ count: 42 }) }) | ||
| mockGetDocs.mockResolvedValue({ docs: [] }) | ||
| mockGetDoc.mockResolvedValue({ exists: () => false }) | ||
| mockWhere.mockReturnValue({}) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it('renders the live active-incidents count', async () => { | ||
| render(<AnalyticsDashboardPage />, { wrapper }) | ||
| expect(await screen.findByText('42')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows a loading state while analytics count is fetching', () => { | ||
| mockGetCountFromServer.mockImplementationOnce( | ||
| () => | ||
| new Promise<void>(() => { | ||
| /* never resolves */ | ||
| }), | ||
| ) | ||
| render(<AnalyticsDashboardPage />, { wrapper }) | ||
| expect(screen.getByText(/loading/i)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows trend loading state while snapshot data is fetching', async () => { | ||
| mockGetDocs.mockImplementationOnce( | ||
| () => | ||
| new Promise(() => { | ||
| /* never resolves */ | ||
| }), | ||
| ) | ||
| render(<AnalyticsDashboardPage />, { wrapper }) | ||
| expect(await screen.findByText('Loading trend…')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("scopes data to the caller's municipalityId for muni admins", async () => { | ||
| render(<AnalyticsDashboardPage />, { wrapper }) | ||
| expect(await screen.findByText(/daet/i)).toBeInTheDocument() | ||
| // Verify the live-count query included the municipalityId filter. | ||
| const hasMuniFilter = (mockWhere.mock.calls as unknown[][]).some( | ||
| (args) => args[0] === 'municipalityId' && args[1] === '==' && args[2] === 'daet', | ||
| ) | ||
| expect(hasMuniFilter).toBe(true) | ||
| }) | ||
|
|
||
| it('renders a trend chart when snapshots are present', async () => { | ||
| mockGetDocs.mockResolvedValueOnce({ | ||
| docs: [ | ||
| { | ||
| id: '2026-04-20', | ||
| data: () => ({ | ||
| reportsByStatus: { verified: 5, closed: 2 }, | ||
| }), | ||
| }, | ||
| ], | ||
| }) | ||
| mockGetDoc.mockResolvedValueOnce({ | ||
| exists: () => true, | ||
| data: () => ({ reportsByStatus: { verified: 5, closed: 2 } }), | ||
| }) | ||
| render(<AnalyticsDashboardPage />, { wrapper }) | ||
| expect(await screen.findByLabelText('7-day trend chart')).toBeInTheDocument() | ||
| expect(screen.getByLabelText(/2026-04-20: 7 reports/)).toBeInTheDocument() | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
143 changes: 143 additions & 0 deletions
143
apps/admin-desktop/src/__tests__/mass-alert-modal.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
| import { render, screen } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
|
|
||
| vi.mock('../app/firebase', () => ({ db: {} })) | ||
|
|
||
| const mockPreview = vi.hoisted(() => vi.fn()) | ||
| const mockSend = vi.hoisted(() => vi.fn()) | ||
| const mockEscalate = vi.hoisted(() => vi.fn()) | ||
|
|
||
| vi.mock('../services/callables', () => ({ | ||
| callables: { | ||
| massAlertReachPlanPreview: mockPreview, | ||
| sendMassAlert: mockSend, | ||
| requestMassAlertEscalation: mockEscalate, | ||
| }, | ||
| })) | ||
|
|
||
| import { MassAlertModal } from '../pages/MassAlertModal' | ||
|
|
||
| const DIRECT_PLAN = { | ||
| route: 'direct', | ||
| fcmCount: 200, | ||
| smsCount: 150, | ||
| segmentCount: 1, | ||
| unicodeWarning: false, | ||
| } | ||
| const NDRRMC_PLAN = { | ||
| route: 'ndrrmc_escalation', | ||
| fcmCount: 6000, | ||
| smsCount: 2000, | ||
| segmentCount: 1, | ||
| unicodeWarning: false, | ||
| } | ||
|
|
||
| describe('MassAlertModal', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockPreview.mockResolvedValue(DIRECT_PLAN) | ||
| mockSend.mockResolvedValue({ requestId: 'req-1' }) | ||
| mockEscalate.mockResolvedValue({ requestId: 'req-2' }) | ||
| }) | ||
|
|
||
| it('shows GSM-7 indicator and correct segment count for ASCII message', async () => { | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'ALERT: Typhoon warning') | ||
| expect(screen.getByText(/GSM-7/i)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows UCS-2 warning when message contains unicode characters', async () => { | ||
| const user = userEvent.setup() | ||
| mockPreview.mockResolvedValue({ ...DIRECT_PLAN, unicodeWarning: true }) | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Alerto sa ñ lugar') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| expect(await screen.findByText(/⚠ UCS-2 \(multi-byte\)/i)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows Preview Reach button', () => { | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| expect(screen.getByRole('button', { name: /preview reach/i })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows fcmCount and smsCount after preview loads', async () => { | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test alert') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| expect(await screen.findByText(/200/)).toBeInTheDocument() | ||
| expect(screen.getByText(/150/)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows Direct Send badge when route is direct', async () => { | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| expect(await screen.findByText(/direct/i)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows NDRRMC Escalation badge when route is ndrrmc_escalation', async () => { | ||
| mockPreview.mockResolvedValue(NDRRMC_PLAN) | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| expect(await screen.findByText(/NDRRMC escalation required/i)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('disables Send button when route is ndrrmc_escalation', async () => { | ||
| mockPreview.mockResolvedValue(NDRRMC_PLAN) | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| await screen.findByText(/NDRRMC escalation required/i) | ||
| expect(screen.getByRole('button', { name: /^send alert$/i })).toBeDisabled() | ||
| }) | ||
|
|
||
| it('shows Request NDRRMC Escalation button when route is ndrrmc_escalation', async () => { | ||
| mockPreview.mockResolvedValue(NDRRMC_PLAN) | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| expect( | ||
| await screen.findByRole('button', { name: /request ndrrmc escalation/i }), | ||
| ).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('calls sendMassAlert on Send click (direct path)', async () => { | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test alert') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| await screen.findByText(/200/) | ||
| await user.click(screen.getByRole('button', { name: /^send alert$/i })) | ||
| expect(mockSend).toHaveBeenCalledTimes(1) | ||
| expect(mockSend).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| message: 'Test alert', | ||
| targetScope: expect.objectContaining({ municipalityIds: ['daet'] }), | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| it('calls requestMassAlertEscalation on escalation CTA click', async () => { | ||
| mockPreview.mockResolvedValue(NDRRMC_PLAN) | ||
| const user = userEvent.setup() | ||
| render(<MassAlertModal municipalityId="daet" onClose={vi.fn()} />) | ||
| await user.type(screen.getByLabelText(/message/i), 'Test') | ||
| await user.click(screen.getByRole('button', { name: /preview reach/i })) | ||
| await user.click(await screen.findByRole('button', { name: /request ndrrmc escalation/i })) | ||
| expect(mockEscalate).toHaveBeenCalledTimes(1) | ||
| expect(mockEscalate).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| message: 'Test', | ||
| targetScope: expect.objectContaining({ municipalityIds: ['daet'] }), | ||
| }), | ||
| ) | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.