Skip to content

Commit

Permalink
web: refactor test data for generating a single resource, so that the…
Browse files Browse the repository at this point in the history
…re is a central, configurable function that is called instead of many (#5228)
  • Loading branch information
lizzthabet committed Nov 29, 2021
1 parent 36c5660 commit b1dbdb0
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 295 deletions.
4 changes: 2 additions & 2 deletions web/src/HeaderBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MemoryRouter } from "react-router"
import HeaderBar from "./HeaderBar"
import {
nResourceView,
oneResourceTest,
oneTestResource,
tenResourceView,
twoResourceView,
} from "./testdata"
Expand Down Expand Up @@ -47,6 +47,6 @@ export const UpgradeAvailable = () => {

export const WithTests = () => {
let view = twoResourceView()
view.uiResources.push(oneResourceTest(), oneResourceTest())
view.uiResources.push(oneTestResource(), oneTestResource())
return <HeaderBar view={view} />
}
38 changes: 8 additions & 30 deletions web/src/OverviewActionBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import { createMemoryHistory } from "history"
import React from "react"
import { Router } from "react-router"
import { ButtonSet } from "./ApiButton"
import {
EMPTY_FILTER_TERM,
FilterLevel,
FilterSet,
FilterSource,
useFilterSet,
} from "./logfilters"
import { FilterLevel, FilterSource, useFilterSet } from "./logfilters"
import OverviewActionBar from "./OverviewActionBar"
import { TiltSnackbarProvider } from "./Snackbar"
import { StarredResourceMemoryProvider } from "./StarredResourcesContext"
Expand Down Expand Up @@ -53,35 +47,19 @@ export default {
},
}

let defaultFilter: FilterSet = {
source: FilterSource.all,
level: FilterLevel.all,
term: EMPTY_FILTER_TERM,
}

export const OverflowTextBar = () => {
let filterSet = useFilterSet()
let res = oneResource()
res.status = res.status || {}
res.status.endpointLinks = [
{ url: "http://my-pod-grafana-long-service-name-deadbeef:4001" },
{ url: "http://my-pod-grafana-long-service-name-deadbeef:4002" },
]
res.status.k8sResourceInfo = {
podName: "my-pod-grafana-long-service-name-deadbeef",
}
let res = oneResource({
isBuilding: true,
name: "my-grafana-long-service-name-deadbeef",
endpoints: 2,
})
return <OverviewActionBar resource={res} filterSet={filterSet} />
}

export const FullBar = () => {
let filterSet = useFilterSet()
let res = oneResource()
res.status = res.status || {}
res.status.endpointLinks = [
{ url: "http://localhost:4001" },
{ url: "http://localhost:4002" },
]
res.status.k8sResourceInfo = { podName: "my-pod-deadbeef" }
let res = oneResource({ isBuilding: true, name: "my-deadbeef", endpoints: 2 })
let buttons: ButtonSet = {
default: [oneButton(1, "vigoda")],
toggleDisable: disableButton("vigoda", true),
Expand All @@ -93,7 +71,7 @@ export const FullBar = () => {

export const EmptyBar = () => {
let filterSet = useFilterSet()
let res = oneResource()
let res = oneResource({ isBuilding: true })
res.status = res.status || {}
res.status.endpointLinks = []
res.status.k8sResourceInfo = {}
Expand Down
6 changes: 3 additions & 3 deletions web/src/OverviewActionBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import OverviewActionBar, {
FILTER_INPUT_DEBOUNCE,
} from "./OverviewActionBar"
import { EmptyBar, FullBar } from "./OverviewActionBar.stories"
import { disableButton, oneButton, oneResourceNoAlerts } from "./testdata"
import { disableButton, oneButton, oneResource } from "./testdata"

let history: MemoryHistory
beforeEach(() => {
Expand Down Expand Up @@ -63,7 +63,7 @@ it("shows pod ID", () => {
const podId = root.find(ActionBarTopRow).find(CopyButton)

expect(podId).toHaveLength(1)
expect(podId.text()).toContain("my-pod-deadbeef Pod ID") // Hardcoded from test data
expect(podId.text()).toContain("my-deadbeef-pod Pod ID") // Hardcoded from test data
})

it("skips the top bar when empty", () => {
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("disabled resource view", () => {
let root: ReactWrapper<any, any>

beforeEach(() => {
const resource = oneResourceNoAlerts({
const resource = oneResource({
name: "i-am-not-enabled",
disabled: true,
})
Expand Down
4 changes: 2 additions & 2 deletions web/src/OverviewResourceBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MemoryRouter } from "react-router"
import OverviewResourceBar from "./OverviewResourceBar"
import {
nResourceView,
oneResourceTest,
oneTestResource,
tenResourceView,
twoResourceView,
} from "./testdata"
Expand Down Expand Up @@ -53,6 +53,6 @@ export const UpgradeAvailable = () => {

export const WithTests = () => {
let view = twoResourceView()
view.uiResources.push(oneResourceTest(), oneResourceTest())
view.uiResources.push(oneTestResource(), oneTestResource())
return <OverviewResourceBar view={view} />
}
2 changes: 1 addition & 1 deletion web/src/OverviewResourcePane.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("alert filtering", () => {

it("categorizes buttons", () => {
const view = {
uiResources: [oneResource()],
uiResources: [oneResource({ isBuilding: true })],
uiButtons: [oneButton(0, "vigoda"), disableButton("vigoda", true)],
}
const root = mount(
Expand Down
14 changes: 6 additions & 8 deletions web/src/OverviewResourceSidebar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
nResourceView,
nResourceWithLabelsView,
oneResource,
oneResourceNoAlerts,
oneResourceTest,
oneTestResource,
tenResourceView,
tiltfileResource,
twoResourceView,
Expand Down Expand Up @@ -86,12 +85,11 @@ export const OneHundredResources = () => (
export function TwoResourcesTwoTests() {
let all: UIResource[] = [
tiltfileResource(),
oneResource(),
oneResourceNoAlerts({}),
oneResourceTest(),
oneResourceTest(),
oneResource({ isBuilding: true }),
oneResource({ name: "snack" }),
oneTestResource(),
oneTestResource(),
]
all[2].metadata = { name: "snack" }
all[3].metadata = { name: "beep" }
let view = { uiResources: all, tiltfileKey: "test" }
return <OverviewResourceSidebar name={""} view={view} />
Expand All @@ -103,7 +101,7 @@ export function TestsWithErrors() {
let spans = {} as any
let all: UIResource[] = [tiltfileResource()]
for (let i = 0; i < 8; i++) {
let test = oneResourceTest()
let test = oneTestResource()
let name = "test_" + i
test.metadata = { name: name }

Expand Down
10 changes: 5 additions & 5 deletions web/src/OverviewTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
nButtonView,
nResourceView,
nResourceWithLabelsView,
oneResourceNoAlerts,
oneResource,
tiltfileResource,
twoResourceView,
} from "./testdata"
Expand Down Expand Up @@ -91,8 +91,8 @@ export const TenResources = () => {
const view = nResourceView(8)

// Add a couple disabled resources
const disableResource9 = oneResourceNoAlerts({ disabled: true, name: "_8" })
const disableResource10 = oneResourceNoAlerts({ disabled: true, name: "_9" })
const disableResource9 = oneResource({ disabled: true, name: "_8" })
const disableResource10 = oneResource({ disabled: true, name: "_9" })
view.uiResources.push(disableResource9)
view.uiResources.push(disableResource10)

Expand All @@ -103,12 +103,12 @@ export const TenResourceWithLabels = () => {
const view = nResourceWithLabelsView(8)

// Add a couple disabled resources
const disableResource9 = oneResourceNoAlerts({
const disableResource9 = oneResource({
disabled: true,
name: "_8",
labels: 2,
})
const disableResource10 = oneResourceNoAlerts({ disabled: true, name: "_9" })
const disableResource10 = oneResource({ disabled: true, name: "_9" })
view.uiResources.push(disableResource9)
view.uiResources.push(disableResource10)

Expand Down
10 changes: 5 additions & 5 deletions web/src/OverviewTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
nResourceView,
nResourceWithLabelsView,
oneButton,
oneResourceNoAlerts,
oneResource,
TestDataView,
} from "./testdata"
import { RuntimeStatus, UpdateStatus } from "./types"
Expand Down Expand Up @@ -149,7 +149,7 @@ it("sorts by status", () => {
view.uiResources[3].status!.updateStatus = UpdateStatus.Error
view.uiResources[7].status!.runtimeStatus = RuntimeStatus.Error
view.uiResources.unshift(
oneResourceNoAlerts({ disabled: true, name: "disabled_resource" })
oneResource({ disabled: true, name: "disabled_resource" })
)
const root = mount(
tableViewWithSettings({ view, disableResourcesEnabled: true })
Expand Down Expand Up @@ -618,11 +618,11 @@ describe("when disable resources feature is enabled", () => {
beforeEach(() => {
view = nResourceView(4)
// Add two disabled resources to view and place them throughout list
const firstDisabledResource = oneResourceNoAlerts({
const firstDisabledResource = oneResource({
name: "zee_disabled_resource",
disabled: true,
})
const secondDisabledResource = oneResourceNoAlerts({
const secondDisabledResource = oneResource({
name: "_0_disabled_resource",
disabled: true,
})
Expand Down Expand Up @@ -713,7 +713,7 @@ describe("when disable resources feature is NOT enabled", () => {
beforeEach(() => {
view = nResourceView(8)
// Add a disabled resource to view
const disabledResource = oneResourceNoAlerts({
const disabledResource = oneResource({
name: "disabled_resource",
disabled: true,
})
Expand Down
4 changes: 2 additions & 2 deletions web/src/SidebarItemView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ResourceNavContextProvider } from "./ResourceNav"
import SidebarItem from "./SidebarItem"
import SidebarItemView, { SidebarItemViewProps } from "./SidebarItemView"
import { Width } from "./style-helpers"
import { oneResourceNoAlerts } from "./testdata"
import { oneResource } from "./testdata"
import {
ResourceName,
ResourceStatus,
Expand Down Expand Up @@ -105,7 +105,7 @@ function withArgs(args: Args): optionFn {

function itemView(...options: optionFn[]) {
let ls = new LogStore()
let item = new SidebarItem(oneResourceNoAlerts({}), ls)
let item = new SidebarItem(oneResource({}), ls)
let props = {
item: item,
selected: false,
Expand Down
4 changes: 2 additions & 2 deletions web/src/SidebarItemView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SidebarItemView, {
DisabledSidebarItemView,
EnabledSidebarItemView,
} from "./SidebarItemView"
import { oneResourceNoAlerts, TestResourceOptions } from "./testdata"
import { oneResource, TestResourceOptions } from "./testdata"
import { ResourceView } from "./types"

const PATH_BUILDER = PathBuilder.forTesting("localhost", "/")
Expand Down Expand Up @@ -40,7 +40,7 @@ const SidebarItemViewTestWrapper = ({
}

const oneSidebarItem = (options: TestResourceOptions) => {
return new SidebarItem(oneResourceNoAlerts(options), LOG_ALERT_INDEX)
return new SidebarItem(oneResource(options), LOG_ALERT_INDEX)
}

describe("SidebarItemView", () => {
Expand Down
14 changes: 7 additions & 7 deletions web/src/SidebarResources.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
nResourceView,
nResourceWithLabelsView,
oneResource,
oneResourceTestWithName,
oneTestResource,
twoResourceView,
} from "./testdata"
import { ResourceStatus, ResourceView } from "./types"
Expand Down Expand Up @@ -213,9 +213,9 @@ describe("SidebarResources", () => {

let ls = new LogStore()
const items = [
oneResource(),
oneResourceTestWithName("a"),
oneResourceTestWithName("b"),
oneResource({ isBuilding: true }),
oneTestResource("a"),
oneTestResource("b"),
].map((res) => new SidebarItem(res, ls))

const root = mount(
Expand Down Expand Up @@ -252,9 +252,9 @@ describe("SidebarResources", () => {
(name, expectedOptions) => {
let ls = new LogStore()
const items = [
oneResource(),
oneResourceTestWithName("a"),
oneResourceTestWithName("b"),
oneResource({ isBuilding: true }),
oneTestResource("a"),
oneTestResource("b"),
].map((res) => new SidebarItem(res, ls))

const root = mount(
Expand Down

0 comments on commit b1dbdb0

Please sign in to comment.