Skip to content

Commit

Permalink
Merge pull request StateVoicesNational#1776 from MoveOnOrg/stage-main…
Browse files Browse the repository at this point in the history
…-82a

Stage-main 9.1 pre
  • Loading branch information
schuyler1d authored Sep 8, 2020
2 parents 6edb5fb + 04e4cc6 commit b494832
Show file tree
Hide file tree
Showing 55 changed files with 3,067 additions and 445 deletions.
153 changes: 108 additions & 45 deletions __test__/containers/UserMenu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,43 @@ import { StyleSheetTestUtils } from "aphrodite";
import { UserMenu } from "../../src/containers/UserMenu";
import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";

function getData(isSuperAdmin = false) {
return {
currentUser: {
id: 1,
displayName: "TestName",
email: "[email protected]",
is_superadmin: isSuperAdmin,
superVolOrganizations: [
{
id: 2,
name: "testOrg"
}
],
texterOrganizations: [
{
id: 2,
name: "testOrg"
}
]
}
};
}

function getWrapper(data) {
return mount(
<MuiThemeProvider>
<UserMenu data={data} />
</MuiThemeProvider>
).find(UserMenu);
}

describe("UserMenu", () => {
it("renders the correct user Avatar icon", async () => {
StyleSheetTestUtils.suppressStyleInjection();

const data = {
currentUser: {
id: 1,
displayName: "TestName",
email: "[email protected]",
superVolOrganizations: [
{
id: 2,
name: "testOrg"
}
],
texterOrganizations: [
{
id: 2,
name: "testOrg"
}
]
}
};

const wrapper = mount(
<MuiThemeProvider>
<UserMenu data={data} />
</MuiThemeProvider>
).find(UserMenu);
const data = getData();
const wrapper = getWrapper(data);

const avatar = wrapper.find("Avatar");
expect(avatar.props().children).toBe(
Expand All @@ -47,26 +55,8 @@ describe("UserMenu", () => {
it("renders the full popover menu", async () => {
StyleSheetTestUtils.suppressStyleInjection();

const data = {
currentUser: {
id: 1,
displayName: "TestName",
email: "[email protected]",
superVolOrganizations: [],
texterOrganizations: [
{
id: 2,
name: "testOrg"
}
]
}
};

const wrapper = mount(
<MuiThemeProvider>
<UserMenu data={data} />
</MuiThemeProvider>
).find(UserMenu);
const data = getData();
const wrapper = getWrapper(data);

// Make sure the menu loads
const menuPopover = wrapper.find("Popover");
Expand All @@ -83,4 +73,77 @@ describe("UserMenu", () => {
expect(menuItems[2].props["data-test"]).toBe("FAQs");
expect(menuItems[3].props["data-test"]).toBe("userMenuLogOut");
});

it("renders admin tools if user is superadmin and MULTI_TENTANT", async () => {
StyleSheetTestUtils.suppressStyleInjection();

const data = getData("true");
const wrapper = getWrapper(data);
window.MULTI_TENTANT = true;

// Make sure the menu loads
const menuPopover = wrapper.find("Popover");
expect(menuPopover.length).toBeGreaterThan(0);

const menuContentArray = menuPopover.props().children.props.children;
const menuItems = menuContentArray.filter(
item =>
item.type && (item.type.muiName === "MenuItem" || item.type === "div")
);

// Check for each thing we always expect to see in the menu
expect(menuItems[0].props["data-test"]).toBe("userMenuDisplayName");
expect(menuItems[1].key).toBe(null); // div containing rendered AdminTools
expect(menuItems[2].props["data-test"]).toBe("home");
expect(menuItems[3].props["data-test"]).toBe("FAQs");
expect(menuItems[4].props["data-test"]).toBe("userMenuLogOut");
});

it("DOESN'T render admin tools if user is NOT superadmin and MULTI_TENTANT", async () => {
StyleSheetTestUtils.suppressStyleInjection();

const data = getData();
const wrapper = getWrapper(data);
window.MULTI_TENTANT = true;

// Make sure the menu loads
const menuPopover = wrapper.find("Popover");
expect(menuPopover.length).toBeGreaterThan(0);

const menuContentArray = menuPopover.props().children.props.children;
const menuItems = menuContentArray.filter(
item =>
item.type && (item.type.muiName === "MenuItem" || item.type === "div")
);

// Check for each thing we always expect to see in the menu
expect(menuItems[0].props["data-test"]).toBe("userMenuDisplayName");
expect(menuItems[2].props["data-test"]).toBe("home");
expect(menuItems[3].props["data-test"]).toBe("FAQs");
expect(menuItems[4].props["data-test"]).toBe("userMenuLogOut");
});

it("DOESN'T render admin tools if user is NOT superadmin and NOT MULTI_TENTANT", async () => {
StyleSheetTestUtils.suppressStyleInjection();

const data = getData();
const wrapper = getWrapper(data);
window.MULTI_TENTANT = false;

// Make sure the menu loads
const menuPopover = wrapper.find("Popover");
expect(menuPopover.length).toBeGreaterThan(0);

const menuContentArray = menuPopover.props().children.props.children;
const menuItems = menuContentArray.filter(
item =>
item.type && (item.type.muiName === "MenuItem" || item.type === "div")
);

// Check for each thing we always expect to see in the menu
expect(menuItems[0].props["data-test"]).toBe("userMenuDisplayName");
expect(menuItems[2].props["data-test"]).toBe("home");
expect(menuItems[3].props["data-test"]).toBe("FAQs");
expect(menuItems[4].props["data-test"]).toBe("userMenuLogOut");
});
});
13 changes: 10 additions & 3 deletions __test__/extensions/contact-loaders/csv-upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import React from "react";
import { shallow, mount } from "enzyme";
import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
import { StyleSheetTestUtils } from "aphrodite";
import CampaignContactsChoiceForm from "../../../src/components/CampaignContactsChoiceForm";
import { CampaignContactsChoiceForm } from "../../../src/components/CampaignContactsChoiceForm";
import { icons } from "../../../src/components/CampaignContactsChoiceForm";

const contacts = [
Expand All @@ -53,6 +53,13 @@ const dupeContacts = [
zip: "10025",
custom_fields: '{"custom1": "abc"}'
},
{
first_name: "second",
last_name: "thirdlast",
cell: "+12125550100",
zip: "10025",
custom_fields: '{"custom1": "xyz"}'
},
{
first_name: "fdsa",
last_name: "yyyy",
Expand Down Expand Up @@ -111,7 +118,7 @@ describe("ingest-contact-loader method: csv-upload backend", async () => {
expect(dbContacts[0].last_name).toBe("xxxx");
expect(dbContacts[0].custom_fields).toBe('{"custom1": "abc"}');
});
it("csv-upload:processContactLoad dedupe", async () => {
it("csv-upload:processContactLoad dedupe last wins", async () => {
const job = {
payload: await gzip(JSON.stringify({ contacts: dupeContacts })),
campaign_id: testCampaign.id,
Expand All @@ -127,7 +134,7 @@ describe("ingest-contact-loader method: csv-upload backend", async () => {
.where("campaign_id", testCampaign.id)
.first();
expect(dbContacts.length).toBe(1);
expect(adminResult.duplicate_contacts_count).toBe(1);
expect(adminResult.duplicate_contacts_count).toBe(2);
expect(adminResult.contacts_count).toBe(1);
expect(dbContacts[0].first_name).toBe("fdsa");
expect(dbContacts[0].last_name).toBe("yyyy");
Expand Down
Loading

0 comments on commit b494832

Please sign in to comment.