Skip to content

Commit

Permalink
AppList and AppListItem render tests (#519)
Browse files Browse the repository at this point in the history
* Render tests

* Review
  • Loading branch information
andresmgot authored Aug 23, 2018
1 parent 5bedab7 commit 243eeb0
Show file tree
Hide file tree
Showing 3 changed files with 696 additions and 0 deletions.
108 changes: 108 additions & 0 deletions dashboard/src/components/AppList/AppList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { shallow } from "enzyme";
import * as React from "react";

import { IAppOverview, IAppState } from "../../shared/types";
import { CardGrid } from "../Card";
import AppList from "./AppList";
import AppListItem from "./AppListItem";

const defaultProps = {
apps: {} as IAppState,
fetchApps: jest.fn(),
filter: "",
namespace: "default",
pushSearchFilter: jest.fn(),
};

it("renders a loading message if apps object is empty", () => {
const wrapper = shallow(<AppList {...defaultProps} />);
expect(wrapper.text()).toBe("Loading");
});

it("renders a loading message if it's fetching apps", () => {
const wrapper = shallow(
<AppList
{...defaultProps}
apps={
{
isFetching: true,
items: [],
listOverview: [],
} as IAppState
}
/>,
);
expect(wrapper.text()).toContain("Loading");
});

it("renders a welcome message if no apps are available", () => {
const wrapper = shallow(
<AppList
{...defaultProps}
apps={
{
isFetching: false,
items: [],
listOverview: [],
} as IAppState
}
/>,
);
expect(wrapper).toMatchSnapshot();
});

it("renders a CardGrid with the available Apps", () => {
const wrapper = shallow(
<AppList
{...defaultProps}
apps={
{
isFetching: false,
items: [],
listOverview: [
{
releaseName: "foo",
} as IAppOverview,
],
} as IAppState
}
/>,
);
expect(
wrapper
.find(CardGrid)
.children()
.find(AppListItem)
.key(),
).toBe("foo");
});

it("filters apps", () => {
const wrapper = shallow(
<AppList
{...defaultProps}
apps={
{
isFetching: false,
items: [],
listOverview: [
{
releaseName: "foo",
} as IAppOverview,
{
releaseName: "bar",
} as IAppOverview,
],
} as IAppState
}
filter="bar"
/>,
);
expect(
wrapper
.find(CardGrid)
.children()
.find(AppListItem)
.key(),
).toBe("bar");
});
41 changes: 41 additions & 0 deletions dashboard/src/components/AppList/AppListItem.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { shallow } from "enzyme";
import * as React from "react";
import { Link } from "react-router-dom";

import { IAppOverview } from "../../shared/types";
import Card from "../Card";
import AppListItem from "./AppListItem";

it("renders a app item", () => {
const wrapper = shallow(
<AppListItem
app={
{
namespace: "default",
releaseName: "foo",
status: "DEPLOYED",
version: "1.0.0",
} as IAppOverview
}
/>,
);
expect(wrapper.find(Card).key()).toBe("foo");
expect(
wrapper
.find(Card)
.children()
.find(Link)
.props().title,
).toBe("foo");
expect(
wrapper
.find(Card)
.children()
.find(Link)
.props().to,
).toBe("/apps/ns/default/foo");
expect(wrapper.find(".ChartListItem__content__info_version").text()).toBe("1.0.0");
expect(wrapper.find(".DEPLOYED").exists()).toBe(true);
expect(wrapper.find(".ChartListItem__content__info_repo").text()).toBe("default");
expect(wrapper.find(".ChartListItem__content__info_other").text()).toBe("deployed");
});
Loading

0 comments on commit 243eeb0

Please sign in to comment.