| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  | /* global cy */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('Username input field', () => { | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							|  |  |  |     cy.visit('/'); | 
					
						
							|  |  |  |     cy.contains("Get started (it's free)").click({ force: true }); | 
					
						
							|  |  |  |     cy.visit('/settings'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Setting aliases here
 | 
					
						
							|  |  |  |     cy.get('input[name=username-settings]').as('usernameInput'); | 
					
						
							|  |  |  |     cy.get('form#usernameSettings').as('usernameForm'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should be possible to type', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('twaha', { force: true }) | 
					
						
							|  |  |  |       .should('have.attr', 'value', 'twaha'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should show message when validating name', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('twaha', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.contains('Validating username...') | 
					
						
							|  |  |  |       .should('have.attr', 'role', 'alert') | 
					
						
							|  |  |  |       // We are checking for classes here to check for proper styling
 | 
					
						
							|  |  |  |       // This will be replaced with Percy in the future
 | 
					
						
							|  |  |  |       .should('have.class', 'alert alert-info'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should show username is available if it is', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('brad', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username is available') | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |       .should('be.visible') | 
					
						
							|  |  |  |       .should('have.attr', 'role', 'alert') | 
					
						
							|  |  |  |       // We are checking for classes here to check for proper styling
 | 
					
						
							|  |  |  |       // This will be replaced with Percy in the future
 | 
					
						
							|  |  |  |       .should('have.class', 'alert alert-success'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should info message if username is available', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('mrugesh', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.contains( | 
					
						
							|  |  |  |       'Please note, changing your username will also change ' + | 
					
						
							|  |  |  |         'the URL to your profile and your certifications.' | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |       .should('be.visible') | 
					
						
							|  |  |  |       .should('have.attr', 'role', 'alert') | 
					
						
							|  |  |  |       // We are checking for classes here to check for proper styling
 | 
					
						
							|  |  |  |       // This will be replaced with Percy in the future
 | 
					
						
							|  |  |  |       .should('have.class', 'alert alert-info'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // eslint-disable-next-line
 | 
					
						
							|  |  |  |   it('Should be able to click the `Save` button if username is avalable', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('oliver', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.get('@usernameForm').within(() => { | 
					
						
							|  |  |  |       cy.contains('Save').should('not.be.disabled'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should show username is unavailable if it is', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('twaha', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username not available') | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |       .should('be.visible') | 
					
						
							|  |  |  |       .should('have.attr', 'role', 'alert') | 
					
						
							|  |  |  |       // We are checking for classes here to check for proper styling
 | 
					
						
							|  |  |  |       // This will be replaced with Percy in the future
 | 
					
						
							|  |  |  |       .should('have.class', 'alert alert-warning'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // eslint-disable-next-line
 | 
					
						
							|  |  |  |   it('Should not be possible to click the `Save` button if username is unavailable', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('twaha', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username is available').should('not.exist'); | 
					
						
							|  |  |  |     cy.contains('Username not available').should('not.exist'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |     cy.contains( | 
					
						
							|  |  |  |       'Please note, changing your username will also change ' + | 
					
						
							|  |  |  |         'the URL to your profile and your certifications.' | 
					
						
							| 
									
										
										
										
											2020-12-07 16:02:52 +06:00
										 |  |  |     ).should('not.exist'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     cy.get('@usernameForm').contains('Save').should('be.disabled'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should not show anything if user types their current name', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('developmentuser', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     cy.get('@usernameForm').contains('Save').should('be.disabled'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // eslint-disable-next-line max-len
 | 
					
						
							|  |  |  |   it('Should not be possible to click the `Save` button if user types their current name', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('developmentuser', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     cy.get('@usernameForm').contains('Save').should('be.disabled'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should show warning if username includes invalid character', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('Quincy Larson', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username "quincy larson" contains invalid characters') | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |       .should('be.visible') | 
					
						
							|  |  |  |       .should('have.attr', 'role', 'alert') | 
					
						
							|  |  |  |       // We are checking for classes here to check for proper styling
 | 
					
						
							|  |  |  |       // This will be replaced with Percy in the future
 | 
					
						
							|  |  |  |       .should('have.class', 'alert alert-danger'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // eslint-disable-next-line max-len
 | 
					
						
							|  |  |  |   it('Should not be able to click the `Save` button if username includes invalid character', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('Quincy Larson', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     cy.get('@usernameForm').contains('Save').should('be.disabled'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should change username if `Save` button is clicked', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('quincy', { force: true }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username is available'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 00:31:46 +05:30
										 |  |  |     cy.get('@usernameForm').contains('Save').click({ force: true }); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |     cy.contains('Account Settings for quincy').should('be.visible'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.resetUsername(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should show flash message showing username has been updated', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('nhcarrigan', { force: true }); | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username is available'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |     cy.get('@usernameInput').type('{enter}', { force: true, release: false }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.contains('We have updated your username to nhcarrigan') | 
					
						
							|  |  |  |       .should('be.visible') | 
					
						
							|  |  |  |       // We are checking for classes here to check for proper styling
 | 
					
						
							|  |  |  |       // This will be replaced with Percy in the future
 | 
					
						
							|  |  |  |       .should( | 
					
						
							|  |  |  |         'have.class', | 
					
						
							|  |  |  |         'flash-message alert alert-success alert-dismissable' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.resetUsername(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should be able to close the shown flash message', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('bjorno', { force: true }); | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username is available'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  |     cy.get('@usernameInput').type('{enter}', { force: true, release: false }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.contains('We have updated your username to bjorno').within(() => { | 
					
						
							|  |  |  |       cy.get('button').click(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-07 16:02:52 +06:00
										 |  |  |     cy.contains('We have updated your username to bjorno').should('not.exist'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     cy.resetUsername(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('Should change username if enter is pressed', () => { | 
					
						
							|  |  |  |     cy.get('@usernameInput') | 
					
						
							|  |  |  |       .clear({ force: true }) | 
					
						
							|  |  |  |       .type('symbol', { force: true }); | 
					
						
							| 
									
										
										
										
											2020-12-16 02:02:52 -06:00
										 |  |  |     cy.contains('Username is available'); | 
					
						
							| 
									
										
										
										
											2020-11-22 00:09:38 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     cy.get('@usernameInput').type('{enter}', { force: true, release: false }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.contains('Account Settings for symbol').should('be.visible'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cy.resetUsername(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |