pulsar/spec/title-bar-spec.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-05-31 19:33:56 +03:00
const TitleBar = require('../src/title-bar');
const temp = require('temp').track();
describe('TitleBar', () => {
it('updates its title when document.title changes', () => {
const titleBar = new TitleBar({
workspace: atom.workspace,
themes: atom.themes,
applicationDelegate: atom.applicationDelegate
2019-05-31 19:33:56 +03:00
});
2019-02-22 10:55:17 +03:00
expect(titleBar.element.querySelector('.title').textContent).toBe(
document.title
2019-05-31 19:33:56 +03:00
);
2019-05-31 19:33:56 +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
2019-05-31 19:33:56 +03:00
);
2019-05-31 19:33:56 +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
2019-05-31 19:33:56 +03:00
);
2019-05-31 19:33:56 +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
2019-05-31 19:33:56 +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
2019-05-31 19:33:56 +03:00
});
expect(() => titleBar.updateWindowSheetOffset()).not.toThrow();
});
});
class FakePaneItem {
2019-05-31 19:33:56 +03:00
constructor(title) {
this.title = title;
}
2019-05-31 19:33:56 +03:00
getTitle() {
return this.title;
}
2019-05-31 19:33:56 +03:00
onDidChangeTitle(callback) {
this.didChangeTitleCallback = callback;
return {
2019-02-22 10:55:17 +03:00
dispose: () => {
2019-05-31 19:33:56 +03:00
this.didChangeTitleCallback = null;
2019-02-22 10:55:17 +03:00
}
2019-05-31 19:33:56 +03:00
};
}
2019-05-31 19:33:56 +03:00
setTitle(title) {
this.title = title;
if (this.didChangeTitleCallback) this.didChangeTitleCallback(title);
}
}