Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: add starred resource bar to storybook (#4398)
- Loading branch information
Showing
8 changed files
with
367 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ResourceStatus } from "./types" | ||
|
||
export function ClassNameFromResourceStatus(rs: ResourceStatus): string { | ||
switch (rs) { | ||
case ResourceStatus.Building: | ||
return "isBuilding" | ||
case ResourceStatus.Pending: | ||
return "isPending" | ||
case ResourceStatus.Warning: | ||
return "isWarning" | ||
case ResourceStatus.Healthy: | ||
return "isHealthy" | ||
case ResourceStatus.Unhealthy: | ||
return "isUnhealthy" | ||
case ResourceStatus.None: | ||
return "isNone" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from "react" | ||
import StarredResourceBar, { ResourceNameAndStatus } from "./StarredResourceBar" | ||
import { Color } from "./style-helpers" | ||
import { ResourceStatus } from "./types" | ||
|
||
export default { | ||
title: "New UI/Shared/StarredResourceBar", | ||
decorators: [ | ||
// make the pane bg black so that the menu bg stands out | ||
(Story: any) => ( | ||
<div style={{ backgroundColor: Color.black, height: "300px" }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
} | ||
|
||
function story(resources: ResourceNameAndStatus[], selectedResource?: string) { | ||
return ( | ||
<StarredResourceBar | ||
resources={resources} | ||
unstar={(n) => {}} | ||
selectedResource={selectedResource} | ||
/> | ||
) | ||
} | ||
|
||
export const OneItem = () => | ||
story([{ name: "foo", status: ResourceStatus.Healthy }]) | ||
|
||
export const ThreeItems = () => | ||
story(Array(3).fill(["foo", ResourceStatus.Healthy])) | ||
|
||
export const TwentyItems = () => | ||
story(Array(20).fill(["foobar", ResourceStatus.Healthy])) | ||
|
||
export const LongName = () => | ||
story([ | ||
{ | ||
name: "supercalifragilisticexpialidocious", | ||
status: ResourceStatus.Unhealthy, | ||
}, | ||
]) | ||
|
||
export const MixedNames = () => | ||
story( | ||
[ | ||
{ name: "max-object-detected-name", status: ResourceStatus.Healthy }, | ||
{ name: "muxer", status: ResourceStatus.Unhealthy }, | ||
{ name: "benchmark-muxer", status: ResourceStatus.Healthy }, | ||
{ name: "benchmark-all", status: ResourceStatus.Healthy }, | ||
{ name: "recompile-storage", status: ResourceStatus.Unhealthy }, | ||
{ name: "benchamrk-rectangle-test", status: ResourceStatus.Healthy }, | ||
{ name: "benchmark-storage", status: ResourceStatus.Healthy }, | ||
{ name: "(Tiltfile)", status: ResourceStatus.Pending }, | ||
{ name: "recompile-rectangle-test", status: ResourceStatus.Unhealthy }, | ||
{ name: "SillyOne test", status: ResourceStatus.Unhealthy }, | ||
{ name: "AttackOfTheSilly test", status: ResourceStatus.Unhealthy }, | ||
], | ||
"benchmark-muxer" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { mount, ReactWrapper } from "enzyme" | ||
import React from "react" | ||
import { MemoryRouter } from "react-router" | ||
import PathBuilder from "./PathBuilder" | ||
import StarredResourceBar, { | ||
StarButton, | ||
StarredResource, | ||
StarredResourceLabel, | ||
} from "./StarredResourceBar" | ||
import { ResourceStatus } from "./types" | ||
|
||
const pathBuilder = PathBuilder.forTesting("localhost", "/") | ||
|
||
function getStarredItemNames( | ||
root: ReactWrapper<any, React.Component["state"], React.Component> | ||
): Array<string> { | ||
let starredItems = root.find(StarredResourceLabel) | ||
return starredItems.map((i) => i.text()) | ||
} | ||
|
||
function clickStar( | ||
root: ReactWrapper<any, React.Component["state"], React.Component>, | ||
name: string | ||
) { | ||
const r = root | ||
.find(StarredResource) | ||
.find({ resource: { name: name } }) | ||
.find(StarButton) | ||
expect(r.length).toEqual(1) | ||
r.at(0).simulate("click") | ||
} | ||
|
||
it("renders the starred items", () => { | ||
const resources = [ | ||
{ name: "foo", status: ResourceStatus.Healthy }, | ||
{ name: "bar", status: ResourceStatus.Unhealthy }, | ||
] | ||
|
||
const root = mount( | ||
<MemoryRouter> | ||
<StarredResourceBar resources={resources} unstar={() => {}} /> | ||
</MemoryRouter> | ||
) | ||
|
||
expect(getStarredItemNames(root)).toEqual(["foo", "bar"]) | ||
}) | ||
|
||
it("calls unstar", () => { | ||
const resources = [ | ||
{ name: "foo", status: ResourceStatus.Healthy }, | ||
{ name: "bar", status: ResourceStatus.Unhealthy }, | ||
] | ||
|
||
let unstars: string[] = [] | ||
let onClick = (resourceName: string) => { | ||
unstars.push(resourceName) | ||
} | ||
|
||
const root = mount( | ||
<MemoryRouter> | ||
<StarredResourceBar resources={resources} unstar={onClick} /> | ||
</MemoryRouter> | ||
) | ||
|
||
clickStar(root, "foo") | ||
|
||
expect(unstars).toEqual(["foo"]) | ||
}) |
Oops, something went wrong.