|
| 1 | +beforeEach(() => { |
| 2 | + const user1 = Cypress.env('user1'); |
| 3 | + const user2 = Cypress.env('user2'); |
| 4 | + |
| 5 | + cy.request('POST', 'http://localhost:3001/api/test/reset'); |
| 6 | + |
| 7 | + cy.createUser(user1); |
| 8 | + cy.createUser(user2); |
| 9 | + |
| 10 | + cy.login({ username: user1.username, password: user1.password }); |
| 11 | +}); |
| 12 | + |
| 13 | +describe('navigating to search page', () => { |
| 14 | + it('user can navigate to search page on desktop', () => { |
| 15 | + cy.get('[data-cy=desktop-search-btn]').click(); |
| 16 | + |
| 17 | + cy.url().should('include', '/search'); |
| 18 | + cy.get('input[placeholder="Search"]').should('be.visible'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('user can navigate to search page on mobile', () => { |
| 22 | + cy.viewport('iphone-6'); |
| 23 | + cy.get('[data-cy=mobile-search-btn]').click(); |
| 24 | + |
| 25 | + cy.url().should('include', '/search'); |
| 26 | + cy.get('input[placeholder="Search"]').should('be.visible'); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +describe('searching for users', () => { |
| 31 | + beforeEach(() => { |
| 32 | + cy.visit('http://localhost:3000/search'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('displays no results if input is empty', () => { |
| 36 | + const user1 = Cypress.env('user1'); |
| 37 | + const user2 = Cypress.env('user2'); |
| 38 | + |
| 39 | + cy.contains(user1.username).should('not.be.exist'); |
| 40 | + cy.contains(user2.username).should('not.be.exist'); |
| 41 | + |
| 42 | + cy.get('input[placeholder="Search"]').type('a').clear(); |
| 43 | + |
| 44 | + cy.contains(user1.username).should('not.be.exist'); |
| 45 | + cy.contains(user2.username).should('not.be.exist'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('user can search for users by username', () => { |
| 49 | + const user1 = Cypress.env('user1'); |
| 50 | + const user2 = Cypress.env('user2'); |
| 51 | + |
| 52 | + cy.contains(user1.username).should('not.be.exist'); |
| 53 | + cy.contains(user2.username).should('not.be.exist'); |
| 54 | + |
| 55 | + cy.get('input[placeholder="Search"]').type(user1.username); |
| 56 | + |
| 57 | + cy.contains(user1.username).should('be.visible'); |
| 58 | + cy.contains(user2.username).should('not.be.exist'); |
| 59 | + |
| 60 | + cy.get('input[placeholder="Search"]').clear().type(user2.username); |
| 61 | + |
| 62 | + cy.contains(user1.username).should('not.be.exist'); |
| 63 | + cy.contains(user2.username).should('be.visible'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('user can search for users by full name', () => { |
| 67 | + const user1 = Cypress.env('user1'); |
| 68 | + const user2 = Cypress.env('user2'); |
| 69 | + |
| 70 | + cy.contains(user1.fullName).should('not.be.exist'); |
| 71 | + cy.contains(user2.fullName).should('not.be.exist'); |
| 72 | + |
| 73 | + cy.get('input[placeholder="Search"]').type(user1.fullName); |
| 74 | + |
| 75 | + cy.contains(user1.fullName).should('be.visible'); |
| 76 | + cy.contains(user2.fullName).should('not.be.exist'); |
| 77 | + |
| 78 | + cy.get('input[placeholder="Search"]').clear().type(user2.fullName); |
| 79 | + |
| 80 | + cy.contains(user1.fullName).should('not.be.exist'); |
| 81 | + cy.contains(user2.fullName).should('be.visible'); |
| 82 | + }); |
| 83 | + |
| 84 | + it('user can search for users by username case-insensitively', () => { |
| 85 | + const user1 = Cypress.env('user1'); |
| 86 | + |
| 87 | + cy.contains(user1.username).should('not.be.exist'); |
| 88 | + |
| 89 | + cy.get('input[placeholder="Search"]').type(user1.username.toUpperCase()); |
| 90 | + |
| 91 | + cy.contains(user1.username).should('be.visible'); |
| 92 | + }); |
| 93 | + |
| 94 | + it('user can search for users by full name case-insensitively', () => { |
| 95 | + const user1 = Cypress.env('user1'); |
| 96 | + |
| 97 | + cy.contains(user1.fullName).should('not.be.exist'); |
| 98 | + |
| 99 | + cy.get('input[placeholder="Search"]').type(user1.fullName.toUpperCase()); |
| 100 | + |
| 101 | + cy.contains(user1.fullName).should('be.visible'); |
| 102 | + }); |
| 103 | + |
| 104 | + it('user can search for users by partial username', () => { |
| 105 | + const user1 = Cypress.env('user1'); |
| 106 | + |
| 107 | + cy.contains(user1.username).should('not.be.exist'); |
| 108 | + |
| 109 | + cy.get('input[placeholder="Search"]').type(user1.username.slice(0, 3)); |
| 110 | + |
| 111 | + cy.contains(user1.username).should('be.visible'); |
| 112 | + }); |
| 113 | + |
| 114 | + it('user can search for users by partial full name', () => { |
| 115 | + const user1 = Cypress.env('user1'); |
| 116 | + |
| 117 | + cy.contains(user1.fullName).should('not.be.exist'); |
| 118 | + |
| 119 | + cy.get('input[placeholder="Search"]').type(user1.fullName.slice(0, 3)); |
| 120 | + |
| 121 | + cy.contains(user1.fullName).should('be.visible'); |
| 122 | + }); |
| 123 | + |
| 124 | + it('clicking on a user navigates to their profile', () => { |
| 125 | + const user1 = Cypress.env('user1'); |
| 126 | + |
| 127 | + cy.get('input[placeholder="Search"]').type(user1.username); |
| 128 | + cy.contains(user1.username).click(); |
| 129 | + |
| 130 | + cy.url().should('include', `/${user1.username}`); |
| 131 | + }); |
| 132 | +}); |
0 commit comments