-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fleet UI: Info banner component, uses Card as base component, tests #26276
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ | |
background-color: $core-white; | ||
} | ||
|
||
&__gray { | ||
&__grey { | ||
background-color: $ui-off-white; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
import React from "react"; | ||
|
||
import { render, screen } from "@testing-library/react"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
|
||
import InfoBanner from "./InfoBanner"; | ||
|
||
describe("InfoBanner - component", () => { | ||
it("info banner renders text", () => { | ||
it("renders children content", () => { | ||
render(<InfoBanner>Info banner testing text</InfoBanner>); | ||
|
||
const title = screen.getByText("Info banner testing text"); | ||
|
||
expect(title).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders as page-level banner", () => { | ||
const { container } = render(<InfoBanner pageLevel />); | ||
expect(container.firstChild).toHaveClass("info-banner__page-banner"); | ||
}); | ||
|
||
it("renders CTA element", () => { | ||
const cta = <button>Click me</button>; | ||
render(<InfoBanner cta={cta} />); | ||
expect(screen.getByText("Click me")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders closable button and hides banner on click", () => { | ||
render(<InfoBanner closable>Test message</InfoBanner>); | ||
|
||
const closeButton = screen.getByRole("button"); | ||
expect(closeButton).toBeInTheDocument(); | ||
|
||
fireEvent.click(closeButton); | ||
expect(screen.queryByText("Test message")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("renders with icon class when icon prop is provided", () => { | ||
const { container } = render(<InfoBanner icon="info" />); | ||
expect(container.firstChild).toHaveClass("info-banner__icon"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,22 @@ import classNames from "classnames"; | |
import Icon from "components/Icon"; | ||
import Button from "components/buttons/Button"; | ||
import { IconNames } from "components/icons"; | ||
import Card from "components/Card"; | ||
|
||
const baseClass = "info-banner"; | ||
|
||
export interface IInfoBannerProps { | ||
children?: React.ReactNode; | ||
className?: string; | ||
/** default light purple */ | ||
color?: "purple" | "purple-bold-border" | "yellow" | "grey"; | ||
color?: "purple" | "yellow" | "grey"; | ||
/** default 4px */ | ||
borderRadius?: "large" | "xlarge"; | ||
borderRadius?: "medium" | "xlarge"; | ||
pageLevel?: boolean; | ||
/** Add this element to the end of the banner message. Mutually exclusive with `link`. */ | ||
cta?: JSX.Element; | ||
/** closable and link are mutually exclusive */ | ||
closable?: boolean; | ||
/** Makes the entire banner clickable */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing through instead since |
||
link?: string; | ||
icon?: IconNames; | ||
} | ||
|
||
|
@@ -32,15 +31,11 @@ const InfoBanner = ({ | |
pageLevel, | ||
cta, | ||
closable, | ||
link, | ||
icon, | ||
}: IInfoBannerProps) => { | ||
const wrapperClasses = classNames( | ||
baseClass, | ||
`${baseClass}__${color}`, | ||
{ | ||
[`${baseClass}__${color}`]: !!color, | ||
[`${baseClass}__border-radius-${borderRadius}`]: !!borderRadius, | ||
[`${baseClass}__page-banner`]: !!pageLevel, | ||
[`${baseClass}__icon`]: !!icon, | ||
}, | ||
|
@@ -75,23 +70,14 @@ const InfoBanner = ({ | |
return <></>; | ||
} | ||
|
||
if (link) { | ||
return ( | ||
<a | ||
href={link} | ||
target="_blank" | ||
rel="noreferrer" | ||
className={wrapperClasses} | ||
> | ||
{content} | ||
</a> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={wrapperClasses} role="status"> | ||
<Card | ||
className={wrapperClasses} | ||
color={color} | ||
borderRadiusSize={borderRadius} | ||
> | ||
{content} | ||
</div> | ||
</Card> | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ const MainContent = ({ | |
banner = <AppleBMTermsMessage />; | ||
} else if (isVppExpired || willVppExpire) { | ||
banner = <VppRenewalMessage expired={isVppExpired} />; | ||
} else if (isFleetLicenseExpired) { | ||
} else if (!isFleetLicenseExpired) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Change this back - used for testing |
||
banner = <LicenseExpirationBanner />; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corresponds to Card border radius sizes