title-bar-spec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const TitleBar = require('../src/title-bar');
  2. const temp = require('temp').track();
  3. describe('TitleBar', () => {
  4. it('updates its title when document.title changes', () => {
  5. const titleBar = new TitleBar({
  6. workspace: atom.workspace,
  7. themes: atom.themes,
  8. applicationDelegate: atom.applicationDelegate
  9. });
  10. expect(titleBar.element.querySelector('.title').textContent).toBe(
  11. document.title
  12. );
  13. const paneItem = new FakePaneItem('Title 1');
  14. atom.workspace.getActivePane().activateItem(paneItem);
  15. expect(document.title).toMatch('Title 1');
  16. expect(titleBar.element.querySelector('.title').textContent).toBe(
  17. document.title
  18. );
  19. paneItem.setTitle('Title 2');
  20. expect(document.title).toMatch('Title 2');
  21. expect(titleBar.element.querySelector('.title').textContent).toBe(
  22. document.title
  23. );
  24. atom.project.setPaths([temp.mkdirSync('project-1')]);
  25. expect(document.title).toMatch('project-1');
  26. expect(titleBar.element.querySelector('.title').textContent).toBe(
  27. document.title
  28. );
  29. });
  30. it('can update the sheet offset for the current window based on its height', () => {
  31. const titleBar = new TitleBar({
  32. workspace: atom.workspace,
  33. themes: atom.themes,
  34. applicationDelegate: atom.applicationDelegate
  35. });
  36. expect(() => titleBar.updateWindowSheetOffset()).not.toThrow();
  37. });
  38. });
  39. class FakePaneItem {
  40. constructor(title) {
  41. this.title = title;
  42. }
  43. getTitle() {
  44. return this.title;
  45. }
  46. onDidChangeTitle(callback) {
  47. this.didChangeTitleCallback = callback;
  48. return {
  49. dispose: () => {
  50. this.didChangeTitleCallback = null;
  51. }
  52. };
  53. }
  54. setTitle(title) {
  55. this.title = title;
  56. if (this.didChangeTitleCallback) this.didChangeTitleCallback(title);
  57. }
  58. }