| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | /* eslint-disable @typescript-eslint/no-unsafe-member-access */ | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | import { Provider } from 'react-redux'; | 
					
						
							|  |  |  | import ShallowRenderer from 'react-test-renderer/shallow'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import FourOhFourPage from '../../src/pages/404'; | 
					
						
							|  |  |  | import Certification from '../../src/pages/certification'; | 
					
						
							| 
									
										
										
										
											2021-08-02 15:39:40 +02:00
										 |  |  | import Learn from '../../src/pages/learn'; | 
					
						
							|  |  |  | import { createStore } from '../../src/redux/createStore'; | 
					
						
							|  |  |  | import layoutSelector from './layout-selector'; | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-30 01:48:58 +02:00
										 |  |  | jest.mock('../../src/analytics'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  | const store = createStore(); | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | interface NameAndProps { | 
					
						
							|  |  |  |   props: Record<string, unknown>; | 
					
						
							|  |  |  |   name: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function getComponentNameAndProps( | 
					
						
							|  |  |  |   elementType: React.JSXElementConstructor<never>, | 
					
						
							|  |  |  |   pathname: string | 
					
						
							|  |  |  | ): NameAndProps { | 
					
						
							|  |  |  |   // eslint-disable-next-line testing-library/render-result-naming-convention
 | 
					
						
							|  |  |  |   const shallow = ShallowRenderer.createRenderer(); | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  |   const LayoutReactComponent = layoutSelector({ | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  |     element: { type: elementType, props: {}, key: '' }, | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  |     props: { | 
					
						
							|  |  |  |       location: { | 
					
						
							|  |  |  |         pathname | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   shallow.render(<Provider store={store}>{LayoutReactComponent}</Provider>); | 
					
						
							| 
									
										
										
										
											2021-07-20 19:51:16 +05:30
										 |  |  |   const view = shallow.getRenderOutput(); | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  |   return { | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  |     props: view.props as Record<string, unknown>, | 
					
						
							|  |  |  |     // eslint-disable-next-line @typescript-eslint/ban-ts-comment
 | 
					
						
							|  |  |  |     // @ts-ignore
 | 
					
						
							|  |  |  |     // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
 | 
					
						
							| 
									
										
										
										
											2021-07-20 19:51:16 +05:30
										 |  |  |     name: view.type.WrappedComponent.displayName | 
					
						
							| 
									
										
										
										
											2021-08-09 01:30:31 -07:00
										 |  |  |     // TODO: Revisit this when react-test-renderer is replaced with
 | 
					
						
							|  |  |  |     // react-testing-library
 | 
					
						
							| 
									
										
										
										
											2021-02-18 08:11:05 +03:00
										 |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('Challenge path should have DefaultLayout and no footer', () => { | 
					
						
							|  |  |  |   const challengePath = | 
					
						
							|  |  |  |     '/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements'; | 
					
						
							|  |  |  |   const compnentObj = getComponentNameAndProps(Learn, challengePath); | 
					
						
							|  |  |  |   expect(compnentObj.name).toEqual('DefaultLayout'); | 
					
						
							|  |  |  |   expect(compnentObj.props.showFooter).toEqual(false); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('SuperBlock path should have DefaultLayout and footer', () => { | 
					
						
							|  |  |  |   const superBlockPath = '/learn/responsive-web-design/'; | 
					
						
							|  |  |  |   const compnentObj = getComponentNameAndProps(Learn, superBlockPath); | 
					
						
							|  |  |  |   expect(compnentObj.name).toEqual('DefaultLayout'); | 
					
						
							|  |  |  |   expect(compnentObj.props.showFooter).toEqual(true); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('i18l challenge path should have DefaultLayout and no footer', () => { | 
					
						
							|  |  |  |   const challengePath = | 
					
						
							|  |  |  |     'espanol/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements/'; | 
					
						
							|  |  |  |   const compnentObj = getComponentNameAndProps(Learn, challengePath); | 
					
						
							|  |  |  |   expect(compnentObj.name).toEqual('DefaultLayout'); | 
					
						
							|  |  |  |   expect(compnentObj.props.showFooter).toEqual(false); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('i18l superBlock path should have DefaultLayout and footer', () => { | 
					
						
							|  |  |  |   const superBlockPath = '/learn/responsive-web-design/'; | 
					
						
							|  |  |  |   const compnentObj = getComponentNameAndProps(Learn, superBlockPath); | 
					
						
							|  |  |  |   expect(compnentObj.name).toEqual('DefaultLayout'); | 
					
						
							|  |  |  |   expect(compnentObj.props.showFooter).toEqual(true); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('404 page should have DefaultLayout and footer', () => { | 
					
						
							|  |  |  |   const challengePath = | 
					
						
							|  |  |  |     '/espanol/learn/responsive-web-design/basic-html-and-html5/say-hello-to-html-elements/'; | 
					
						
							|  |  |  |   const compnentObj = getComponentNameAndProps(FourOhFourPage, challengePath); | 
					
						
							|  |  |  |   expect(compnentObj.name).toEqual('DefaultLayout'); | 
					
						
							|  |  |  |   expect(compnentObj.props.showFooter).toEqual(true); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('Certification path should have CertificationLayout', () => { | 
					
						
							|  |  |  |   const challengePath = | 
					
						
							|  |  |  |     '/certification/mot01/javascript-algorithms-and-data-structures/'; | 
					
						
							|  |  |  |   const compnentObj = getComponentNameAndProps(Certification, challengePath); | 
					
						
							|  |  |  |   expect(compnentObj.name).toEqual('CertificationLayout'); | 
					
						
							|  |  |  | }); |