Skip to content

Commit f460a03

Browse files
committed
test: update titlebar tests for consistency and add new cases for background color and icon handling
1 parent ea521bc commit f460a03

1 file changed

Lines changed: 38 additions & 17 deletions

File tree

__test__/titlebar.test.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const { CustomTitlebar } = require('../dist/titlebar/index')
2-
const { BOTTOM_TITLEBAR_HEIGHT } = require('../dist/consts')
1+
const { CustomTitlebar } = require('../dist/index')
32

43
jest.mock('electron')
54
jest.mock('base/common/color')
@@ -29,24 +28,11 @@ describe('CustomTitlebar', () => {
2928

3029
test('should update the menu position', () => {
3130
titlebar.updateMenuPosition('bottom')
32-
expect(titlebar.titlebarElement.style.height).toBe(`${BOTTOM_TITLEBAR_HEIGHT}px`)
33-
expect(titlebar.containerElement.style.top).toBe(`${BOTTOM_TITLEBAR_HEIGHT}px`)
31+
expect(titlebar.titlebarElement.style.height).toBe('60px')
32+
expect(titlebar.containerElement.style.top).toBe('60px')
3433
expect(titlebar.menuBarContainer.classList.contains('bottom')).toBe(true)
3534
})
3635

37-
/* test('should update the background color', () => {
38-
const { Color } = require('base/common/color')
39-
titlebar.updateBackground(Color.fromHex('#ffffff'))
40-
console.log(titlebar.titlebarElement.style)
41-
expect(titlebar.titlebarElement.style.backgroundColor).toBe('#ffffff')
42-
})
43-
44-
test('should background color from string', async () => {
45-
await titlebar.updateBackground('#ffffff')
46-
console.log(titlebar.titlebarElement.style)
47-
expect(titlebar.titlebarElement.style.backgroundColor).toBe('#ffffff')
48-
}) */
49-
5036
test('should refresh the menu', async () => {
5137
const { ipcRenderer } = require('electron')
5238
const mockedMenu = { items: [{ label: 'Test &Menu' }] }
@@ -58,4 +44,39 @@ describe('CustomTitlebar', () => {
5844
expect(ipcRenderer.invoke).toHaveBeenCalledWith('request-application-menu')
5945
expect(titlebar.menuBarContainer.children.length).toBe(2) // Because the 'More' button is added
6046
})
47+
48+
test('should update background color from string', async () => {
49+
await titlebar.updateBackground('#123456')
50+
expect(titlebar.titlebarElement.style.backgroundColor).toMatch(/rgb\(18, 52, 86\)/)
51+
})
52+
53+
test('should update background color from Color object', async () => {
54+
const { TitlebarColor } = require('../dist/index')
55+
await titlebar.updateBackground(TitlebarColor.fromHex('#abcdef'))
56+
expect(titlebar.titlebarElement.style.backgroundColor).toMatch(/rgb\(171, 205, 239\)/)
57+
})
58+
59+
test('should update the icon', () => {
60+
titlebar.currentOptions.icon = 'https://example.com/initial.png'
61+
titlebar.createIcon()
62+
titlebar.updateIcon('https://example.com/icon.png')
63+
const img = titlebar.icon.querySelector('img')
64+
expect(img).not.toBeNull()
65+
expect(img.getAttribute('src')).toBe('https://example.com/icon.png')
66+
})
67+
68+
test('should hide and show the menu', () => {
69+
titlebar.menuBarContainer.style.display = 'none'
70+
expect(titlebar.menuBarContainer.style.display).toBe('none')
71+
titlebar.menuBarContainer.style.display = ''
72+
expect(titlebar.menuBarContainer.style.display).toBe('')
73+
})
74+
75+
test('should remove elements from DOM on dispose', () => {
76+
const parent = titlebar.titlebarElement.parentElement
77+
titlebar.dispose()
78+
if (parent) {
79+
expect(Array.from(parent.children)).not.toContain(titlebar.titlebarElement)
80+
}
81+
})
6182
})

0 commit comments

Comments
 (0)