Outlook_Addin_LLM/node_modules/@fluentui/utilities/lib/customizations/useCustomizationSettings.test.js

90 lines
4.0 KiB
JavaScript

import * as React from 'react';
import * as ReactTestUtils from 'react-dom/test-utils';
import { mount } from 'enzyme';
import { Customizations } from './Customizations';
import { CustomizerContext } from './CustomizerContext';
import { useCustomizationSettings } from './useCustomizationSettings';
describe('useCustomizatioSettings', function () {
var wrapper;
afterEach(function () {
ReactTestUtils.act(function () {
wrapper === null || wrapper === void 0 ? void 0 : wrapper.unmount();
wrapper = undefined;
});
Customizations.reset();
});
it('get settings from Customizations', function () {
Customizations.applySettings({ a: 'a' });
var settingsStates = [];
var TestComponent = function () {
var settings = useCustomizationSettings(['a']);
settingsStates.push(settings);
return null;
};
wrapper = mount(React.createElement(TestComponent, null));
expect(settingsStates.length).toBe(1);
expect(settingsStates[0]).toEqual({ a: 'a' });
});
it('get settings from Customizations when settings have changed', function () {
Customizations.applySettings({ a: 'a' });
var settingsStates = [];
var TestComponent = function () {
var settings = useCustomizationSettings(['a']);
settingsStates.push(settings);
return null;
};
wrapper = mount(React.createElement(TestComponent, null));
ReactTestUtils.act(function () {
Customizations.applySettings({ a: 'aa' });
});
expect(settingsStates.length).toBe(2);
expect(settingsStates[0]).toEqual({ a: 'a' });
expect(settingsStates[1]).toEqual({ a: 'aa' });
});
it('get settings from Customizations that are not applied', function () {
var settingsStates = [];
var TestComponent = function () {
var settings = useCustomizationSettings(['a']);
settingsStates.push(settings);
return null;
};
wrapper = mount(React.createElement(TestComponent, null));
expect(settingsStates.length).toBe(1);
expect(settingsStates[0]).toEqual({ a: undefined });
});
it('get settings from CustomizerContext', function () {
var settingsStates = [];
var TestComponent = function () {
var settings = useCustomizationSettings(['theme']);
settingsStates.push(settings);
return null;
};
var newContext = { customizations: { settings: { theme: { color: 'red' } }, scopedSettings: {} } };
wrapper = mount(React.createElement(CustomizerContext.Provider, { value: newContext },
React.createElement(TestComponent, null)));
expect(settingsStates.length).toBe(1);
expect(settingsStates[0]).toEqual({ theme: { color: 'red' } });
var updatedContext = { customizations: { settings: { theme: { color: 'green' } }, scopedSettings: {} } };
wrapper.setProps({ value: updatedContext });
expect(settingsStates.length).toBe(2);
expect(settingsStates[1]).toEqual({ theme: { color: 'green' } });
});
it('does not re-render if global settings update but within context', function () {
Customizations.applySettings({ a: 'a' });
var settingsStates = [];
var TestComponent = function () {
var settings = useCustomizationSettings(['a']);
settingsStates.push(settings);
return null;
};
var newContext = { customizations: { settings: { a: 'aa' }, scopedSettings: {}, inCustomizerContext: true } };
wrapper = mount(React.createElement(CustomizerContext.Provider, { value: newContext },
React.createElement(TestComponent, null)));
ReactTestUtils.act(function () {
Customizations.applySettings({ a: 'aaa' });
});
expect(settingsStates.length).toBe(1);
expect(settingsStates[0]).toEqual({ a: 'aa' });
});
});
//# sourceMappingURL=useCustomizationSettings.test.js.map