Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(routerTypes): issues/328 lazy load routing #337

Merged
merged 2 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
"@patternfly/react-icons": "4.4.2",
"@patternfly/react-styles": "4.4.2",
"@patternfly/react-tokens": "4.5.2",
"@redhat-cloud-services/frontend-components": "2.1.1",
"@redhat-cloud-services/frontend-components-notifications": "2.1.0",
"@redhat-cloud-services/frontend-components": "2.1.3",
"@redhat-cloud-services/frontend-components-notifications": "2.1.1",
"@redhat-cloud-services/frontend-components-utilities": "2.1.0",
"axios": "^0.19.2",
"c3": "^0.7.15",
Expand Down
35 changes: 35 additions & 0 deletions src/components/loader/__tests__/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Loader Component should handle variant loader components: variant: default 1`] = `
<Skeleton
isDark={false}
size="md"
/>
`;

exports[`Loader Component should handle variant loader components: variant: skeleton 1`] = `
<Skeleton
isDark={false}
size="md"
/>
`;

exports[`Loader Component should handle variant loader components: variant: spinner 1`] = `<Spinner />`;

exports[`Loader Component should handle variant loader components: variant: title 1`] = `
<PageLayout>
<PageHeader>
<Skeleton
isDark={false}
size="md"
/>
</PageHeader>
</PageLayout>
`;

exports[`Loader Component should render a non-connected component: non-connected 1`] = `
<Skeleton
isDark={false}
size="md"
/>
`;
34 changes: 34 additions & 0 deletions src/components/loader/__tests__/loader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Loader } from '../loader';

describe('Loader Component', () => {
it('should render a non-connected component', () => {
const props = {};

const component = shallow(<Loader {...props} />);
expect(component).toMatchSnapshot('non-connected');
});

it('should handle variant loader components', () => {
const props = {};

const component = shallow(<Loader {...props} />);
expect(component).toMatchSnapshot('variant: default');

component.setProps({
variant: 'skeleton'
});
expect(component).toMatchSnapshot('variant: skeleton');

component.setProps({
variant: 'spinner'
});
expect(component).toMatchSnapshot('variant: spinner');

component.setProps({
variant: 'title'
});
expect(component).toMatchSnapshot('variant: title');
});
});
53 changes: 53 additions & 0 deletions src/components/loader/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Skeleton } from '@redhat-cloud-services/frontend-components/components/Skeleton';
import { Spinner } from '@redhat-cloud-services/frontend-components/components/cjs/Spinner';
import { PageHeader, PageLayout } from '../pageLayout/pageLayout';

/**
* ToDo: Expand the loader to accept variants.
* Need updated skeleton with multiline/paragraph, graph and table variations.
*/
/**
* Render a basic skeleton loader.
*
* @param {string} variant
* @returns {Node}
*/
const Loader = ({ variant }) => {
switch (variant) {
case 'title':
return (
<PageLayout>
<PageHeader>
<Skeleton size="md" />
</PageHeader>
</PageLayout>
);
case 'skeleton':
return <Skeleton size="md" />;
case 'spinner':
default:
return <Spinner />;
}
};

/**
* Prop types.
*
* @type {{}}
*/
Loader.propTypes = {
variant: PropTypes.oneOf(['skeleton', 'spinner', 'title'])
};

/**
* Default props.
*
* @type {{}}
*/
Loader.defaultProps = {
variant: 'skeleton'
};

export { Loader as default, Loader };
102 changes: 59 additions & 43 deletions src/components/router/__tests__/__snapshots__/router.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Router Component should handle unique route settings: settings 1`] = `
<Switch>
<Route
component={[Function]}
exact={false}
key="/lorem"
path="/lorem"
/>
<Route
component={[Function]}
exact={false}
key="/ipsum"
path="/ipsum"
/>
</Switch>
<Suspense
fallback={
<Loader
variant="title"
/>
}
>
<Switch>
<Route
component={[Function]}
exact={false}
key="/lorem"
path="/lorem"
/>
<Route
component={[Function]}
exact={false}
key="/ipsum"
path="/ipsum"
/>
</Switch>
</Suspense>
`;

exports[`Router Component should pass customized props to routed components: routeDetail and location parsedSearch props 1`] = `
Expand Down Expand Up @@ -51,33 +59,41 @@ Object {
`;

exports[`Router Component should render a basic component: basic 1`] = `
<Switch>
<Route
exact={true}
key="/rhel-sw/all"
path="/rhel-sw/all"
render={[Function]}
/>
<Route
exact={true}
key="/rhel-sw/:variant"
path="/rhel-sw/:variant"
render={[Function]}
/>
<Route
exact={true}
key="/openshift-sw"
path="/openshift-sw"
render={[Function]}
/>
<Route
exact={true}
key="/optin"
path="/optin"
render={[Function]}
/>
<Redirect
to="/rhel-sw/all"
/>
</Switch>
<Suspense
fallback={
<Loader
variant="title"
/>
}
>
<Switch>
<Route
exact={true}
key="/rhel-sw/all"
path="/rhel-sw/all"
render={[Function]}
/>
<Route
exact={true}
key="/rhel-sw/:variant"
path="/rhel-sw/:variant"
render={[Function]}
/>
<Route
exact={true}
key="/openshift-sw"
path="/openshift-sw"
render={[Function]}
/>
<Route
exact={true}
key="/optin"
path="/optin"
render={[Function]}
/>
<Redirect
to="/rhel-sw/all"
/>
</Switch>
</Suspense>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ exports[`RouterHelpers should return an error route: error route 1`] = `
Object {
"activateOnError": true,
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(OptinView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"disabled": false,
"exact": true,
Expand All @@ -68,11 +67,10 @@ Object {
},
"navRoute": Object {
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(RhelView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"default": true,
"disabled": false,
Expand All @@ -88,11 +86,10 @@ Object {
},
"route": Object {
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(RhelView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"disabled": false,
"exact": true,
Expand All @@ -115,11 +112,10 @@ Object {
},
"navRoute": Object {
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(RhelView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"default": true,
"disabled": false,
Expand All @@ -135,11 +131,10 @@ Object {
},
"route": Object {
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(RhelView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"disabled": false,
"exact": true,
Expand Down Expand Up @@ -170,11 +165,10 @@ Object {
},
"navRoute": Object {
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(RhelView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"default": true,
"disabled": false,
Expand Down Expand Up @@ -211,11 +205,10 @@ Object {
},
"navRoute": Object {
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(RhelView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"disabled": false,
"exact": true,
Expand All @@ -238,11 +231,10 @@ Object {
"route": Object {
"activateOnError": true,
"component": Object {
"$$typeof": Symbol(react.memo),
"WrappedComponent": [Function],
"compare": null,
"displayName": "Connect(OptinView)",
"type": [Function],
"$$typeof": Symbol(react.lazy),
"_ctor": [Function],
"_result": null,
"_status": -1,
},
"disabled": false,
"exact": true,
Expand Down
Loading