Skip to content

Commit df40506

Browse files
committed
refactor: test suites
Signed-off-by: Adam Setch <[email protected]>
1 parent 8bf28b0 commit df40506

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

src/main/first-run.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ import { APPLICATION } from '../shared/constants';
4343

4444
import { onFirstRunMaybe } from './first-run';
4545

46+
function configPath() {
47+
return path.join('/User/Data', 'FirstRun', APPLICATION.FIRST_RUN_FOLDER);
48+
}
49+
4650
describe('main/first-run', () => {
4751
beforeEach(() => {
4852
jest.clearAllMocks();
4953
mac = true;
5054
});
5155

52-
function configPath() {
53-
return path.join('/User/Data', 'FirstRun', APPLICATION.FIRST_RUN_FOLDER);
54-
}
55-
5656
it('creates first-run marker when not existing and returns true', async () => {
5757
existsSync.mockReturnValueOnce(false); // marker absent
5858
existsSync.mockReturnValueOnce(false); // folder absent

src/main/menu.test.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ describe('main/menu.ts', () => {
6262
/** Helper: build menu & return template (first arg passed to buildFromTemplate) */
6363
const buildAndGetTemplate = () => {
6464
menuBuilder.buildMenu();
65-
return (Menu.buildFromTemplate as jest.Mock).mock.calls.slice(
65+
return (Menu.buildFromTemplate as jest.Mock).mock.calls.at(
6666
-1,
67-
)[0][0] as TemplateItem[];
67+
)[0] as TemplateItem[];
6868
};
6969

7070
beforeEach(() => {
@@ -179,9 +179,7 @@ describe('main/menu.ts', () => {
179179

180180
it('developer submenu click actions execute expected functions', () => {
181181
const template = buildAndGetTemplate();
182-
const devEntry = template.find(
183-
(item) => item?.label === 'Developer',
184-
) as TemplateItem;
182+
const devEntry = template.find((item) => item?.label === 'Developer');
185183
expect(devEntry).toBeDefined();
186184
const submenu = devEntry.submenu;
187185
const clickByLabel = (label: string) =>
@@ -218,9 +216,7 @@ describe('main/menu.ts', () => {
218216

219217
it('developer submenu includes expected static accelerators', () => {
220218
const template = buildAndGetTemplate();
221-
const devEntry = template.find(
222-
(item) => item?.label === 'Developer',
223-
) as TemplateItem;
219+
const devEntry = template.find((item) => item?.label === 'Developer');
224220
const reloadItem = devEntry.submenu.find((i) => i.role === 'reload');
225221
expect(reloadItem?.accelerator).toBe('CommandOrControl+R');
226222
});
@@ -239,16 +235,14 @@ describe('main/menu.ts', () => {
239235
mb.buildMenu();
240236
});
241237
// Return the newest template captured
242-
return (Menu.buildFromTemplate as jest.Mock).mock.calls.slice(
238+
return (Menu.buildFromTemplate as jest.Mock).mock.calls.at(
243239
-1,
244-
)[0][0] as TemplateItem[];
240+
)[0] as TemplateItem[];
245241
};
246242

247243
it('uses mac accelerator for toggleDevTools when on macOS', () => {
248244
const template = buildTemplateWithPlatform(true);
249-
const devEntry = template.find(
250-
(i) => i?.label === 'Developer',
251-
) as TemplateItem;
245+
const devEntry = template.find((item) => item?.label === 'Developer');
252246
const toggleItem = devEntry.submenu.find(
253247
(i) => i.role === 'toggleDevTools',
254248
);
@@ -257,9 +251,7 @@ describe('main/menu.ts', () => {
257251

258252
it('uses non-mac accelerator for toggleDevTools otherwise', () => {
259253
const template = buildTemplateWithPlatform(false);
260-
const devEntry = template.find(
261-
(i) => i?.label === 'Developer',
262-
) as TemplateItem;
254+
const devEntry = template.find((item) => item?.label === 'Developer');
263255
const toggleItem = devEntry.submenu.find(
264256
(i) => i.role === 'toggleDevTools',
265257
);

src/main/updater.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jest.mock('electron', () => {
4646

4747
// Utility to emit mocked autoUpdater events
4848
const emit = (event: string, arg?: ListenerArgs) => {
49-
(listeners[event] || []).forEach((cb) => {
49+
for (const cb of listeners[event] || []) {
5050
cb(arg);
51-
});
51+
}
5252
};
5353

5454
// Re-import autoUpdater after mocking

src/renderer/components/avatars/AvatarWithFallback.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => {
4848
renderWithAppContext(<AvatarWithFallback {...props} />);
4949

5050
// Find the avatar element by its alt text
51-
const avatar = screen.getByAltText('gitify-app') as HTMLImageElement;
51+
const avatar = screen.getByAltText('gitify-app');
5252

5353
// Simulate image load error (wrapped in act via fireEvent)
5454
fireEvent.error(avatar);
@@ -60,7 +60,7 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => {
6060
renderWithAppContext(<AvatarWithFallback {...props} userType={'Bot'} />);
6161

6262
// Find the avatar element by its alt text
63-
const avatar = screen.getByAltText('gitify-app') as HTMLImageElement;
63+
const avatar = screen.getByAltText('gitify-app');
6464

6565
// Simulate image load error (wrapped in act via fireEvent)
6666
fireEvent.error(avatar);

0 commit comments

Comments
 (0)