Skip to content

Commit d3c516a

Browse files
authored
Merge pull request #647 from zendesk/daniel_munera/GG-4255_Fix_Use_colors_from_team_settings
GG-4255: fix: Use colours from team settings in the services page
2 parents ba3b881 + 9b0448d commit d3c516a

File tree

4 files changed

+121
-11
lines changed

4 files changed

+121
-11
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
"wait-on": "8.0.3"
110110
},
111111
"resolutions": {
112-
"@types/react": "^17.x"
112+
"@types/react": "^17.x",
113+
"nwsapi": "^2.2.20"
113114
},
114115
"commitlint": {
115116
"extends": [
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { ThemeProvider } from "styled-components";
3+
import { DEFAULT_THEME } from "@zendeskgarden/react-theming";
4+
import ServiceCatalogListItem from "./ServiceCatalogListItem";
5+
import type { ServiceCatalogItem } from "../../data-types/ServiceCatalogItem";
6+
import { userEvent } from "@testing-library/user-event";
7+
8+
jest.mock("@zendeskgarden/svg-icons/src/16/shapes-fill.svg", () => {
9+
return function MockShapesIcon() {
10+
return <div data-testid="atl-nacional" />;
11+
};
12+
});
13+
14+
const theme = {
15+
...DEFAULT_THEME,
16+
colors: {
17+
...DEFAULT_THEME.colors,
18+
foreground: "#ff0000",
19+
primaryHue: "#0000ff",
20+
},
21+
};
22+
23+
const renderWithTheme = (component: React.ReactElement) => {
24+
return render(<ThemeProvider theme={theme}>{component}</ThemeProvider>);
25+
};
26+
27+
describe("ServiceCatalogListItem", () => {
28+
const mockServiceItem: ServiceCatalogItem = {
29+
id: 1989,
30+
name: "Atl Nacional keyboard",
31+
description: "This is a keyboard from Atl Nacional",
32+
form_id: 456,
33+
};
34+
35+
const mockHelpCenterPath = "/hc/en-us";
36+
37+
beforeEach(() => jest.clearAllMocks());
38+
39+
describe("Rendering", () => {
40+
it("should render the service item with correct content", () => {
41+
renderWithTheme(
42+
<ServiceCatalogListItem
43+
serviceItem={mockServiceItem}
44+
helpCenterPath={mockHelpCenterPath}
45+
/>
46+
);
47+
48+
expect(screen.getByText(mockServiceItem.name)).toBeInTheDocument();
49+
expect(screen.getByText(mockServiceItem.description)).toBeInTheDocument();
50+
expect(screen.getByTestId("atl-nacional")).toBeInTheDocument();
51+
});
52+
53+
it("should render as a link with correct href", () => {
54+
renderWithTheme(
55+
<ServiceCatalogListItem
56+
serviceItem={mockServiceItem}
57+
helpCenterPath={mockHelpCenterPath}
58+
/>
59+
);
60+
61+
const linkElement = screen.getByRole("link");
62+
63+
expect(linkElement).toHaveAttribute(
64+
"href",
65+
`${mockHelpCenterPath}/services/${mockServiceItem.id}`
66+
);
67+
});
68+
69+
it("should use the theme foreground color as text color", () => {
70+
renderWithTheme(
71+
<ServiceCatalogListItem
72+
serviceItem={mockServiceItem}
73+
helpCenterPath={mockHelpCenterPath}
74+
/>
75+
);
76+
77+
const itemContainer = screen.getByTestId(
78+
"service-catalog-list-item-container"
79+
);
80+
expect(itemContainer).toHaveStyle(`color: ${theme.colors.foreground}`);
81+
});
82+
83+
it("should use primaryHue as card border color on hover", async () => {
84+
renderWithTheme(
85+
<ServiceCatalogListItem
86+
serviceItem={mockServiceItem}
87+
helpCenterPath={mockHelpCenterPath}
88+
/>
89+
);
90+
91+
const user = userEvent.setup();
92+
const itemContainer = screen.getByTestId(
93+
"service-catalog-list-item-container"
94+
);
95+
const defaultBorderColor = DEFAULT_THEME.palette.grey?.[300];
96+
97+
expect(defaultBorderColor).toBeTruthy();
98+
expect(itemContainer).toHaveStyle(`border-color: ${defaultBorderColor}`);
99+
100+
await user.hover(itemContainer);
101+
102+
expect(itemContainer).toHaveStyle(
103+
`border-color: ${theme.colors.primaryHue}`
104+
);
105+
});
106+
});
107+
});

src/modules/service-catalog/components/service-catalog-list/ServiceCatalogListItem.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ const ItemContainer = styled.a`
1111
padding: ${(props) => props.theme.space.md};
1212
border: ${(props) => props.theme.borders.sm}
1313
${(props) => getColorV8("grey", 300, props.theme)};
14-
color: ${(props) => getColorV8("grey", 800, props.theme)};
14+
color: ${(props) => props.theme.colors.foreground};
1515
1616
&:hover {
17-
text-decoration: none;
18-
border: ${(props) => props.theme.borders.sm};
19-
border-color: ${(props) => getColorV8("blue", 600, props.theme)};
17+
border-color: ${(props) => props.theme.colors.primaryHue};
2018
}
2119
20+
&:hover,
2221
&:visited {
2322
text-decoration: none;
24-
color: ${(props) => getColorV8("grey", 800, props.theme)};
2523
}
2624
`;
2725

@@ -49,6 +47,7 @@ const TextContainer = styled.div`
4947
flex-direction: column;
5048
align-items: flex-start;
5149
gap: ${(props) => props.theme.space.xxs};
50+
color: ${(props) => props.theme.colors.foreground};
5251
`;
5352

5453
const IconContainer = styled.div`
@@ -69,7 +68,10 @@ const ServiceCatalogListItem = ({
6968
helpCenterPath: string;
7069
}) => {
7170
return (
72-
<ItemContainer href={`${helpCenterPath}/services/${serviceItem.id}`}>
71+
<ItemContainer
72+
data-testid="service-catalog-list-item-container"
73+
href={`${helpCenterPath}/services/${serviceItem.id}`}
74+
>
7375
<IconContainer>
7476
<ShapesIcon />
7577
</IconContainer>

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10836,10 +10836,10 @@ nth-check@^2.0.1:
1083610836
dependencies:
1083710837
boolbase "^1.0.0"
1083810838

10839-
nwsapi@^2.2.2:
10840-
version "2.2.7"
10841-
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.7.tgz#738e0707d3128cb750dddcfe90e4610482df0f30"
10842-
integrity sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==
10839+
nwsapi@^2.2.2, nwsapi@^2.2.20:
10840+
version "2.2.20"
10841+
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.20.tgz#22e53253c61e7b0e7e93cef42c891154bcca11ef"
10842+
integrity sha512-/ieB+mDe4MrrKMT8z+mQL8klXydZWGR5Dowt4RAGKbJ3kIGEx3X4ljUo+6V73IXtUPWgfOlU5B9MlGxFO5T+cA==
1084310843

1084410844
object-assign@^4, object-assign@^4.1.0, object-assign@^4.1.1:
1084510845
version "4.1.1"

0 commit comments

Comments
 (0)