| 
									
										
										
										
											2020-09-04 22:27:21 +06:00
										 |  |  | /* global cy */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  | const selectors = { | 
					
						
							|  |  |  |   heading: "[data-test-label='landing-header']", | 
					
						
							|  |  |  |   smallCallToAction: "[data-test-label='landing-small-cta']", | 
					
						
							| 
									
										
										
										
											2020-10-22 19:27:41 +03:00
										 |  |  |   navigationLinks: '.nav-list', | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |   avatarContainer: '.avatar-container', | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |   defaultAvatar: '.avatar-container', | 
					
						
							| 
									
										
										
										
											2021-05-11 03:45:16 +09:00
										 |  |  |   menuButton: '.toggle-button-nav', | 
					
						
							|  |  |  |   avatarImage: '.avatar-container .avatar' | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  | let appHasStarted; | 
					
						
							|  |  |  | function spyOnListener(win) { | 
					
						
							|  |  |  |   const addListener = win.EventTarget.prototype.addEventListener; | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |   win.EventTarget.prototype.addEventListener = function (name) { | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |     if (name === 'click') { | 
					
						
							|  |  |  |       appHasStarted = true; | 
					
						
							|  |  |  |       win.EventTarget.prototype.addEventListener = addListener; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return addListener.apply(this, arguments); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function waitForAppStart() { | 
					
						
							|  |  |  |   return new Promise(resolve => { | 
					
						
							|  |  |  |     const isReady = () => { | 
					
						
							|  |  |  |       if (appHasStarted) { | 
					
						
							|  |  |  |         return resolve(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return setTimeout(isReady, 0); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     isReady(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 22:27:21 +06:00
										 |  |  | describe('Navbar', () => { | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |     appHasStarted = false; | 
					
						
							|  |  |  |     cy.visit('/', { | 
					
						
							|  |  |  |       onBeforeLoad: spyOnListener | 
					
						
							|  |  |  |     }).then(waitForAppStart); | 
					
						
							|  |  |  |     cy.viewport(1300, 660); | 
					
						
							| 
									
										
										
										
											2020-09-04 22:27:21 +06:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should render properly', () => { | 
					
						
							|  |  |  |     cy.get('#universal-nav').should('be.visible'); | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |     cy.get('#universal-nav').should('have.class', 'universal-nav'); | 
					
						
							| 
									
										
										
										
											2020-09-04 22:27:21 +06:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it( | 
					
						
							|  |  |  |     'Should take user to learn page when clicked on ' + 'the freeCodeCamp logo', | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       cy.get('.universal-nav-middle').within(() => { | 
					
						
							|  |  |  |         cy.get('svg').click(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       cy.url().should('include', '/learn'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |   it('Should have a "Sign in" button', () => { | 
					
						
							|  |  |  |     cy.contains("[data-test-label='landing-small-cta']", 'Sign in'); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // have the curriculum and CTA on landing and /learn pages.
 | 
					
						
							|  |  |  |   it( | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |     'Should have `Radio`, `Forum`, and `Curriculum` links on landing and learn pages' + | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |       'page when not signed in', | 
					
						
							|  |  |  |     () => { | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |       cy.get(selectors.menuButton).click(); | 
					
						
							| 
									
										
										
										
											2020-10-22 19:27:41 +03:00
										 |  |  |       cy.get(selectors.navigationLinks).contains('Forum'); | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |       cy.get(selectors.navigationLinks).contains('Curriculum').click(); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |       cy.url().should('include', '/learn'); | 
					
						
							| 
									
										
										
										
											2020-10-22 19:27:41 +03:00
										 |  |  |       cy.get(selectors.navigationLinks).contains('Curriculum'); | 
					
						
							|  |  |  |       cy.get(selectors.navigationLinks).contains('Forum'); | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |       cy.get(selectors.navigationLinks).contains('Radio'); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it( | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     'Should have `Sign in` link on landing and learn pages' + | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |       ' when not signed in', | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |     () => { | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |       cy.contains(selectors.smallCallToAction, 'Sign in'); | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |       cy.get(selectors.menuButton).click(); | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |       cy.get(selectors.navigationLinks).contains('Curriculum').click(); | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |       cy.contains(selectors.smallCallToAction, 'Sign in'); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should have `Profile` link when user is signed in', () => { | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |     cy.login(); | 
					
						
							|  |  |  |     cy.get(selectors.menuButton).click(); | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     cy.get(selectors.navigationLinks).contains('Profile').click(); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |     cy.url().should('include', '/developmentuser'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should have a profile image with class `default-border`', () => { | 
					
						
							| 
									
										
										
										
											2021-01-27 12:34:29 -08:00
										 |  |  |     cy.login(); | 
					
						
							|  |  |  |     cy.get(selectors.avatarContainer).should('have.class', 'default-border'); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:21:16 +03:00
										 |  |  |     cy.get(selectors.defaultAvatar).should('exist'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-05-11 03:45:16 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('Should have a profile image with dimensions that are <= 31px', () => { | 
					
						
							|  |  |  |     cy.login(); | 
					
						
							|  |  |  |     cy.get(selectors.avatarImage).invoke('width').should('lte', 31); | 
					
						
							|  |  |  |     cy.get(selectors.avatarImage).invoke('height').should('lte', 31); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-09-04 22:27:21 +06:00
										 |  |  | }); |