2017-06-26 17:32:14 +03:00
|
|
|
const TitleBar = require('../src/title-bar')
|
2017-08-04 21:08:29 +03:00
|
|
|
const temp = require('temp').track()
|
2017-06-26 17:32:14 +03:00
|
|
|
|
|
|
|
describe('TitleBar', () => {
|
|
|
|
it('updates its title when document.title changes', () => {
|
|
|
|
const titleBar = new TitleBar({
|
|
|
|
workspace: atom.workspace,
|
|
|
|
themes: atom.themes,
|
|
|
|
applicationDelegate: atom.applicationDelegate
|
|
|
|
})
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(titleBar.element.querySelector('.title').textContent).toBe(
|
|
|
|
document.title
|
|
|
|
)
|
2017-06-26 17:32:14 +03:00
|
|
|
|
|
|
|
const paneItem = new FakePaneItem('Title 1')
|
|
|
|
atom.workspace.getActivePane().activateItem(paneItem)
|
|
|
|
expect(document.title).toMatch('Title 1')
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(titleBar.element.querySelector('.title').textContent).toBe(
|
|
|
|
document.title
|
|
|
|
)
|
2017-06-26 17:32:14 +03:00
|
|
|
|
|
|
|
paneItem.setTitle('Title 2')
|
|
|
|
expect(document.title).toMatch('Title 2')
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(titleBar.element.querySelector('.title').textContent).toBe(
|
|
|
|
document.title
|
|
|
|
)
|
2017-06-26 17:32:14 +03:00
|
|
|
|
|
|
|
atom.project.setPaths([temp.mkdirSync('project-1')])
|
|
|
|
expect(document.title).toMatch('project-1')
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(titleBar.element.querySelector('.title').textContent).toBe(
|
|
|
|
document.title
|
|
|
|
)
|
2017-06-26 17:32:14 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can update the sheet offset for the current window based on its height', () => {
|
|
|
|
const titleBar = new TitleBar({
|
|
|
|
workspace: atom.workspace,
|
|
|
|
themes: atom.themes,
|
|
|
|
applicationDelegate: atom.applicationDelegate
|
|
|
|
})
|
|
|
|
expect(() => titleBar.updateWindowSheetOffset()).not.toThrow()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
class FakePaneItem {
|
|
|
|
constructor (title) {
|
|
|
|
this.title = title
|
|
|
|
}
|
|
|
|
|
|
|
|
getTitle () {
|
|
|
|
return this.title
|
|
|
|
}
|
|
|
|
|
|
|
|
onDidChangeTitle (callback) {
|
|
|
|
this.didChangeTitleCallback = callback
|
|
|
|
return {
|
2019-02-22 10:55:17 +03:00
|
|
|
dispose: () => {
|
|
|
|
this.didChangeTitleCallback = null
|
|
|
|
}
|
2017-06-26 17:32:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTitle (title) {
|
|
|
|
this.title = title
|
|
|
|
if (this.didChangeTitleCallback) this.didChangeTitleCallback(title)
|
|
|
|
}
|
|
|
|
}
|