import * as React from 'react'; import { act, render } from '@testing-library/react'; import { Customizations } from './Customizations'; import { CustomizerContext } from './CustomizerContext'; import { useCustomizationSettings } from './useCustomizationSettings'; describe('useCustomizatioSettings', function () { var component; afterEach(function () { act(function () { component === null || component === void 0 ? void 0 : component.unmount(); component = 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; }; act(function () { component = render(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; }; act(function () { component = render(React.createElement(TestComponent, null)); }); 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; }; act(function () { component = render(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: {} } }; act(function () { component = render(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: {} } }; act(function () { component.rerender(React.createElement(CustomizerContext.Provider, { value: updatedContext }, React.createElement(TestComponent, null))); }); 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 } }; act(function () { component = render(React.createElement(CustomizerContext.Provider, { value: newContext }, React.createElement(TestComponent, null))); }); act(function () { Customizations.applySettings({ a: 'aaa' }); }); expect(settingsStates.length).toBe(1); expect(settingsStates[0]).toEqual({ a: 'aa' }); }); }); //# sourceMappingURL=useCustomizationSettings.test.js.map