perf: Variety of small type and performance fixes (#2367)
This commit is contained in:
@@ -258,7 +258,4 @@ describe('getReviewSeverity', () => {
|
||||
it('should get detection severity', () => {
|
||||
expect(getReviewSeverity('detection')).toBe('medium');
|
||||
});
|
||||
it('should get significant_motion severity', () => {
|
||||
expect(getReviewSeverity('significant_motion')).toBe('low');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('OverlayMessageManager', () => {
|
||||
|
||||
it('should set and get message', () => {
|
||||
const manager = new OverlayMessageManager(api);
|
||||
const message = { message: 'foo' };
|
||||
const message = { text: 'foo' };
|
||||
manager.setMessage(message);
|
||||
|
||||
expect(manager.getMessage()).toBe(message);
|
||||
@@ -32,7 +32,7 @@ describe('OverlayMessageManager', () => {
|
||||
|
||||
it('should reset message', () => {
|
||||
const manager = new OverlayMessageManager(api);
|
||||
manager.setMessage({ message: 'foo' });
|
||||
manager.setMessage({ text: 'foo' });
|
||||
vi.clearAllMocks();
|
||||
|
||||
manager.reset();
|
||||
|
||||
@@ -105,7 +105,54 @@ describe('GalleryCoreController', () => {
|
||||
).toBeCalledWith(sentinel);
|
||||
});
|
||||
|
||||
it('should not observe when sentinel is null', () => {
|
||||
it('should disconnect when sentinel changes to null', () => {
|
||||
const sentinel = document.createElement('div');
|
||||
let currentSentinel: HTMLElement | null = sentinel;
|
||||
const getSentinelBottom = vi.fn(() => currentSentinel);
|
||||
const host = createLitElement();
|
||||
|
||||
const controller = createController({
|
||||
host,
|
||||
getSentinelBottom,
|
||||
});
|
||||
|
||||
// First call with a real sentinel.
|
||||
controller.hostUpdated();
|
||||
|
||||
currentSentinel = null;
|
||||
controller.hostUpdated();
|
||||
|
||||
expect(
|
||||
vi.mocked(IntersectionObserver).mock.results[0].value.disconnect,
|
||||
).toBeCalledTimes(2);
|
||||
expect(
|
||||
vi.mocked(IntersectionObserver).mock.results[0].value.observe,
|
||||
).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should skip disconnect/observe when sentinel is unchanged', () => {
|
||||
const sentinel = document.createElement('div');
|
||||
const getSentinelBottom = vi.fn(() => sentinel);
|
||||
const host = createLitElement();
|
||||
|
||||
const controller = createController({
|
||||
host,
|
||||
getSentinelBottom,
|
||||
});
|
||||
|
||||
controller.hostUpdated();
|
||||
controller.hostUpdated();
|
||||
|
||||
// Only called once despite two hostUpdated() calls.
|
||||
expect(
|
||||
vi.mocked(IntersectionObserver).mock.results[0].value.disconnect,
|
||||
).toBeCalledTimes(1);
|
||||
expect(
|
||||
vi.mocked(IntersectionObserver).mock.results[0].value.observe,
|
||||
).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not observe when sentinel is null from the start', () => {
|
||||
const getSentinelBottom = vi.fn(() => null);
|
||||
const host = createLitElement();
|
||||
|
||||
@@ -118,7 +165,7 @@ describe('GalleryCoreController', () => {
|
||||
|
||||
expect(
|
||||
vi.mocked(IntersectionObserver).mock.results[0].value.disconnect,
|
||||
).toBeCalled();
|
||||
).not.toBeCalled();
|
||||
expect(
|
||||
vi.mocked(IntersectionObserver).mock.results[0].value.observe,
|
||||
).not.toBeCalled();
|
||||
|
||||
@@ -311,7 +311,7 @@ describe('getChildrenFromElement', () => {
|
||||
describe('recursivelyMergeObjectsNotArrays', () => {
|
||||
it('should recursively merge objects but replace arrays', () => {
|
||||
expect(
|
||||
recursivelyMergeObjectsNotArrays(
|
||||
recursivelyMergeObjectsNotArrays<Record<string, unknown>>(
|
||||
{},
|
||||
{
|
||||
a: {
|
||||
@@ -358,7 +358,7 @@ describe('recursivelyMergeObjectsNotArrays', () => {
|
||||
describe('recursivelyMergeObjectsConcatenatingArraysUniquely', () => {
|
||||
it('should recursively merge objects but uniquely concat arrays', () => {
|
||||
expect(
|
||||
recursivelyMergeObjectsConcatenatingArraysUniquely(
|
||||
recursivelyMergeObjectsConcatenatingArraysUniquely<Record<string, unknown>>(
|
||||
{},
|
||||
{
|
||||
a: {
|
||||
|
||||
Reference in New Issue
Block a user