generated from Seekra/repository-template
Add settings validator unit test #113
@@ -15,11 +15,330 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
import { validateEntry, validateSelectionOptions, assertType, assertString } from '../settingsValidator';
|
import { validateSettingsConfig, validateEntry, validateSelectionOptions, assertType, assertString } from '../settingsValidator';
|
||||||
|
|
||||||
// describe('validateSettingsConfig', () => {
|
describe('validateSettingsConfig', () => {
|
||||||
|
test.for([
|
||||||
// });
|
{ raw: false, expected: false },
|
||||||
|
{ raw: true, expected: false },
|
||||||
|
{ raw: 0, expected: false },
|
||||||
|
{ raw: 42, expected: false },
|
||||||
|
{ raw: '', expected: false },
|
||||||
|
{ raw: ' ', expected: false },
|
||||||
|
{ raw: 'a', expected: false },
|
||||||
|
{ raw: {}, expected: false },
|
||||||
|
{ raw: {
|
||||||
|
contents: []
|
||||||
|
}, expected: true },
|
||||||
|
{ raw: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, expected: true },
|
||||||
|
{ raw: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}, expected: true },
|
||||||
|
{ raw: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}, expected: true },
|
||||||
|
{ raw: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43',
|
||||||
|
default: 'true'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 42
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}, expected: false },
|
||||||
|
{ raw: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}, expected: false },
|
||||||
|
{ raw: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'sectio',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}, expected: false },
|
||||||
|
])('returns valid: $expected', ({ raw, expected }) => {
|
||||||
|
const result = validateSettingsConfig(raw);
|
||||||
|
if (!result.valid) {
|
||||||
|
console.error('Error message:', result.error);
|
||||||
|
};
|
||||||
|
expect(result.valid).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('validateEntry', () => {
|
describe('validateEntry', () => {
|
||||||
test.for([
|
test.for([
|
||||||
|
|||||||
Reference in New Issue
Block a user