From 1e997762c83df4b8b379d817fdb2cfc1f877662d Mon Sep 17 00:00:00 2001 From: Berk Arslan Date: Tue, 3 Aug 2021 14:30:50 +0300 Subject: [PATCH] Issue-4772 - Current PortalId on SiteSettings tab fix --- .../ClientSide/SiteSettings.Web/package.json | 4 +++ .../__tests__/siteInfoReducer.test.js | 29 +++++++++++++++++++ .../src/reducers/siteInfoReducer.js | 6 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/__tests__/siteInfoReducer.test.js diff --git a/Dnn.AdminExperience/ClientSide/SiteSettings.Web/package.json b/Dnn.AdminExperience/ClientSide/SiteSettings.Web/package.json index 9e8376293bb..caa2fb8f20d 100644 --- a/Dnn.AdminExperience/ClientSide/SiteSettings.Web/package.json +++ b/Dnn.AdminExperience/ClientSide/SiteSettings.Web/package.json @@ -4,6 +4,8 @@ "private": true, "scripts": { "build": "set NODE_ENV=production&&webpack -p", + "test": "jest", + "test:watch": "jest --watch", "debug": "set NODE_ENV=debug&&webpack -p", "webpack": "webpack-dev-server -d --port 8085 --hot --inline --content-base dist/ --history-api-fallback", "watch": "set NODE_ENV=debug & webpack --mode=development --progress --colors --watch", @@ -25,9 +27,11 @@ "css-loader": "2.1.1", "eslint": "5.8.0", "eslint-loader": "4.0.2", + "eslint-plugin-jest": "^22.0.0", "eslint-plugin-react": "7.11.1", "eslint-plugin-spellcheck": "0.0.11", "file-loader": "3.0.1", + "jest": "^24.8.0", "jwt-decode": "2.2.0", "less": "3.9.0", "less-loader": "5.0.0", diff --git a/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/__tests__/siteInfoReducer.test.js b/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/__tests__/siteInfoReducer.test.js new file mode 100644 index 00000000000..07e8086abf5 --- /dev/null +++ b/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/__tests__/siteInfoReducer.test.js @@ -0,0 +1,29 @@ +import siteInfo from "../siteInfoReducer"; +import { siteInfo as ActionTypes } from "../../constants/actionTypes"; + +describe("Site Info Reducer", () => { + it("Sets the current portal id correctly when there are multiple sites", () => { + // Arrange + let action = { + type: ActionTypes.RETRIEVED_PORTALS, + data: { + portals: [ + { + PortalID: 0, + IsCurrentPortal: false + }, + { + PortalID: 1, + IsCurrentPortal: true + } + ] + } + }; + + // Act + let state = siteInfo({}, action); + + // Assert + expect(state.portalId).toEqual(1); + }); +}); \ No newline at end of file diff --git a/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/siteInfoReducer.js b/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/siteInfoReducer.js index f5e5af1f9e4..ddd69dd61fa 100644 --- a/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/siteInfoReducer.js +++ b/Dnn.AdminExperience/ClientSide/SiteSettings.Web/src/reducers/siteInfoReducer.js @@ -26,11 +26,13 @@ export default function siteInfo(state = { return { ...state, clientModified: action.data.clientModified }; - case ActionTypes.RETRIEVED_PORTALS: + case ActionTypes.RETRIEVED_PORTALS: { + let currentPortal = action.data.portals.find(a => a.IsCurrentPortal === true); return { ...state, portals: action.data.portals, - portalId: action.data.portals[0].PortalID + portalId: currentPortal != null ? currentPortal.PortalID : action.data.portals[0].PortalID }; + } default: return state; }