|
@@ -28,13 +28,50 @@ describe('List', () => {
|
|
|
|
|
|
const setupWrapper = (props: Partial<ListProps> = {}) => (
|
|
const setupWrapper = (props: Partial<ListProps> = {}) => (
|
|
<StaticRouter location={{ pathname }} context={{}}>
|
|
<StaticRouter location={{ pathname }} context={{}}>
|
|
- <List schemas={[]} {...props} />
|
|
|
|
|
|
+ <List
|
|
|
|
+ isFetching
|
|
|
|
+ fetchSchemasByClusterName={jest.fn()}
|
|
|
|
+ schemas={[]}
|
|
|
|
+ {...props}
|
|
|
|
+ />
|
|
</StaticRouter>
|
|
</StaticRouter>
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ describe('Initial state', () => {
|
|
|
|
+ let useEffect: jest.SpyInstance<
|
|
|
|
+ void,
|
|
|
|
+ [effect: React.EffectCallback, deps?: React.DependencyList | undefined]
|
|
|
|
+ >;
|
|
|
|
+ const mockedFn = jest.fn();
|
|
|
|
+
|
|
|
|
+ const mockedUseEffect = () => {
|
|
|
|
+ useEffect.mockImplementationOnce(mockedFn);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ beforeEach(() => {
|
|
|
|
+ useEffect = jest.spyOn(React, 'useEffect');
|
|
|
|
+ mockedUseEffect();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ it('should call fetchSchemasByClusterName every render', () => {
|
|
|
|
+ mount(setupWrapper({ fetchSchemasByClusterName: mockedFn }));
|
|
|
|
+ expect(mockedFn).toHaveBeenCalled();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ describe('when fetching', () => {
|
|
|
|
+ it('renders PageLoader', () => {
|
|
|
|
+ const wrapper = mount(setupWrapper({ isFetching: true }));
|
|
|
|
+ expect(wrapper.exists('Breadcrumb')).toBeTruthy();
|
|
|
|
+ expect(wrapper.exists('thead')).toBeFalsy();
|
|
|
|
+ expect(wrapper.exists('ListItem')).toBeFalsy();
|
|
|
|
+ expect(wrapper.exists('PageLoader')).toBeTruthy();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
describe('without schemas', () => {
|
|
describe('without schemas', () => {
|
|
it('renders table heading without ListItem', () => {
|
|
it('renders table heading without ListItem', () => {
|
|
- const wrapper = mount(setupWrapper());
|
|
|
|
|
|
+ const wrapper = mount(setupWrapper({ isFetching: false }));
|
|
expect(wrapper.exists('Breadcrumb')).toBeTruthy();
|
|
expect(wrapper.exists('Breadcrumb')).toBeTruthy();
|
|
expect(wrapper.exists('thead')).toBeTruthy();
|
|
expect(wrapper.exists('thead')).toBeTruthy();
|
|
expect(wrapper.exists('ListItem')).toBeFalsy();
|
|
expect(wrapper.exists('ListItem')).toBeFalsy();
|
|
@@ -42,7 +79,7 @@ describe('List', () => {
|
|
});
|
|
});
|
|
|
|
|
|
describe('with schemas', () => {
|
|
describe('with schemas', () => {
|
|
- const wrapper = mount(setupWrapper({ schemas }));
|
|
|
|
|
|
+ const wrapper = mount(setupWrapper({ isFetching: false, schemas }));
|
|
|
|
|
|
it('renders table heading with ListItem', () => {
|
|
it('renders table heading with ListItem', () => {
|
|
expect(wrapper.exists('Breadcrumb')).toBeTruthy();
|
|
expect(wrapper.exists('Breadcrumb')).toBeTruthy();
|