Skip to content

Commit d76a9a2

Browse files
committed
test: update tests to support updated deps
1 parent 3c66cc6 commit d76a9a2

33 files changed

+1025
-986
lines changed

apps/electron/test/ui/electron.spec.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import addCommonUiTests, {
44
useMockDefinitions,
55
useMockRhymes,
66
} from '@lyricistant/common-ui-tests';
7-
import { deleteAsync as del } from 'del';
87
import { _electron as electron, ElectronApplication, Page } from 'playwright';
9-
import { getDocument, getQueriesForElement } from 'playwright-testing-library';
108
import waitForExpect from 'wait-for-expect';
9+
import * as fs from 'node:fs';
1110

1211
const viewports = [
13-
{ label: 'default', isSmallLayout: false },
14-
{ width: 500, height: 500, label: '500 x 500', isSmallLayout: true },
15-
{ width: 1200, height: 1200, label: '1200 x 1200', isSmallLayout: false },
12+
{ label: 'default' },
13+
{ width: 500, height: 500, label: '500 x 500' },
14+
{ width: 1200, height: 1200, label: '1200 x 1200' },
1615
] as const;
1716

1817
describe.each(viewports)('Electron launch - $label', (viewport) => {
@@ -22,9 +21,7 @@ describe.each(viewports)('Electron launch - $label', (viewport) => {
2221

2322
beforeEach(async () => {
2423
tempDir = path.resolve(os.tmpdir(), 'lyricistant-electron-test');
25-
await del(tempDir, {
26-
force: true,
27-
});
24+
fs.rmSync(tempDir, { recursive: true, force: true });
2825
app = await electron.launch({
2926
args: [
3027
path.resolve('apps/electron/dist/test/main.js'),
@@ -50,7 +47,7 @@ describe.each(viewports)('Electron launch - $label', (viewport) => {
5047
expect(elements).not.toBeEmpty();
5148

5249
await app.evaluate(
53-
(electronModule, [newViewport, browserWindow]) => {
50+
(_, [newViewport, browserWindow]) => {
5451
if (newViewport.label === 'default') {
5552
return;
5653
} else {
@@ -79,23 +76,7 @@ describe.each(viewports)('Electron launch - $label', (viewport) => {
7976
await waitForExpect(() => expect(window.title()).resolves.toBe('Untitled'));
8077
});
8178

82-
it('shows the basic components', async () => {
83-
const components = [
84-
await window.$('_react=Editor'),
85-
await window.$('_react=Menu'),
86-
await window.$('_react=Rhymes'),
87-
];
88-
89-
for (const component of components) {
90-
await waitForExpect(
91-
async () => await expect(component.isVisible()).resolves.toBeTruthy(),
92-
);
93-
}
94-
});
95-
9679
addCommonUiTests(async () => ({
9780
page: window,
98-
screen: getQueriesForElement(await getDocument(window)),
99-
isSmallLayout: viewport.isSmallLayout,
10081
}));
10182
});

apps/electron/test/unit/MenuTest.spec.ts

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,103 @@
1+
import expect from 'expect';
12
import { createAppMenu, MenuItemHandlers } from '@electron-app/app-menu';
2-
import { expect, use } from 'chai';
33
import { MenuItemConstructorOptions } from 'electron';
4-
import sinonChai from 'sinon-chai';
5-
import { StubbedInstance, stubObject } from 'ts-sinon';
6-
7-
use(sinonChai);
4+
import { DeepMockProxy, mockDeep } from 'jest-mock-extended';
85

96
describe('Create Electron App Menu', () => {
10-
const handlerObj: MenuItemHandlers = {
11-
onFindClicked: () => undefined,
12-
onNewClicked: () => undefined,
13-
onOpenClicked: () => undefined,
14-
onOpenRecentClicked: () => undefined,
15-
onPreferencesClicked: () => undefined,
16-
onAboutClicked: () => undefined,
17-
onQuitClicked: () => undefined,
18-
onRedoClicked: () => undefined,
19-
onReplaceClicked: () => undefined,
20-
onSaveAsClicked: () => undefined,
21-
onSaveClicked: () => undefined,
22-
onUndoClicked: () => undefined,
23-
};
24-
let handlers: StubbedInstance<MenuItemHandlers>;
7+
let handlers: DeepMockProxy<MenuItemHandlers>;
258

269
beforeEach(() => {
27-
handlers = stubObject<MenuItemHandlers>(handlerObj);
10+
jest.resetAllMocks();
11+
handlers = mockDeep<MenuItemHandlers>();
2812

29-
Object.keys(handlerObj)
13+
Object.keys(handlers)
3014
.filter((name) => name.startsWith('on'))
31-
.forEach((funcName) => {
32-
// @ts-expect-error types are lost here due to stubbing
33-
handlers[funcName]
34-
.onSecondCall()
35-
.throws(new Error(`${funcName} was registered multiple times!`));
15+
.forEach((funcName: keyof MenuItemHandlers) => {
16+
handlers[funcName].mockReturnValueOnce().mockImplementation(() => {
17+
new Error(`${funcName} was registered multiple times!`);
18+
});
3619
});
3720
});
3821

3922
it('actually creates a menu', () => {
4023
const actual = createAppMenu('MyApp', 'linux', handlers);
4124

42-
expect(actual).to.not.be.null;
43-
expect(actual).to.not.be.empty;
25+
expect(actual).not.toBeNull();
26+
expect(Object.keys(actual)).not.toHaveLength(0);
4427
});
4528

4629
it('includes the Mac menu when on Mac', () => {
4730
const actual = createAppMenu('MyApp', 'darwin', handlers);
4831

49-
expect(actual[0].label).to.be.equal('MyApp');
32+
expect(actual[0].label).toBe('MyApp');
5033
});
5134

5235
it("doesn't show prefs in File when on Mac", () => {
5336
const actual = createAppMenu('MyApp', 'darwin', handlers);
5437

55-
expect(actual[1].submenu).to.not.containSubset([{ label: 'Preferences' }]);
38+
expect(actual[1].submenu).not.toContainEqual([{ label: 'Preferences' }]);
5639
});
5740

5841
it("doesn't show quit in File when on Mac", () => {
5942
const actual = createAppMenu('MyApp', 'darwin', handlers);
6043

61-
expect(actual[1].submenu).to.not.containSubset([{ label: 'Quit' }]);
44+
expect(actual[1].submenu).not.toContainEqual([{ label: 'Quit' }]);
6245
});
6346

6447
it("doesn't show about in File when on Mac", () => {
6548
const actual = createAppMenu('MyApp', 'darwin', handlers);
6649

67-
expect(actual[1].submenu).to.not.containSubset([
50+
expect(actual[1].submenu).not.toContainEqual([
6851
{ label: 'About Lyricistant...' },
6952
]);
7053
});
7154

7255
it('does show about in Mac menu when on Mac', () => {
7356
const actual = createAppMenu('MyApp', 'darwin', handlers);
7457

75-
expect(actual[0].submenu).to.containSubset([
76-
{ label: 'About Lyricistant...' },
77-
]);
58+
expect(actual[0].submenu).toContainEqual(
59+
expect.objectContaining({ label: 'About Lyricistant...' }),
60+
);
7861
});
7962

8063
it('does show prefs in File when on Windows', () => {
8164
const actual = createAppMenu('MyApp', 'win32', handlers);
8265

83-
expect(actual[0].submenu).to.containSubset([{ label: 'Preferences' }]);
66+
expect(actual[0].submenu).toContainEqual(
67+
expect.objectContaining({ label: 'Preferences' }),
68+
);
8469
});
8570

8671
it('does show quit in File when on Windows', () => {
8772
const actual = createAppMenu('MyApp', 'win32', handlers);
8873

89-
expect(actual[0].submenu).to.containSubset([{ label: 'Quit' }]);
74+
expect(actual[0].submenu).toContainEqual(
75+
expect.objectContaining({ label: 'Quit' }),
76+
);
9077
});
9178

9279
it('does show about in File when on Windows', () => {
9380
const actual = createAppMenu('MyApp', 'win32', handlers);
9481

95-
expect(actual[0].submenu).to.containSubset([
96-
{ label: 'About Lyricistant...' },
97-
]);
82+
expect(actual[0].submenu).toContainEqual(
83+
expect.objectContaining({ label: 'About Lyricistant...' }),
84+
);
9885
});
9986

10087
it('does show prefs in File when on Linux', () => {
10188
const actual = createAppMenu('MyApp', 'linux', handlers);
10289

103-
expect(actual[0].submenu).to.containSubset([{ label: 'Preferences' }]);
90+
expect(actual[0].submenu).toContainEqual(
91+
expect.objectContaining({ label: 'Preferences' }),
92+
);
10493
});
10594

10695
it('does show quit in File when on Linux', () => {
10796
const actual = createAppMenu('MyApp', 'linux', handlers);
10897

109-
expect(actual[0].submenu).to.containSubset([{ label: 'Quit' }]);
98+
expect(actual[0].submenu).toContainEqual(
99+
expect.objectContaining({ label: 'Quit' }),
100+
);
110101
});
111102

112103
it('includes all of the major sections on Mac', () => {
@@ -119,7 +110,7 @@ describe('Create Electron App Menu', () => {
119110
const actual = createAppMenu('MyApp', 'darwin', handlers);
120111

121112
actual.forEach((menu, index) => {
122-
expect(menu).to.include(expected[index]);
113+
expect(menu).toMatchObject(expected[index]);
123114
});
124115
});
125116

@@ -128,7 +119,7 @@ describe('Create Electron App Menu', () => {
128119
const actual = createAppMenu('MyApp', 'linux', handlers);
129120

130121
actual.forEach((menu, index) => {
131-
expect(menu).to.include(expected[index]);
122+
expect(menu).toMatchObject(expected[index]);
132123
});
133124
});
134125

@@ -137,7 +128,7 @@ describe('Create Electron App Menu', () => {
137128
const actual = createAppMenu('MyApp', 'win32', handlers);
138129

139130
actual.forEach((menu, index) => {
140-
expect(menu).to.include(expected[index]);
131+
expect(menu).toMatchObject(expected[index]);
141132
});
142133
});
143134

@@ -147,8 +138,8 @@ describe('Create Electron App Menu', () => {
147138
({ label }) => label === 'Open recent',
148139
);
149140

150-
expect(recents).to.exist;
151-
expect(recents.submenu).to.eql([
141+
expect(recents).toBeDefined();
142+
expect(recents.submenu).toEqual([
152143
{
153144
label: '<No recent files>',
154145
enabled: false,
@@ -163,9 +154,9 @@ describe('Create Electron App Menu', () => {
163154
({ label }) => label === 'Open recent',
164155
);
165156

166-
expect(recents).to.exist;
157+
expect(recents).toBeDefined();
167158
(recents.submenu as MenuItemConstructorOptions[]).forEach((menu, index) => {
168-
expect(menu).to.include({ label: recentFiles[index] });
159+
expect(menu).toMatchObject({ label: recentFiles[index] });
169160
});
170161
});
171162

0 commit comments

Comments
 (0)