mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 04:13:47 +00:00
feat: add custom field type of image
This commit is contained in:
committed by
Carlos Valente
parent
d0b4c6a279
commit
570ff59cfc
@@ -156,7 +156,7 @@ describe('parseCustomFields()', () => {
|
||||
});
|
||||
|
||||
describe('sanitiseCustomFields()', () => {
|
||||
it('returns an empty array if not an array', () => {
|
||||
it('returns an empty object the type is incorrect', () => {
|
||||
expect(sanitiseCustomFields({})).toEqual({});
|
||||
});
|
||||
|
||||
@@ -170,16 +170,16 @@ describe('sanitiseCustomFields()', () => {
|
||||
expect(sanitationResult).toStrictEqual(customFields);
|
||||
});
|
||||
|
||||
it('type is forced to be string', () => {
|
||||
const customFields: CustomFields = {
|
||||
// @ts-expect-error intentional bad data
|
||||
test: { label: 'test', type: 'another', colour: 'red' },
|
||||
};
|
||||
const expectedCustomFields: CustomFields = {
|
||||
test: { label: 'test', type: 'string', colour: 'red' },
|
||||
};
|
||||
const sanitationResult = sanitiseCustomFields(customFields);
|
||||
expect(sanitationResult).toStrictEqual(expectedCustomFields);
|
||||
it('type should be one of (image | string)', () => {
|
||||
const testTypes = sanitiseCustomFields({
|
||||
test1: { label: 'test1', type: 'another', colour: 'red' },
|
||||
test2: { label: 'test2', type: 'image', colour: 'red' },
|
||||
test3: { label: 'test3', type: 'string', colour: 'red' },
|
||||
});
|
||||
expect(testTypes).toMatchObject({
|
||||
test2: { label: 'test2', type: 'image', colour: 'red' },
|
||||
test3: { label: 'test3', type: 'string', colour: 'red' },
|
||||
});
|
||||
});
|
||||
|
||||
it('colour must be a string', () => {
|
||||
|
||||
@@ -217,15 +217,15 @@ export function sanitiseCustomFields(data: object): CustomFields {
|
||||
}
|
||||
|
||||
const keyFromLabel = customFieldLabelToKey(field.label);
|
||||
//Test label and key cohesion, but allow old lowercased keys to stay
|
||||
//TODO: the `toLocaleLowerCase` part here is to conserve keys from old projects and could be removed at some point (okt. 2024)
|
||||
// Test label and key cohesion, but allow old lowercased keys to stay
|
||||
// TODO: the `toLocaleLowerCase` part here is to conserve keys from old projects and could be removed at some point (okt. 2024)
|
||||
const key = originalKey.toLocaleLowerCase() === keyFromLabel.toLocaleLowerCase() ? originalKey : keyFromLabel;
|
||||
if (key in newCustomFields) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newCustomFields[key] = {
|
||||
type: 'string',
|
||||
type: field.type,
|
||||
colour: field.colour,
|
||||
label: field.label,
|
||||
};
|
||||
@@ -238,7 +238,9 @@ export function sanitiseCustomFields(data: object): CustomFields {
|
||||
'label' in data &&
|
||||
data.label !== '' &&
|
||||
'colour' in data &&
|
||||
typeof data.colour === 'string'
|
||||
typeof data.colour === 'string' &&
|
||||
'type' in data &&
|
||||
(data.type === 'string' || data.type === 'image')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user