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(build, routerTypes): issues/34 dynamic routing baseName #68

Merged
merged 1 commit into from
Aug 2, 2019
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
REACT_APP_UI_VERSION=$npm_package_version
REACT_APP_UI_NAME=subscription-reporting
REACT_APP_UI_DISPLAY_NAME=Subscription Reporting
REACT_APP_UI_DEPLOY_PATH_PREFIX=${UI_DEPLOY_PATH_PREFIX}
PUBLIC_URL=${UI_DEPLOY_PATH_PREFIX}/apps/subscription-reporting/

REACT_APP_AJAX_TIMEOUT=60000
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="%REACT_APP_CONFIG_SERVICE_LOCALES_DEFAULT_LNG%">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INDEED! =)

<head>
<meta charset="utf-8" />
<title>%REACT_APP_UI_DISPLAY_NAME%</title>
Expand Down
1 change: 1 addition & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object {
"PROD_MODE": false,
"REVIEW_MODE": false,
"TEST_MODE": true,
"UI_DEPLOY_PATH_PREFIX": "",
"UI_DISPLAY_NAME": "Subscription Reporting",
"UI_NAME": "subscription-reporting",
"UI_PATH": "/apps/subscription-reporting/",
Expand Down
3 changes: 3 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const TEST_MODE = process.env.REACT_APP_ENV === 'test';

const UI_NAME = process.env.REACT_APP_UI_NAME;

const UI_DEPLOY_PATH_PREFIX = process.env.REACT_APP_UI_DEPLOY_PATH_PREFIX;

const UI_DISPLAY_NAME = process.env.REACT_APP_UI_DISPLAY_NAME;

const UI_PATH = process.env.PUBLIC_URL || '/';
Expand All @@ -52,6 +54,7 @@ const helpers = {
REVIEW_MODE,
TEST_MODE,
UI_NAME,
UI_DEPLOY_PATH_PREFIX,
UI_DISPLAY_NAME,
UI_PATH,
UI_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ exports[`Authorization Component should render a non-connected component authori
}
routes={
Array [
Object {
"component": [Function],
"exact": true,
"id": "overview",
"title": "Subscription Reporting",
"to": "/",
},
Object {
"component": [Function],
"exact": true,
"id": "rhel",
"redirect": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel",
},
Expand Down Expand Up @@ -63,17 +57,11 @@ exports[`Authorization Component should render a non-connected component error:
}
routes={
Array [
Object {
"component": [Function],
"exact": true,
"id": "overview",
"title": "Subscription Reporting",
"to": "/",
},
Object {
"component": [Function],
"exact": true,
"id": "rhel",
"redirect": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ exports[`Router Component should render a basic component: basic 1`] = `
className="curiosity-content"
>
<Switch>
<Route
component={[Function]}
exact={true}
key="/"
path="/"
/>
<Route
component={[Function]}
exact={true}
key="/rhel"
path="/rhel"
/>
<Redirect
to="/rhel"
/>
</Switch>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RouterTypes should return specific properties: baseName 1`] = `"/apps/subscription-reporting/"`;
exports[`RouterTypes should return a generated baseName: app base lorem base name 1`] = `"/apps/lorem"`;

exports[`RouterTypes should return a generated baseName: app base name 1`] = `"/apps/appName"`;

exports[`RouterTypes should return a generated baseName: beta app base name 1`] = `"/beta/apps/appName"`;

exports[`RouterTypes should return a generated baseName: beta app lorem base name 1`] = `"/beta/apps/lorem"`;

exports[`RouterTypes should return specific properties: routes 1`] = `
Array [
Object {
"component": [Function],
"exact": true,
"id": "overview",
"title": "Subscription Reporting",
"to": "/",
},
Object {
"component": [Function],
"exact": true,
"id": "rhel",
"redirect": true,
"title": "Red Hat Enterprise Linux",
"to": "/rhel",
},
Expand Down
35 changes: 33 additions & 2 deletions src/components/router/__tests__/routerTypes.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
import { baseName, routes } from '../routerTypes';
import { baseName, dynamicBaseName, routes } from '../routerTypes';

describe('RouterTypes', () => {
it('should return specific properties', () => {
expect(baseName).toMatchSnapshot('baseName');
expect(baseName).toBeDefined();
expect(dynamicBaseName).toBeDefined();
expect(routes).toMatchSnapshot('routes');
});

it('should return a generated baseName', () => {
expect(
dynamicBaseName({
pathName: '/apps/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('app base name');

expect(
dynamicBaseName({
pathName: '/apps/lorem/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('app base lorem base name');

expect(
dynamicBaseName({
pathName: '/beta/apps/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('beta app base name');

expect(
dynamicBaseName({
pathName: '/beta/apps/lorem/appName',
pathPrefix: '/beta'
})
).toMatchSnapshot('beta app lorem base name');
});
});
33 changes: 22 additions & 11 deletions src/components/router/routerTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,41 @@ import { helpers } from '../../common/helpers';
import RhelView from '../rhelView/rhelView';

/**
* Return the application base directory.
* @type {string}
* Return an assumed dynamic route baseName directory
* based on a predictable platform directory depth of
* /[OPTIONAL]/apps/[APP NAME]
*
* @param pathName {string}
* @param pathPrefix {string}
* @return {string}
*/
const baseName = helpers.UI_PATH;
const dynamicBaseName = ({ pathName, pathPrefix }) => {
const path = pathName.split('/');

path.shift();

const pathSlice = pathPrefix && new RegExp(path[0]).test(pathPrefix) ? 3 : 2;

return `/${path.slice(0, pathSlice).join('/')}`;
};

const baseName =
(helpers.TEST_MODE && '/') ||
dynamicBaseName({ pathName: window.location.pathname, pathPrefix: helpers.UI_DEPLOY_PATH_PREFIX });

/**
* Return array of objects that describe navigation
* @return {array}
*/
const routes = [
{
title: 'Subscription Reporting',
id: 'overview',
to: '/',
component: RhelView,
exact: true
},
{
title: 'Red Hat Enterprise Linux',
id: 'rhel',
to: '/rhel',
redirect: true,
component: RhelView,
exact: true
}
];

export { routes as default, baseName, routes };
export { routes as default, baseName, dynamicBaseName, routes };
2 changes: 1 addition & 1 deletion tests/__snapshots__/html.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Index.HTML should have a specific html output: html output 1`] = `
"
<!doctype html>
<html lang=\\"en\\">
<html lang=\\"en-US\\">
<head>
<meta charset=\\"utf-8\\"/>
<title>Subscription Reporting
Expand Down