1- const { CustomTitlebar } = require ( '../dist/titlebar/index' )
2- const { BOTTOM_TITLEBAR_HEIGHT } = require ( '../dist/consts' )
1+ const { CustomTitlebar } = require ( '../dist/index' )
32
43jest . mock ( 'electron' )
54jest . 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 ( / r g b \( 1 8 , 5 2 , 8 6 \) / )
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 ( / r g b \( 1 7 1 , 2 0 5 , 2 3 9 \) / )
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