Skip to content

Commit

Permalink
Merged in r2-2829-release-2.10.1.1-main (pull request #6724)
Browse files Browse the repository at this point in the history
R2-2829: release-2.10.1.1 to main
  • Loading branch information
jtoliver-quoin committed Mar 25, 2024
2 parents af2d7db + c380cd7 commit 86c92b0
Show file tree
Hide file tree
Showing 11 changed files with 785 additions and 836 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ GEM
net-smtp (0.4.0.1)
net-protocol
nio4r (2.5.9)
nokogiri (1.16.2)
nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
openssl (3.1.0)
Expand All @@ -255,7 +255,7 @@ GEM
public_suffix (5.0.3)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.1)
racc (1.7.3)
rack (2.2.8.1)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/activity-log/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { lookups, stub } from "../../test";

import ActivityLog from "./component";

describe.skip("<ActivityLog", () => {
describe("<ActivityLog", () => {
let stubI18n = null;
const initialState = {
records: {
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/components/pages/account/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ const Container = ({ mode }) => {
identityOptions,
onClickChangePassword,
true,
{ userGroups: currentUser.get("userGroups", fromJS([])), webPushConfig }
{
userGroups: currentUser.get("userGroups", fromJS([])),
webPushConfigEnabled: webPushConfig?.get("enabled", false)
}
);

// eslint-disable-next-line react/no-multi-comp
Expand Down
61 changes: 61 additions & 0 deletions app/javascript/components/pages/account/container.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Account from "./container";
describe("<Account />", () => {
let component;

const getVisibleFields = allFields =>
allFields.filter(field => Object.is(field.visible, null) || field.visible).map(field => field.toJS());

beforeEach(() => {
const initialState = fromJS({
user: {
Expand Down Expand Up @@ -45,4 +48,62 @@ describe("<Account />", () => {
it("renders ChangePassword component", () => {
expect(component.find(ChangePassword)).to.have.length(1);
});

describe("when WEBPUSH is enabled", () => {
const state = fromJS({
user: {
loading: false,
errors: false,
serverErrors: [],
locale: "en",
id: 1,
full_name: "Test user",
disabled: false,
email: "[email protected]",
time_zone: "UTC",
user_name: "primero"
},
application: {
agencies: [{ id: 1, unique_id: "agency-unicef", name: "UNICEF" }],
webpush: {
enabled: true
}
}
});

const { component: newComponent } = setupMountedComponent(Account, { mode: "'edit'" }, state, ["/account"]);

it("renders 25 fields", () => {
expect(getVisibleFields(newComponent.find("FormSection").props().formSection.fields)).to.have.lengthOf(25);
});
});

describe("when WEBPUSH is disabled", () => {
const state = fromJS({
user: {
loading: false,
errors: false,
serverErrors: [],
locale: "en",
id: 1,
full_name: "Test user",
disabled: false,
email: "[email protected]",
time_zone: "UTC",
user_name: "primero"
},
application: {
agencies: [{ id: 1, unique_id: "agency-unicef", name: "UNICEF" }],
webpush: {
enabled: false
}
}
});

const { component: newComponent } = setupMountedComponent(Account, { mode: "'edit'" }, state, ["/account"]);

it("renders 20 fields", () => {
expect(getVisibleFields(newComponent.find("FormSection").props().formSection.fields)).to.have.lengthOf(20);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const Container = ({ mode }) => {
{
agencyReadOnUsers,
currentRoleGroupPermission,
webPushConfig
webPushConfigEnabled: webPushConfig?.get("enabled", false)
}
).map(formSection => (
<FormSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,34 @@ describe("<UsersForm />", () => {
expect(IdpComponent.find("a")).to.be.empty;
});
});

describe("when WEBPUSH is disabled", () => {
const state = fromJS({
records: {
users: {
selectedUser: users.jose,
data: [Object.values(users)],
metadata: { total: 2, per: 20, page: 1 }
}
},
application: {
agencies,
webpush: {
enabled: false
}
},
user: {
username: users.carlos.user_name,
permissions
}
});

const { component: newComponent } = setupMountedComponent(UsersForm, { mode: MODES.edit }, state, [
"/admin/users/1"
]);

it("renders 22 fields", () => {
expect(getVisibleFields(newComponent.find("FormSection").props().formSection.fields)).to.have.lengthOf(22);
});
});
});
19 changes: 11 additions & 8 deletions app/javascript/components/pages/admin/users-form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,28 @@ import css from "./styles.css";

const passwordPlaceholder = formMode => (formMode.get("isEdit") ? "•••••" : "");

const notificationPreferences = (i18n, notifier) =>
NOTIFICATIONS_PREFERENCES.map(preferences => ({
const notificationPreferences = (i18n, notifier, shouldRender = true) => {
if (!shouldRender) return [];

return NOTIFICATIONS_PREFERENCES.map(preferences => ({
display_name: i18n.t(`user.notification_preferences.${preferences}`),
name: FIELD_NAMES[`${notifier}_${preferences.toUpperCase()}`],
type: TICK_FIELD,
inputClassname: css.settingsChildField,
watchedInputs: FIELD_NAMES[notifier],
handleWatchedInputs: value => ({
visible: Boolean(value)
visible: Boolean(value) === true
})
}));
};

const sharedUserFields = (
i18n,
formMode,
hideOnAccountPage,
onClickChangePassword,
useIdentity,
{ agencyReadOnUsers, currentRoleGroupPermission, userGroups, webPushConfig }
{ agencyReadOnUsers, currentRoleGroupPermission, userGroups, webPushConfigEnabled }
) => [
{
display_name: i18n.t("user.full_name"),
Expand Down Expand Up @@ -219,9 +222,9 @@ const sharedUserFields = (
name: FIELD_NAMES.RECEIVE_WEBPUSH,
type: TICK_FIELD,
help_text: i18n.t("user.receive_webpush.help_text"),
visible: webPushConfig?.get("enabled", false)
visible: webPushConfigEnabled
},
...notificationPreferences(i18n, NOTIFIERS.receive_webpush)
...notificationPreferences(i18n, NOTIFIERS.receive_webpush, webPushConfigEnabled)
];

const identityUserFields = (i18n, identityOptions) => [
Expand Down Expand Up @@ -251,14 +254,14 @@ export const form = (
identityOptions,
onClickChangePassword,
hideOnAccountPage = false,
{ agencyReadOnUsers, currentRoleGroupPermission, userGroups, webPushConfig } = {}
{ agencyReadOnUsers, currentRoleGroupPermission, userGroups, webPushConfigEnabled } = {}
) => {
const useIdentity = useIdentityProviders && providers;
const sharedFields = sharedUserFields(i18n, formMode, hideOnAccountPage, onClickChangePassword, useIdentity, {
agencyReadOnUsers,
currentRoleGroupPermission,
userGroups,
webPushConfig
webPushConfigEnabled
});

const identityFields = identityUserFields(i18n, identityOptions);
Expand Down
1 change: 0 additions & 1 deletion app/javascript/test-utils/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.

import "react-16-node-hanging-test-fix"; // TODO: Remove when update to React 18
import "./globals";
import "@testing-library/jest-dom/extend-expect";
import { MessageChannel } from "worker_threads";
Expand Down
2 changes: 1 addition & 1 deletion config/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Copyright (c) 2014 - 2023 UNICEF. All rights reserved.

class Primero::Application
VERSION = '2.10.0'
VERSION = '2.10.1.1'
end
Loading

0 comments on commit 86c92b0

Please sign in to comment.