Skip to content

Commit 1847794

Browse files
chore: refacto content
1 parent acf4355 commit 1847794

File tree

16 files changed

+1536
-777
lines changed

16 files changed

+1536
-777
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"content_scripts": [{
4242
"matches": ["<all_urls>"],
4343
"js": [
44-
"src/content.js"
44+
"src/content.ts"
4545
]
4646
}],
4747
"permissions": [

src/background/__tests__/TabRulesService.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ vi.mock('../../common/storage', () => ({
4343

4444
// Mock helpers module
4545
vi.mock('../../common/helpers', () => ({
46-
_processUrlFragment: vi.fn((fragment, url) => url),
46+
_processUrlFragment: vi.fn((_fragment, url) => url),
4747
}));
4848

4949
import { _getRuleFromUrl, _shouldSkipUrl, _getDefaultRule, _setStorage } from '../../common/storage';
@@ -160,7 +160,16 @@ describe('TabRulesService', () => {
160160
name: 'New Title (example.com)',
161161
detection: 'CONTAINS',
162162
url_fragment: 'https://example.com',
163-
tab: { title: 'New Title' },
163+
tab: {
164+
title: 'New Title',
165+
icon: null,
166+
muted: false,
167+
pinned: false,
168+
protected: false,
169+
unique: false,
170+
title_matcher: null,
171+
url_matcher: null,
172+
},
164173
is_enabled: true,
165174
};
166175

src/background/__tests__/WindowService.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('WindowService', () => {
2828
const singleWindow = {
2929
id: 1,
3030
focused: true,
31-
type: 'normal' as chrome.windows.WindowType,
31+
type: 'normal' as 'normal',
3232
tabs: [{ id: 1 }],
3333
};
3434

@@ -44,14 +44,14 @@ describe('WindowService', () => {
4444
const focusedWindow = {
4545
id: 1,
4646
focused: true,
47-
type: 'normal' as chrome.windows.WindowType,
47+
type: 'normal' as 'normal',
4848
tabs: [{ id: 1 }, { id: 2 }],
4949
};
5050

5151
const otherWindow = {
5252
id: 2,
5353
focused: false,
54-
type: 'normal' as chrome.windows.WindowType,
54+
type: 'normal' as 'normal',
5555
tabs: [{ id: 3 }, { id: 4 }],
5656
};
5757

@@ -72,14 +72,14 @@ describe('WindowService', () => {
7272
const normalWindow = {
7373
id: 1,
7474
focused: true,
75-
type: 'normal' as chrome.windows.WindowType,
75+
type: 'normal' as 'normal',
7676
tabs: [{ id: 1 }],
7777
};
7878

7979
const popupWindow = {
8080
id: 2,
8181
focused: false,
82-
type: 'popup' as chrome.windows.WindowType,
82+
type: 'popup' as 'popup',
8383
tabs: [{ id: 2 }],
8484
};
8585

@@ -96,14 +96,14 @@ describe('WindowService', () => {
9696
const window1 = {
9797
id: 1,
9898
focused: false,
99-
type: 'normal' as chrome.windows.WindowType,
99+
type: 'normal' as 'normal',
100100
tabs: [{ id: 1 }],
101101
};
102102

103103
const window2 = {
104104
id: 2,
105105
focused: false,
106-
type: 'normal' as chrome.windows.WindowType,
106+
type: 'normal' as 'normal',
107107
tabs: [{ id: 2 }],
108108
};
109109

@@ -124,14 +124,14 @@ describe('WindowService', () => {
124124
const window1 = {
125125
id: 1,
126126
focused: true,
127-
type: 'normal' as chrome.windows.WindowType,
127+
type: 'normal' as 'normal',
128128
tabs: [{ id: 1 }],
129129
};
130130

131131
const window2 = {
132132
id: 2,
133133
focused: false,
134-
type: 'normal' as chrome.windows.WindowType,
134+
type: 'normal' as 'normal',
135135
tabs: [],
136136
};
137137

@@ -148,14 +148,14 @@ describe('WindowService', () => {
148148
const window1 = {
149149
id: 1,
150150
focused: true,
151-
type: 'normal' as chrome.windows.WindowType,
151+
type: 'normal' as 'normal',
152152
tabs: [{ id: 1 }],
153153
};
154154

155155
const window2 = {
156156
id: 2,
157157
focused: false,
158-
type: 'normal' as chrome.windows.WindowType,
158+
type: 'normal' as 'normal',
159159
tabs: [{ id: undefined }, { id: 2 }],
160160
};
161161

@@ -176,14 +176,14 @@ describe('WindowService', () => {
176176
const window1 = {
177177
id: 1,
178178
focused: true,
179-
type: 'normal' as chrome.windows.WindowType,
179+
type: 'normal' as 'normal',
180180
tabs: [{ id: 1 }],
181181
};
182182

183183
const window2 = {
184184
id: 2,
185185
focused: false,
186-
type: 'normal' as chrome.windows.WindowType,
186+
type: 'normal' as 'normal',
187187
tabs: [{ id: 2 }],
188188
};
189189

src/components/options/center/sections/TabRules/EmptyRules.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { beforeEach, describe, expect, it } from 'vitest';
2-
import { processTitle } from '../../../../../content.js';
2+
import { TitleService } from '../../../../../content/TitleService';
3+
import { RegexService } from '../../../../../content/RegexService';
34

45
describe('Sample Rules', () => {
6+
let titleService;
7+
58
beforeEach(() => {
69
document.body.innerHTML = '';
10+
const regexService = new RegexService();
11+
titleService = new TitleService(regexService);
712
});
813

14+
// Helper function to match the old processTitle API
15+
const processTitle = (url, title, rule) => {
16+
return titleService.processTitle(url, title, rule);
17+
};
18+
919
describe('Gmail Rule', () => {
1020
it('should preserve title for Gmail', () => {
1121
const rule = {

0 commit comments

Comments
 (0)