electron/spec/api-view-spec.ts
Sam Maddock 778d3098a0
feat: customize border radius of Views (#42320)
* feat: add View#setBorderRadius

test: initial setBorderRadius tests

fix: robustly set border radius

chore: add PAUSE_CAPTURE_TESTS for easier screencap dev

feat: add view border radius support

test: view border radius

refactor: cleanup view code

* maybe delay capture to fix tests?

* refactor: retry screen captures in an attempt to fix flakiness

* refactor: ScreenCapture constructor no longer async

* increase screen capture timeout, feels a little short

* refactor: move rounded rect util into chromium_src

* skip some capture tests on mas
2024-07-16 20:16:25 -04:00

68 lines
1.9 KiB
TypeScript

import { expect } from 'chai';
import { closeWindow } from './lib/window-helpers';
import { BaseWindow, View } from 'electron/main';
describe('View', () => {
let w: BaseWindow;
afterEach(async () => {
await closeWindow(w as any);
w = null as unknown as BaseWindow;
});
it('can be used as content view', () => {
w = new BaseWindow({ show: false });
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');
});
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]);
});
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);
});
});