From 27f11164d8c2fe39c99070073ceb33422b374fae Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 18 Nov 2020 17:52:17 +0300 Subject: [PATCH] Fix wrapping `:icons` setting and parsing tuples in settings with key `:headers` --- src/store/modules/normalizers.js | 8 +++-- src/views/settings/components/Inputs.vue | 8 +++-- .../normalizers/wrapUpdatedSettings.test.js | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/store/modules/normalizers.js b/src/store/modules/normalizers.js index 3ca63ca2..58e0e284 100644 --- a/src/store/modules/normalizers.js +++ b/src/store/modules/normalizers.js @@ -66,7 +66,11 @@ export const parseTuples = (tuples, key) => { return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] }, []) } else if (Array.isArray(item.tuple[1]) && - (item.tuple[0] === ':groups' || item.tuple[0] === ':replace' || item.tuple[0] === ':retries' || item.tuple[0] === ':headers' || item.tuple[0] === ':crontab')) { + (item.tuple[0] === ':groups' || + item.tuple[0] === ':replace' || + item.tuple[0] === ':retries' || + (item.tuple[0] === ':headers' && key === 'Pleroma.Web.MediaProxy.Invalidation.Http') || + item.tuple[0] === ':crontab')) { if (item.tuple[0] === ':crontab') { accum[item.tuple[0]] = item.tuple[1].reduce((acc, group) => { return [...acc, { [group.tuple[1]]: { value: group.tuple[0], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] @@ -245,7 +249,7 @@ const wrapValues = (settings, currentState) => { return acc }, {}) return { 'tuple': [setting, { ...currentState[setting], ...mapValue }] } - } else if (type.includes('map')) { + } else if (type.includes('map') && !type.includes('list')) { const mapValue = Object.keys(value).reduce((acc, key) => { acc[key] = value[key][1] return acc diff --git a/src/views/settings/components/Inputs.vue b/src/views/settings/components/Inputs.vue index b412c1e4..ad3d7fe1 100644 --- a/src/views/settings/components/Inputs.vue +++ b/src/views/settings/components/Inputs.vue @@ -42,7 +42,8 @@ @change="update($event, settingGroup.group, settingGroup.key, settingParent, setting.key, setting.type, nested)" /> { expect(_.isEqual(result1, expectedResult1)).toBeTruthy() expect(_.isEqual(result2, expectedResult2)).toBeTruthy() }) + + it('wraps settings with type [`list`, `map`]', () => { + const settings = { ':manifest': { ':icons': [['map', 'list'], [ + { ':src': '/static/logo.png', ':type': 'image/png' }, + { ':src': '/static/icon.png', ':type': 'image/png' } + ]]}} + + const state = { ':pleroma': { ':manifest': { + ':background_color': '#191b22', + ':theme_color': '#282c37', + ':icons': [ + [ + { 'id': 'f21318c4', 'key': ':src', 'value': '/static/logo.png' }, + { 'id': 'f4b87549', 'key': ':type', 'value': 'image/png' } + ], [ + { 'id': 'f31d351e', 'key': ':src', 'value': '/static/icon.png' }, + { 'id': 'f1455852', 'key': ':type', 'value': 'image/png' } + ] + ] + }}} + + const result = wrapUpdatedSettings(':pleroma', settings, state) + const expectedResult = [{ + group: ':pleroma', + key: ':manifest', + value: [{ tuple: [':icons', [ + { ':src': '/static/logo.png', ':type': 'image/png' }, + { ':src': '/static/icon.png', ':type': 'image/png' } + ]]}] + }] + + expect(_.isEqual(result, expectedResult)).toBeTruthy() + }) it('wraps IP setting', () => { const settings = { ':gopher': { ':ip': ['tuple', '127.0.0.1']}}