Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdavies73 committed Oct 16, 2023
1 parent 20ddd2d commit 6d89c2a
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 412 deletions.
30 changes: 30 additions & 0 deletions cypress/components/profile/profile.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ context("Tests for Profile component", () => {
});
}
);

describe("colour tests", () => {
it.each([
[true, "rgb(204, 214, 219)"],
[false, "rgba(0, 0, 0, 0.9)"],
])(
"color should be correct when darkBackground variant is %s",
(boolVals, color) => {
CypressMountWithProviders(
<ProfileComponent name="John Doe" darkBackground={boolVals} />
);

profilePreview().should("have.css", "color", color);
}
);

it.each([
[false, "rgba(0, 0, 0, 0.9)"],
[true, "rgb(204, 214, 219)"],
])(
"background-color should be correct when darkBackground variant is %s",
(boolVals, color) => {
CypressMountWithProviders(
<ProfileComponent name="John Doe" darkBackground={boolVals} />
);

profilePreview().should("have.css", "color", color);
}
);
});
});

describe("Accessibility tests for Profile component", () => {
Expand Down
50 changes: 0 additions & 50 deletions src/components/portrait/portrait-gravatar.component.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions src/components/portrait/portrait-gravatar.spec.tsx

This file was deleted.

96 changes: 0 additions & 96 deletions src/components/portrait/portrait-initials.component.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/components/portrait/portrait-initials.spec.tsx

This file was deleted.

60 changes: 34 additions & 26 deletions src/components/portrait/portrait.component.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React, { useEffect, useState, useContext } from "react";
import { MarginProps } from "styled-system";
import MD5 from "crypto-js/md5";
import invariant from "invariant";

import { IconType } from "../icon";
import Tooltip from "../tooltip";
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
import PortraitGravatar from "./portrait-gravatar.component";
import PortraitInitials from "./portrait-initials.component";
import { PORTRAIT_SIZE_PARAMS } from "./portrait.config";
import {
StyledCustomImg,
StyledIcon,
StyledPortraitContainer,
StyledPortraitInitials,
StyledPortraitGravatar,
} from "./portrait.style";
import { filterStyledSystemMarginProps } from "../../style/utils";
import { NewValidationContext as RoundedCornersOptOutContext } from "../carbon-provider/carbon-provider.component";
Expand All @@ -26,6 +28,8 @@ export interface PortraitProps extends MarginProps {
src?: string;
/** The size of the Portrait. */
size?: PortraitSizes;
/** @private @ignore */
name?: string;
/** The `alt` HTML string. */
alt?: string;
/** The shape of the Portrait. */
Expand Down Expand Up @@ -56,10 +60,11 @@ export interface PortraitProps extends MarginProps {
tooltipFontColor?: string;
}

export const Portrait = ({
alt = "",
const Portrait = ({
alt,
name,
darkBackground = false,
gravatar,
gravatar = "",
iconType = "individual",
initials,
shape,
Expand Down Expand Up @@ -92,25 +97,26 @@ export const Portrait = ({

const tagProps = tagComponent("portrait", rest);

const gravatarSrc = () => {
const { dimensions } = PORTRAIT_SIZE_PARAMS[size];
const base = "https://www.gravatar.com/avatar/";
const hash = MD5(gravatar.toLowerCase());
const fallbackOption = "404"; // "Return an HTTP 404 File Not Found response"

/** @see https://en.gravatar.com/site/implement/images/#default-image */
return `${base}${hash}?s=${dimensions}&d=${fallbackOption}`;
};

const renderComponent = () => {
let portrait = (
<StyledIcon
type={iconType}
size={size}
shape={shape || defaultShape}
darkBackground={darkBackground}
/>
<StyledIcon type={iconType} size={size} darkBackground={darkBackground} />
);

if (initials) {
portrait = (
<PortraitInitials
size={size}
shape={shape || defaultShape}
initials={initials}
darkBackground={darkBackground}
alt={alt}
/>
<StyledPortraitInitials size={size} darkBackground={darkBackground}>
{initials.toUpperCase()}
</StyledPortraitInitials>
);
}

Expand All @@ -119,8 +125,6 @@ export const Portrait = ({
<StyledCustomImg
src={src}
alt={alt}
size={size}
shape={shape || defaultShape}
data-element="user-image"
onError={() => setExternalError(true)}
/>
Expand All @@ -129,12 +133,10 @@ export const Portrait = ({

if (gravatar && !externalError) {
portrait = (
<PortraitGravatar
gravatarEmail={gravatar}
shape={shape || defaultShape}
size={size}
alt={alt}
errorCallback={() => setExternalError(true)}
<StyledPortraitGravatar
src={gravatarSrc()}
alt={alt || name || ""}
onError={() => setExternalError(true)}
/>
);
}
Expand All @@ -155,6 +157,9 @@ export const Portrait = ({
{...filterStyledSystemMarginProps(rest)}
onClick={onClick}
{...tagProps}
darkBackground={darkBackground}
size={size}
shape={shape || defaultShape}
>
{portrait}
</StyledPortraitContainer>
Expand All @@ -167,6 +172,9 @@ export const Portrait = ({
{...filterStyledSystemMarginProps(rest)}
onClick={onClick}
{...tagProps}
darkBackground={darkBackground}
size={size}
shape={shape || defaultShape}
>
{portrait}
</StyledPortraitContainer>
Expand Down
14 changes: 13 additions & 1 deletion src/components/portrait/portrait.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ test.describe("Prop checks for Portrait component", () => {

([
["without", false, "rgb(242, 245, 246)"],
["with", true, "rgb(153, 173, 183)"],
["with", true, "rgba(0, 0, 0, 0.9)"],
] as [string, boolean, string][]).forEach(([renderState, boolVal, color]) => {
test(`should render ${renderState} dark background variant, when darkBackground prop is ${boolVal}`, async ({
mount,
Expand All @@ -155,6 +155,18 @@ test.describe("Prop checks for Portrait component", () => {
});
});

["SPM", "JM", "AR", "MJ"].forEach((passInitials) => {
test(`should render with correct width and height, when initials prop is passed as ${passInitials}`, async ({
mount,
page,
}) => {
await mount(<PortraitDefaultComponent initials={passInitials} />);

await expect(portraitInitials(page)).toHaveCSS("height", "38px");
await expect(portraitInitials(page)).toHaveCSS("width", "38px");
});
});

testData.forEach((tooltipMessage) => {
test(`should render with tooltipMessage as ${tooltipMessage}`, async ({
mount,
Expand Down
Loading

0 comments on commit 6d89c2a

Please sign in to comment.