Skip to content

Commit 3e87652

Browse files
committed
test: Add disclaimer banner tests and fix glossary test mock
1 parent b07709c commit 3e87652

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

CompendiumUI/disclaimer.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
/**
6+
* Tests for Disclaimer Banner
7+
* Verifies key elements and content of the disclaimer banner.
8+
*/
9+
describe('Disclaimer Banner Support', () => {
10+
beforeEach(() => {
11+
// Load the actual index.html content
12+
const htmlPath = path.resolve(__dirname, 'index.html');
13+
const htmlContent = fs.readFileSync(htmlPath, 'utf-8');
14+
document.body.innerHTML = htmlContent;
15+
});
16+
17+
afterEach(() => {
18+
document.body.innerHTML = '';
19+
});
20+
21+
it('should display the banner', () => {
22+
const banner = document.getElementById('disclaimer-banner');
23+
expect(banner).not.toBeNull();
24+
expect(banner?.getAttribute('role')).toBe('banner');
25+
});
26+
27+
it('should contain the correct disclaimer text', () => {
28+
const textWrapper = document.querySelector('.disclaimer-banner__text-wrapper');
29+
expect(textWrapper).not.toBeNull();
30+
expect(textWrapper?.textContent).toContain('This is not official government information');
31+
expect(textWrapper?.textContent).toContain('Prototype by Ad Hoc');
32+
});
33+
34+
it('should have a link to the About page', () => {
35+
const aboutLink = document.querySelector('.disclaimer-banner__links a[href="/about.html"]');
36+
expect(aboutLink).not.toBeNull();
37+
});
38+
39+
it('should have a link to the official copyright.gov site', () => {
40+
const officialLink = document.querySelector('.disclaimer-banner__textWrapper a[href="https://www.copyright.gov/comp3/"]');
41+
// The class might be slightly different in structure, check specific anchor
42+
const links = Array.from(document.querySelectorAll('#disclaimer-banner a'));
43+
const hasOfficialLink = links.some(link => link.getAttribute('href') === 'https://www.copyright.gov/comp3/');
44+
expect(hasOfficialLink).toBe(true);
45+
});
46+
47+
it('should have the Ad Hoc logo', () => {
48+
const logo = document.querySelector('.disclaimer-banner__logo img');
49+
expect(logo).not.toBeNull();
50+
expect(logo?.getAttribute('alt')).toBe('Ad Hoc');
51+
});
52+
});

CompendiumUI/glossary.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22

33
describe('Glossary Tooltip Behavior', () => {
44
beforeEach(() => {
5+
// Mock Algolia to prevent "appId is missing" error
6+
vi.mock('algoliasearch/lite', () => ({
7+
default: vi.fn(() => ({
8+
search: vi.fn(),
9+
})),
10+
liteClient: vi.fn(() => ({
11+
search: vi.fn(),
12+
})),
13+
}));
14+
515
vi.resetModules();
616
document.body.innerHTML = `
717
<div id="chapter-content">
@@ -35,6 +45,7 @@ describe('Glossary Tooltip Behavior', () => {
3545

3646
afterEach(() => {
3747
vi.restoreAllMocks();
48+
vi.unstubAllGlobals();
3849
});
3950

4051
it('should close the tooltip when a glossary link is clicked', async () => {

0 commit comments

Comments
 (0)