Skip to content

Commit

Permalink
fix: Changing fullscreen correctly calls updateView
Browse files Browse the repository at this point in the history
During the update context.updatedProperties will contain either `fullscreen_open` or `fullscreen_close`.
  • Loading branch information
BetimBeja committed Feb 27, 2023
1 parent 188aec9 commit 76eaf02
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion __tests__/Components/OwnerLookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('OwnerLookup', () => {
evt.initEvent('click', false, true);
button.dispatchEvent(evt);

expect(mockGenerator.context.updatedProperties).toStrictEqual(['value']);
expect(mockGenerator.context.updatedProperties).toStrictEqual(['value', 'parameters']);
expect(document.body).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion __tests__/Components/YearPicker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('YearPicker', () => {
evt.initEvent('input', false, true);
input.dispatchEvent(evt);

expect(mockGenerator.context.updatedProperties).toStrictEqual(['value']);
expect(mockGenerator.context.updatedProperties).toStrictEqual(['value', 'parameters']);
expect(mockGenerator.onOutputChanged.called).toBeTruthy();
expect(mockGenerator.context._parameters.value.raw).toEqual(new Date(2021, 0, 1));
expect(document.body).toMatchSnapshot();
Expand Down
49 changes: 49 additions & 0 deletions __tests__/ModeMock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright (c) 2022 Betim Beja and Shko Online LLC
Licensed under the MIT license.
*/

import { it, expect, describe, beforeEach } from '@jest/globals';
import { ComponentFrameworkMockGenerator, LookupPropertyMock } from '../src';
import { OwnerLookup } from '../__sample-components__/OwnerLookup';
import { IInputs, IOutputs } from '../__sample-components__/OwnerLookup/generated/ManifestTypes';

describe('ModeMock', () => {
let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs>;
beforeEach(() => {
const container = document.createElement('div');
mockGenerator = new ComponentFrameworkMockGenerator(
OwnerLookup,
{
value: LookupPropertyMock,
},
container,
);
mockGenerator.context._SetCanvasItems({
value: {
entityType: 'contact',
id: '11',
name: 'Betim Beja',
},
});
mockGenerator.ExecuteInit();
});

describe('Full Screen', () => {
it('updatedProperties should contain fullscreen_open', async () => {
mockGenerator.context.mode.setFullScreen(true);
expect(mockGenerator.context.updatedProperties).toContain('fullscreen_open');
});

it('updatedProperties should contain fullscreen_close', async () => {
mockGenerator.context.mode._FullScreen = true;
mockGenerator.context.mode.setFullScreen(false);
expect(mockGenerator.context.updatedProperties).toContain('fullscreen_close');
});

it('updatedProperties is empty if fullscreen is same', async () => {
mockGenerator.context.mode.setFullScreen(false);
expect(mockGenerator.context.updatedProperties).toEqual([]);
});
});
});
1 change: 0 additions & 1 deletion __tests__/WebApiMock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { IInputs, IOutputs } from '../__sample-components__/OwnerLookup/generate
import userMetadataJson from './data/systemUser.json';
import userDataJson from './data/systemUserData.json';
import betimBeja from './data/betimBeja.json';
import { assert } from 'console';

describe('WebApiMock', () => {
let mockGenerator: ComponentFrameworkMockGenerator<IInputs, IOutputs>;
Expand Down
12 changes: 11 additions & 1 deletion src/ComponentFramework-Mock-Generator/mockNotifyOutputChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export const mockNotifyOutputChanged = <
getOutputs: SinonSpy<[], TOutputs> | undefined,
executeUpdateView: () => void,
) => {
mockGenerator.context.mode.setFullScreen.callsFake((value) => {
mockGenerator.context.updatedProperties = [];
if (mockGenerator.context.mode._FullScreen != value) {
mockGenerator.context.updatedProperties.push(value ? 'fullscreen_open' : 'fullscreen_close');
}
mockGenerator.context.mode._FullScreen = value;
executeUpdateView();
});

mockGenerator.notifyOutputChanged.callsFake(() => {
const updates = getOutputs?.();
if (!updates) return;
Expand Down Expand Up @@ -45,7 +54,7 @@ export const mockNotifyOutputChanged = <
mockGenerator.context.updatedProperties.push(k);
}
} else {
/*else if (typeof updates[k] === 'object') {
/*else if (typeof updates[k] === 'object') {
// ToDo
}*/
if (
Expand Down Expand Up @@ -75,6 +84,7 @@ export const mockNotifyOutputChanged = <
}
}
if (mockGenerator.context.updatedProperties.length > 0) {
mockGenerator.context.updatedProperties.push('parameters');
executeUpdateView();
mockGenerator.onOutputChanged?.();
}
Expand Down
5 changes: 1 addition & 4 deletions src/ComponentFramework-Mock/Mode.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export class ModeMock implements ComponentFramework.Mode {
this.label = 'Mocked with @shko.online/componentframework-mock';
this.setControlState = stub(); // this is mocked in ComponentFrameworkMockGenerator
this._FullScreen = false;
this.setFullScreen = stub();
this.setFullScreen.callsFake((value) => {
this._FullScreen = value;
});
this.setFullScreen = stub(); // this is mocked in mockNotifyOutputChanged
this.trackContainerResize = stub(); // this is mocked in ComponentFrameworkMockGenerator
}
}

0 comments on commit 76eaf02

Please sign in to comment.