From 4d6727be625a635a98cc7ab7935caec375f2de42 Mon Sep 17 00:00:00 2001 From: Patrick Cartlidge Date: Mon, 18 Nov 2024 15:10:06 +0000 Subject: [PATCH] update config --- .../src/govuk/common/configuration.mjs | 8 ++--- ...tend-component-configurable.jsdom.test.mjs | 33 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/common/configuration.mjs b/packages/govuk-frontend/src/govuk/common/configuration.mjs index 78595cffaf..63947cd1f6 100644 --- a/packages/govuk-frontend/src/govuk/common/configuration.mjs +++ b/packages/govuk-frontend/src/govuk/common/configuration.mjs @@ -1,5 +1,5 @@ +import { Component } from '../component.mjs' import { ConfigError } from '../errors/index.mjs' -import { GOVUKFrontendComponent } from '../govuk-frontend-component.mjs' import { isObject, formatErrorMessage } from './index.mjs' @@ -13,9 +13,9 @@ export const configOverride = Symbol.for('configOverride') * @virtual * @template {ObjectNested} [ConfigurationType={}] * @template {Element & { dataset: DOMStringMap }} [RootElementType=HTMLElement] - * @augments GOVUKFrontendComponent + * @augments Component */ -export class GOVUKFrontendComponentConfigurable extends GOVUKFrontendComponent { +export class ConfigurableComponent extends Component { /** * configOverride * @@ -354,5 +354,5 @@ export function extractConfigByNamespace(schema, dataset, namespace) { /** * @template {ObjectNested} [ConfigurationType={}] - * @typedef {typeof GOVUKFrontendComponent & ChildClass} ChildClassConstructor + * @typedef {typeof Component & ChildClass} ChildClassConstructor */ diff --git a/packages/govuk-frontend/src/govuk/common/configuration/govuk-frontend-component-configurable.jsdom.test.mjs b/packages/govuk-frontend/src/govuk/common/configuration/govuk-frontend-component-configurable.jsdom.test.mjs index 5e1f4831c3..83326e32cc 100644 --- a/packages/govuk-frontend/src/govuk/common/configuration/govuk-frontend-component-configurable.jsdom.test.mjs +++ b/packages/govuk-frontend/src/govuk/common/configuration/govuk-frontend-component-configurable.jsdom.test.mjs @@ -1,8 +1,5 @@ import { ConfigError } from '../../errors/index.mjs' -import { - GOVUKFrontendComponentConfigurable, - configOverride -} from '../configuration.mjs' +import { ConfigurableComponent, configOverride } from '../configuration.mjs' describe('GOVUKFrontendComponentConfigurable', () => { beforeEach(() => { @@ -18,7 +15,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { describe('throws error', () => { it('if no schema defined', () => { - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { static moduleName = 'config-component' static defaults = { @@ -26,7 +23,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { } } - expect(() => new ConfigurableComponent(document.body)).toThrow( + expect(() => new MockConfigurableComponent(document.body)).toThrow( new ConfigError( 'config-component: Config passed as parameter into constructor but no schema defined' ) @@ -34,7 +31,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { }) it('if no defaults defined', () => { - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { static moduleName = 'config-component' static schema = { @@ -44,7 +41,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { } } - expect(() => new ConfigurableComponent(document.body)).toThrow( + expect(() => new MockConfigurableComponent(document.body)).toThrow( new ConfigError( 'config-component: Config passed as parameter into constructor but no defaults defined' ) @@ -58,7 +55,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
` - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { static moduleName = 'config-component' static schema = { @@ -74,7 +71,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { const testComponent = document.querySelector('#test-component') - const configComponent = new ConfigurableComponent(testComponent) + const configComponent = new MockConfigurableComponent(testComponent) expect(configComponent._config).toMatchObject({ randomAttribute: 0 }) }) @@ -84,7 +81,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
` - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { static moduleName = 'config-component' static schema = { @@ -100,7 +97,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { const testComponent = document.querySelector('#test-component') - const configComponent = new ConfigurableComponent(testComponent) + const configComponent = new MockConfigurableComponent(testComponent) expect(configComponent._config).toMatchObject({ randomAttribute: 42 }) }) @@ -110,7 +107,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
` - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { static moduleName = 'config-component' static schema = { @@ -126,7 +123,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { const testComponent = document.querySelector('#test-component') - const configComponent = new ConfigurableComponent(testComponent, { + const configComponent = new MockConfigurableComponent(testComponent, { randomAttribute: 100 }) @@ -138,7 +135,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
` - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { static moduleName = 'config-component' static schema = { @@ -154,7 +151,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { const testComponent = document.querySelector('#test-component') - const configComponent = new ConfigurableComponent(testComponent, { + const configComponent = new MockConfigurableComponent(testComponent, { randomAttribute: 100 }) @@ -170,7 +167,7 @@ describe('GOVUKFrontendComponentConfigurable', () => {
` - class ConfigurableComponent extends GOVUKFrontendComponentConfigurable { + class MockConfigurableComponent extends ConfigurableComponent { [configOverride](config) { return configOverrideFunction(config) } @@ -190,7 +187,7 @@ describe('GOVUKFrontendComponentConfigurable', () => { const testComponent = document.querySelector('#test-component') - const configComponent = new ConfigurableComponent(testComponent, { + const configComponent = new MockConfigurableComponent(testComponent, { randomAttribute: '14' })