2024-05-09 13:47:47 +00:00
|
|
|
import { expect } from 'chai';
|
2023-01-25 21:01:25 +00:00
|
|
|
import { closeWindow } from './lib/window-helpers';
|
2020-06-29 07:06:20 +00:00
|
|
|
import { BaseWindow, View } from 'electron/main';
|
2019-08-27 07:37:30 +00:00
|
|
|
|
|
|
|
describe('View', () => {
|
2020-06-29 07:06:20 +00:00
|
|
|
let w: BaseWindow;
|
2019-08-27 07:37:30 +00:00
|
|
|
afterEach(async () => {
|
|
|
|
await closeWindow(w as any);
|
2020-06-29 07:06:20 +00:00
|
|
|
w = null as unknown as BaseWindow;
|
2019-08-27 07:37:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can be used as content view', () => {
|
2020-06-29 07:06:20 +00:00
|
|
|
w = new BaseWindow({ show: false });
|
2024-05-09 13:47:47 +00:00
|
|
|
const v = new View();
|
|
|
|
w.setContentView(v);
|
|
|
|
expect(w.contentView).to.equal(v);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will throw when added as a child to itself', () => {
|
|
|
|
w = new BaseWindow({ show: false });
|
|
|
|
expect(() => {
|
|
|
|
w.contentView.addChildView(w.contentView);
|
|
|
|
}).to.throw('A view cannot be added as its own child');
|
2019-08-27 07:37:30 +00:00
|
|
|
});
|
2024-05-10 08:16:33 +00:00
|
|
|
|
|
|
|
it('does not crash when attempting to add a child multiple times', () => {
|
|
|
|
w = new BaseWindow({ show: false });
|
|
|
|
const cv = new View();
|
|
|
|
w.setContentView(cv);
|
|
|
|
|
|
|
|
const v = new View();
|
|
|
|
w.contentView.addChildView(v);
|
|
|
|
w.contentView.addChildView(v);
|
|
|
|
w.contentView.addChildView(v);
|
|
|
|
|
|
|
|
expect(w.contentView.children).to.have.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly reorders children', () => {
|
|
|
|
w = new BaseWindow({ show: false });
|
|
|
|
const cv = new View();
|
|
|
|
w.setContentView(cv);
|
|
|
|
|
|
|
|
const v1 = new View();
|
|
|
|
const v2 = new View();
|
|
|
|
const v3 = new View();
|
|
|
|
w.contentView.addChildView(v1);
|
|
|
|
w.contentView.addChildView(v2);
|
|
|
|
w.contentView.addChildView(v3);
|
|
|
|
|
|
|
|
expect(w.contentView.children).to.deep.equal([v1, v2, v3]);
|
|
|
|
|
|
|
|
w.contentView.addChildView(v1);
|
|
|
|
w.contentView.addChildView(v2);
|
|
|
|
expect(w.contentView.children).to.deep.equal([v3, v1, v2]);
|
|
|
|
});
|
2019-08-27 07:37:30 +00:00
|
|
|
});
|