Skip to content

Commit

Permalink
R2-2825 - Fix account page
Browse files Browse the repository at this point in the history
  • Loading branch information
aespinoza-quoin committed Mar 22, 2024
1 parent 3be9e88 commit 1290cb2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
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);
});
});
});

0 comments on commit 1290cb2

Please sign in to comment.