This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ✅ Added titlebar test using jest
- Loading branch information
1 parent
60b0876
commit 04e89b8
Showing
8 changed files
with
2,042 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
Color: { | ||
fromHex: jest.fn(), | ||
isLighter: jest.fn(), | ||
WHITE: 'mocked-white-color' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
platform: 'Windows', | ||
isMacintosh: false, | ||
isWindows: true, | ||
isLinux: false, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
ipcRenderer: { | ||
invoke: jest.fn(), | ||
on: jest.fn(), | ||
send: jest.fn() | ||
}, | ||
Menu: { | ||
buildFromTemplate: jest.fn() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// customTitlebar.test.js | ||
|
||
const { CustomTitlebar } = require('../dist/titlebar/index'); | ||
const { BOTTOM_TITLEBAR_HEIGHT } = require('../dist/consts'); | ||
|
||
jest.mock('electron'); | ||
jest.mock('base/common/color'); | ||
jest.mock('base/common/platform'); | ||
|
||
describe('CustomTitlebar', () => { | ||
let titlebar; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
titlebar = new CustomTitlebar(); | ||
}); | ||
|
||
afterEach(() => { | ||
titlebar?.dispose(); | ||
}); | ||
|
||
test('should create an instance of CustomTitlebar', () => { | ||
expect(titlebar).toBeInstanceOf(CustomTitlebar); | ||
}); | ||
|
||
test('should update the title', () => { | ||
titlebar.updateTitle('Test Title'); | ||
expect(titlebar.titleElement.innerText).toBe('Test Title'); | ||
expect(document.title).toBe('Test Title'); | ||
}); | ||
|
||
/* test('should update the background color', () => { | ||
const newColor = 'mocked-new-color'; | ||
titlebar.updateBackground(newColor); | ||
expect(titlebar.titlebarElement.style.backgroundColor).toBe(newColor); | ||
}); */ | ||
|
||
test('should update the menu position', () => { | ||
titlebar.updateMenuPosition('bottom'); | ||
expect(titlebar.titlebarElement.style.height).toBe(BOTTOM_TITLEBAR_HEIGHT); | ||
expect(titlebar.containerElement.style.top).toBe(BOTTOM_TITLEBAR_HEIGHT); | ||
expect(titlebar.menuBarContainer.classList.contains('bottom')).toBe(true); | ||
}); | ||
|
||
/* test('should refresh the menu', async () => { | ||
const mockedMenu = { items: [{ label: 'Test Menu' }] }; | ||
ipcRenderer.invoke.mockResolvedValue(mockedMenu); | ||
await titlebar.refreshMenu(); | ||
expect(ipcRenderer.invoke).toHaveBeenCalledWith('request-application-menu'); | ||
expect(titlebar.menubarElement.push).toHaveBeenCalledWith(mockedMenu); | ||
expect(titlebar.menubarElement.update).toHaveBeenCalled(); | ||
}); */ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
preset: 'ts-jest/presets/js-with-babel', | ||
testEnvironment: 'jsdom', | ||
moduleNameMapper: { | ||
'^base/(.*)$': '<rootDir>/src/base/$1', | ||
'^static/(.*)$': '<rootDir>/static/$1' | ||
}, | ||
globals: { | ||
'ts-jest': { | ||
babelConfig: true, | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
"dev": "npm run build && npm run start", | ||
"build": "npm run clean && npm run build:package && npm run build:babel", | ||
"postversion": "cp package.json .. && chmod u+x ../revert.sh && ../revert.sh", | ||
"test": "echo \"Test script here\"" | ||
"test": "jest" | ||
}, | ||
"author": "AlexTorresDev <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -50,6 +50,7 @@ | |
"devDependencies": { | ||
"@babel/cli": "7.22.9", | ||
"@babel/core": "7.22.9", | ||
"@jest/globals": "29.6.1", | ||
"@typescript-eslint/eslint-plugin": "6.1.0", | ||
"@typescript-eslint/parser": "6.1.0", | ||
"babel-plugin-import-require-as-string": "1.0.2", | ||
|
@@ -62,8 +63,11 @@ | |
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-n": "16.0.1", | ||
"eslint-plugin-promise": "6.1.1", | ||
"jest": "^29.6.1", | ||
"jest-environment-jsdom": "29.6.1", | ||
"rimraf": "5.0.1", | ||
"standard": "17.1.0", | ||
"ts-jest": "29.1.1", | ||
"tsc-alias": "1.8.7", | ||
"typescript": "5.1.6" | ||
}, | ||
|
Oops, something went wrong.