Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit 5b7759a

Browse files
authored
Refactor to use new article type classes (#124)
* Seed pages_db.json with exported JSON from Cargo tables * Add pageName and pageId to article type interfaces * Add ways to construct page classes * Refactor page entry classes to article type classes * Comment out updating pages_db.json from GitHub * Refactor constructing page instances to use new class methods * Refactor checking number of results found to use totalPagesFound * Fix tests
1 parent 015f692 commit 5b7759a

File tree

15 files changed

+1721
-1736
lines changed

15 files changed

+1721
-1736
lines changed

data/pages_db.json

Lines changed: 1170 additions & 1454 deletions
Large diffs are not rendered by default.

src/common/helpers/dom-messenger.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import browser from 'webextension-polyfill';
66
import DOMMessenger from './dom-messenger';
77
import { DOMMessengerAction, IShowInPageNotificationPayload } from './dom-messenger.types';
8-
import { IPageEntry, PageEntry } from '@/database';
8+
import { IPage } from '@/models/page';
9+
import { CompanyPage } from '@/models/company';
910

1011
type MessagePayload =
1112
| { action: DOMMessengerAction.DOM_QUERY_SELECTOR_ALL; selector: string }
@@ -15,7 +16,7 @@ type MessagePayload =
1516
| { action: DOMMessengerAction.DOM_CREATE_ELEMENT; id: string; element: string; html: string }
1617
| ({
1718
action: DOMMessengerAction.DOM_SHOW_IN_PAGE_NOTIFICATION;
18-
pages: IPageEntry[];
19+
pages: IPage[];
1920
} & IShowInPageNotificationPayload);
2021

2122
type MessageListener = (
@@ -224,7 +225,15 @@ describe('DOMMessenger', () => {
224225
const sendResponse = jest.fn();
225226
const testMessage = 'Hello from test!';
226227

227-
const testPage = new PageEntry({ pageId: 1, pageTitle: 'title', popupText: 'text', category: 'category' });
228+
const testPage = CompanyPage.fromCargoExport({
229+
PageID: '1',
230+
PageName: 'title',
231+
Description: 'test company',
232+
Industry: '',
233+
ParentCompany: '',
234+
Type: '',
235+
Website: '',
236+
});
228237

229238
const pages = [testPage];
230239

@@ -251,7 +260,7 @@ describe('DOMMessenger', () => {
251260
expect(containerElement).not.toBeNull();
252261
expect(containerElement.nodeName.toLowerCase()).toBe('div');
253262
expect(containerElement.textContent).toContain(testMessage);
254-
expect(containerElement.textContent).toContain(testPage.pageTitle);
263+
expect(containerElement.textContent).toContain(testPage.pageName);
255264
expect(containerElement?.children.length).toBeGreaterThan(0);
256265
expect(containerElement.textContent).toContain(testMessage);
257266

src/common/helpers/dom-messenger.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createRoot } from 'react-dom/client';
88

99
import Inspagenotification from '@/ui/inpagenotification/Inspagenotification';
1010

11-
import { IPageEntry } from '@/database';
11+
import { IPage, Page } from '@/models/page';
1212

1313
type DOMMessagePayload =
1414
| { action: DOMMessengerAction.DOM_QUERY_SELECTOR_ALL; selector: string }
@@ -18,7 +18,7 @@ type DOMMessagePayload =
1818
| { action: DOMMessengerAction.DOM_CREATE_ELEMENT; id: string; element: string; html: string }
1919
| ({
2020
action: DOMMessengerAction.DOM_SHOW_IN_PAGE_NOTIFICATION;
21-
pages: IPageEntry[];
21+
pages: IPage[];
2222
} & IShowInPageNotificationPayload);
2323

2424
declare global {
@@ -72,13 +72,13 @@ class DOMMessenger implements IDOMMessengerInterface {
7272
});
7373
}
7474

75-
public async showInPageNotification(message: string, pages: IPageEntry[]): Promise<unknown> {
75+
public async showInPageNotification(message: string, pages: Page[]): Promise<unknown> {
7676
console.log('showInPageNotification1: ', message);
7777
console.log('showInPageNotification2: ', pages);
7878
return await this.sendMessageToCurrentTab({
7979
action: DOMMessengerAction.DOM_SHOW_IN_PAGE_NOTIFICATION,
8080
message: message,
81-
pages: pages,
81+
pages: pages.map((page) => page.toJSON()),
8282
});
8383
}
8484

@@ -262,7 +262,7 @@ class DOMMessenger implements IDOMMessengerInterface {
262262
return DOMMessenger.elementId;
263263
}
264264

265-
private static displayNotification(message: string, pages: IPageEntry[]): void {
265+
private static displayNotification(message: string, pages: IPage[]): void {
266266
const containerId = DOMMessenger.containerId();
267267

268268
/**

src/content-scanners/base-domain-scanner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export abstract class BaseDomainScanner implements IContentScannerPlugin {
2020
console.log(`${scannerId}: Attempting search: ${description}`);
2121
try {
2222
const results = searchFn();
23-
if (results.pageEntries.length > 0) {
24-
console.log(`${scannerId}: Found ${results.pageEntries.length.toString()} pages via ${description}.`);
23+
if (results.totalPagesFound > 0) {
24+
console.log(`${scannerId}: Found ${results.totalPagesFound.toString()} pages via ${description}.`);
2525
combinedResults.addPageEntries(results.pageEntries);
2626
found = true;
2727
} else {

src/content-scanners/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IContentScannerPlugin, IElementData, IScanParameters } from '@/common/services/content-scanner.types';
2-
import { CATWikiPageSearchResults, PageEntry } from '@/database';
2+
import { CATWikiPageSearchResults } from '@/database';
33
import browser from 'webextension-polyfill';
44

55
// Simple test for simple test page, e.g.
@@ -52,10 +52,10 @@ export class TestScanner implements IContentScannerPlugin {
5252

5353
if (searchResult.totalPagesFound) {
5454
console.log('Adding the CAT html: ', alertImgUrl);
55-
const pageEntry = pageResults.pageEntries[0] as PageEntry;
55+
const pageEntry = pageResults.pageEntries[0];
5656
console.dir(pageEntry);
5757
const pageUrl: string = pageEntry.url();
58-
const popupText: string = pageEntry.popupText;
58+
const popupText: string = pageEntry.description;
5959
await params.dom.createElement(
6060
divId,
6161
'p',

0 commit comments

Comments
 (0)