Skip to content

Commit

Permalink
CQ-4282110-Page with no extension is not rendered (#58)
Browse files Browse the repository at this point in the history
* CQ-4282110-Page with no extension is not rendered

* CQ-4282110-Page with no extension is not rendered
  • Loading branch information
sharanyavinod authored Nov 1, 2019
1 parent cec9597 commit 337fb3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions react-app/src/RouteHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export const withRoute = (WrappedComponent, extension) => {

extension = extension || 'html';

// Context path + route path + extension
return <Route key={ routePath } path={ '(.*)' + routePath + '.' + extension } render={ (routeProps) => {
// Context path + route path + optional extension
return <Route key={ routePath } exact path={ '(.*)' + routePath + '(.' + extension + ')?'} render={ (routeProps) => {
return <WrappedComponent {...this.props} {...routeProps}/>;
} } />
}
}
};
};
26 changes: 25 additions & 1 deletion react-app/tests/RouteHelper.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { BrowserRouter, MemoryRouter } from 'react-router-dom';
import { getVerifyObserver } from './Utils';
import { RouteListener, withRoute } from '../src/RouteHelper';
import { ModelManager } from '@adobe/cq-spa-page-model-manager';
Expand Down Expand Up @@ -71,5 +71,29 @@ describe('RouterHelper ->', () => {
let WrappedComponent = withRoute(RouteContent);
ReactDOM.render(<BrowserRouter><WrappedComponent cqModel={cqModel}/></BrowserRouter>, rootNode);
});

it('should render page with extension', () => {
let WrappedComponent = withRoute(RouteContent, 'extension');
ReactDOM.render(
<MemoryRouter initialEntries={[CUSTOM_ROUTE_PATH + '.extension']}>
<WrappedComponent cqPath={CUSTOM_ROUTE_PATH} />
</MemoryRouter>,
rootNode
);

expect(rootNode.querySelector('.' + ROUTE_CONTENT_CLASS_NAME)).to.not.be.null;
});

it('should render page if extension is not provided', () => {
let WrappedComponent = withRoute(RouteContent);
ReactDOM.render(
<MemoryRouter initialEntries={[CUSTOM_ROUTE_PATH]}>
<WrappedComponent cqPath={CUSTOM_ROUTE_PATH}/>
</MemoryRouter>,
rootNode
);

expect(rootNode.querySelector('.' + ROUTE_CONTENT_CLASS_NAME)).to.not.be.null;
});
});
});

0 comments on commit 337fb3d

Please sign in to comment.