-
Notifications
You must be signed in to change notification settings - Fork 705
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AppList and AppListItem render tests (#519)
* Render tests * Review
- Loading branch information
1 parent
5bedab7
commit 243eeb0
Showing
3 changed files
with
696 additions
and
0 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,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"); | ||
}); |
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,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"); | ||
}); |
Oops, something went wrong.