Skip to content

Commit

Permalink
prevent state name from extending past the sidebar column (#139749)
Browse files Browse the repository at this point in the history
  • Loading branch information
britt-mo authored Aug 23, 2024
1 parent 1198e6c commit 6fe173c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 34 deletions.
32 changes: 20 additions & 12 deletions services/ui-src/src/components/layout/StateHeader.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import React from "react";
import { useSelector } from "react-redux";
import { AppRoles } from "../../types";

const StateHeader = () => {
const { name, imageURI } = useSelector((state) => state.stateUser);

const { currentUser, name, imageURI } = useSelector(
(state) => state.stateUser
);
return (
<div
className="state-header"
data-testid="state-header"
aria-label="State Header"
>
<div className="state-image">
<img src={imageURI} alt={name} />
</div>
<div className="state-name">{name}</div>
</div>
<>
{currentUser?.role === AppRoles.STATE_USER && (
<div
className="state-header"
data-testid="state-header"
aria-label="State Header"
>
<div className="state-image">
<img src={imageURI} alt={name} />
</div>
<div className="state-name" aria-label={name}>
{name}
</div>
</div>
)}
</>
);
};

Expand Down
47 changes: 31 additions & 16 deletions services/ui-src/src/components/layout/StateHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,45 @@ import configureMockStore from "redux-mock-store";
import { Provider } from "react-redux";
import { render } from "@testing-library/react";
import StateHeader from "./StateHeader";
import {
adminUserWithReportInProgress,
stateUserWithReportInProgress,
} from "../../store/fakeStoreExamples";

const mockStore = configureMockStore();
const store = mockStore({
stateUser: {
name: "Kentucky",
imageURI: "kentucky.png",
},
});
const header = (
<Provider store={store}>
<StateHeader />
</Provider>
);
const stateUserStore = mockStore(stateUserWithReportInProgress);
const adminUserStore = mockStore(adminUserWithReportInProgress);

describe("State Header Component", () => {
it("should render correctly", () => {
test("should render correctly", () => {
const header = (
<Provider store={stateUserStore}>
<StateHeader />
</Provider>
);
expect(shallow(header).exists()).toBe(true);
});

it("Displays name, image, and alt-text for a state", () => {
test("Displays state header content for state user", () => {
const header = (
<Provider store={stateUserStore}>
<StateHeader />
</Provider>
);
const { getByTestId, getByAltText } = render(header);
const headerComponent = getByTestId("state-header");
expect(headerComponent).toHaveTextContent("Kentucky");
const img = getByAltText("Kentucky");
expect(img.src).toContain("kentucky.png");
expect(headerComponent).toHaveTextContent("Alabama");
const img = getByAltText("Alabama");
expect(img.src).toContain("al.svg");
});

test("Does not display state header content for admin user", () => {
const header = (
<Provider store={adminUserStore}>
<StateHeader />
</Provider>
);
const { queryByTestId } = render(header);
expect(queryByTestId("state-header")).not.toBeInTheDocument();
});
});
11 changes: 5 additions & 6 deletions services/ui-src/src/styles/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
.sidebar {
margin: ($margin * 3) 0;


.skip-content {
margin-bottom: ($margin * 3);
}
.state-header {
margin-bottom: ($margin * 3);
position: relative;
display: flex;
flex-flow: row wrap;
align-items: center;
}

.state-image {
position: absolute;
text-align: center;
top: 50%;
transform: translateY(-50%);
width: 70px;
}

.state-name {
font-size: 1.6rem;
font-weight: $font-weight-semi-bold;
line-height: 70px;
padding-left: 70px;
overflow-wrap: anywhere;
}
}

0 comments on commit 6fe173c

Please sign in to comment.