From f205ff5334fd24b69554ef171cea94931c6bb977 Mon Sep 17 00:00:00 2001 From: Curtis ROck Date: Sun, 2 Aug 2020 18:45:39 -0500 Subject: [PATCH] Added tests to reducers/soapbox --- .../admin_api_frontend_config.json | 55 +++++++++++++++++++ app/soapbox/__fixtures__/soapbox.json | 40 ++++++++++++++ .../components/branding_preview.js | 32 ----------- app/soapbox/features/configuration/index.js | 2 + .../reducers/__tests__/soapbox-test.js | 36 ++++++++++++ 5 files changed, 133 insertions(+), 32 deletions(-) create mode 100644 app/soapbox/__fixtures__/admin_api_frontend_config.json create mode 100644 app/soapbox/__fixtures__/soapbox.json delete mode 100644 app/soapbox/features/configuration/components/branding_preview.js diff --git a/app/soapbox/__fixtures__/admin_api_frontend_config.json b/app/soapbox/__fixtures__/admin_api_frontend_config.json new file mode 100644 index 000000000..ee37450f8 --- /dev/null +++ b/app/soapbox/__fixtures__/admin_api_frontend_config.json @@ -0,0 +1,55 @@ +{ + "configs": [ + { + "group": ":pleroma", + "key": ":frontend_configurations", + "value": [ + { + "tuple": [ + ":soapbox_fe", + { + "logo": "blob:http://localhost:3036/0cdfa863-6889-4199-b870-4942cedd364f", + "banner": "blob:http://localhost:3036/a835afed-6078-45bd-92b4-7ffd858c3eca", + "brandColor": "#254f92", + "customCss": [ + "/instance/static/custom.css" + ], + "promoPanel": { + "items": [ + { + "icon": "globe", + "text": "blog", + "url": "https://teci.world/blog" + }, + { + "icon": "globe", + "text": "book", + "url": "https://teci.world/book" + } + ] + }, + "extensions": { + "patron": false + }, + "defaultSettings": { + "autoPlayGif": false + }, + "navlinks": { + "homeFooter": [ + { + "title": "about", + "url": "/instance/about/index.html" + }, + { + "title": "tos", + "url": "/instance/about/tos.html" + } + ] + } + } + ] + } + ] + } + ] +} diff --git a/app/soapbox/__fixtures__/soapbox.json b/app/soapbox/__fixtures__/soapbox.json new file mode 100644 index 000000000..6208b855b --- /dev/null +++ b/app/soapbox/__fixtures__/soapbox.json @@ -0,0 +1,40 @@ +{ + "logo": "blob:http://localhost:3036/0cdfa863-6889-4199-b870-4942cedd364f", + "banner": "blob:http://localhost:3036/a835afed-6078-45bd-92b4-7ffd858c3eca", + "brandColor": "#254f92", + "customCss": [ + "/instance/static/custom.css" + ], + "promoPanel": { + "items": [ + { + "icon": "globe", + "text": "blog", + "url": "https://teci.world/blog" + }, + { + "icon": "globe", + "text": "book", + "url": "https://teci.world/book" + } + ] + }, + "extensions": { + "patron": false + }, + "defaultSettings": { + "autoPlayGif": false + }, + "navlinks": { + "homeFooter": [ + { + "title": "about", + "url": "/instance/about/index.html" + }, + { + "title": "tos", + "url": "/instance/about/tos.html" + } + ] + } +} diff --git a/app/soapbox/features/configuration/components/branding_preview.js b/app/soapbox/features/configuration/components/branding_preview.js deleted file mode 100644 index 86c240538..000000000 --- a/app/soapbox/features/configuration/components/branding_preview.js +++ /dev/null @@ -1,32 +0,0 @@ -import React from 'react'; -import ImmutablePropTypes from 'react-immutable-proptypes'; -import { acctFull } from 'soapbox/utils/accounts'; -import StillImage from 'soapbox/components/still_image'; - -const BrandingPreview = ({ account }) => ( -
- -
- -
-
-
- -
-
- {account.get('username')} - - {account.get('display_name')} - - {acctFull(account)} -
-
-
-
-); - -BrandingPreview.propTypes = { - account: ImmutablePropTypes.map, -}; - -export default BrandingPreview; diff --git a/app/soapbox/features/configuration/index.js b/app/soapbox/features/configuration/index.js index cad4cae3a..b243eccd4 100644 --- a/app/soapbox/features/configuration/index.js +++ b/app/soapbox/features/configuration/index.js @@ -160,6 +160,8 @@ class ConfigSoapbox extends ImmutablePureComponent { this.state.customCssItems.forEach((f) => obj.configs[0].value[0].tuple[1].customCss.push(f) ); + console.log(JSON.stringify(obj, null, 2)); + console.log(JSON.stringify(obj.configs[0].value[0].tuple[1], null, 2)); return obj; } diff --git a/app/soapbox/reducers/__tests__/soapbox-test.js b/app/soapbox/reducers/__tests__/soapbox-test.js index f0829d66d..877a0f427 100644 --- a/app/soapbox/reducers/__tests__/soapbox-test.js +++ b/app/soapbox/reducers/__tests__/soapbox-test.js @@ -1,8 +1,44 @@ import reducer from '../soapbox'; import { Map as ImmutableMap } from 'immutable'; +import * as actions from 'soapbox/actions/soapbox'; +import soapbox from 'soapbox/__fixtures__/soapbox.json'; +import frontend_config from 'soapbox/__fixtures__/admin_api_frontend_config.json'; describe('soapbox reducer', () => { it('should return the initial state', () => { expect(reducer(undefined, {})).toEqual(ImmutableMap()); }); + + it('should handle SOAPBOX_CONFIG_REQUEST_SUCCESS', () => { + const state = ImmutableMap({ brandColor: '#354e91' }); + const action = { + type: actions.SOAPBOX_CONFIG_REQUEST_SUCCESS, + soapboxConfig: frontend_config, + }; + expect(reducer(state, action).toJS()).toMatchObject({ + brandColor: '#254f92', + }); + }); + + it('should handle SOAPBOX_CONFIG_REQUEST_FAIL', () => { + const state = ImmutableMap({ skipAlert: false }); + const action = { + type: actions.SOAPBOX_CONFIG_REQUEST_FAIL, + }; + expect(reducer(state, action).toJS()).toMatchObject({ + skipAlert: true, + }); + }); + + it('should handle SOAPBOX_POST_SUCCESS', () => { + const state = ImmutableMap({ brandColor: '#354e91' }); + const action = { + type: actions.SOAPBOX_POST_SUCCESS, + brandColor: soapbox.get('brandColor'), + }; + expect(reducer(state, action).toJS()).toMatchObject({ + brandColor: '#254f92', + }); + }); + });