2024-10-03 05:10:44 +03:00
|
|
|
import { BaseWindow, View } from 'electron/main';
|
|
|
|
|
2024-05-09 16:47:47 +03:00
|
|
|
import { expect } from 'chai';
|
2024-10-03 05:10:44 +03:00
|
|
|
|
2023-01-26 00:01:25 +03:00
|
|
|
import { closeWindow } from './lib/window-helpers';
|
2019-08-27 10:37:30 +03:00
|
|
|
|
|
|
|
describe('View', () => {
|
2020-06-29 10:06:20 +03:00
|
|
|
let w: BaseWindow;
|
2019-08-27 10:37:30 +03:00
|
|
|
afterEach(async () => {
|
|
|
|
await closeWindow(w as any);
|
2020-06-29 10:06:20 +03:00
|
|
|
w = null as unknown as BaseWindow;
|
2019-08-27 10:37:30 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can be used as content view', () => {
|
2020-06-29 10:06:20 +03:00
|
|
|
w = new BaseWindow({ show: false });
|
2024-05-09 16:47:47 +03: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 10:37:30 +03:00
|
|
|
});
|
2024-05-10 11:16:33 +03: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);
|
|
|
|
});
|
|
|
|
|
2024-09-12 11:01:05 +03:00
|
|
|
it('can be added as a child of another View', async () => {
|
|
|
|
const w = new BaseWindow();
|
|
|
|
const v1 = new View();
|
|
|
|
const v2 = new View();
|
|
|
|
|
|
|
|
v1.addChildView(v2);
|
|
|
|
w.contentView.addChildView(v1);
|
|
|
|
|
|
|
|
expect(w.contentView.children).to.deep.equal([v1]);
|
|
|
|
expect(v1.children).to.deep.equal([v2]);
|
|
|
|
});
|
|
|
|
|
2024-05-10 11:16:33 +03:00
|
|
|
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]);
|
|
|
|
});
|
2024-07-17 03:16:25 +03:00
|
|
|
|
|
|
|
it('allows setting various border radius values', () => {
|
|
|
|
w = new BaseWindow({ show: false });
|
|
|
|
const v = new View();
|
|
|
|
w.setContentView(v);
|
|
|
|
v.setBorderRadius(10);
|
|
|
|
v.setBorderRadius(0);
|
|
|
|
v.setBorderRadius(-10);
|
|
|
|
v.setBorderRadius(9999999);
|
|
|
|
v.setBorderRadius(-9999999);
|
|
|
|
});
|
2019-08-27 10:37:30 +03:00
|
|
|
});
|