|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +describe('Page Object Checks', () => { |
| 4 | + beforeEach(() => { |
| 5 | + cy.visit(Cypress.env('mainUrl')); |
| 6 | + |
| 7 | + }); |
| 8 | + |
| 9 | + it('loads main search dashboard', () => { |
| 10 | + cy.url().should('eq', 'http://localhost:3000/') |
| 11 | + cy.title().should('eq', 'Biobot Search Example') |
| 12 | + cy.get('.app-logo').should('exist') |
| 13 | + cy.get('.app-header').contains('Welcome to the Biobot Test Kit Search App') |
| 14 | + cy.get('.search-box-container').should('be.visible'); |
| 15 | + |
| 16 | + }); |
| 17 | + |
| 18 | + it('should always display label Id placeholder text in the search box', () => { |
| 19 | + cy.get('#mui-2-label').should('contain.text', 'Label Id') |
| 20 | + cy.get('#mui-2').click() |
| 21 | + cy.get('#mui-2-label').should('contain.text', 'Label Id') |
| 22 | + cy.get('#mui-2').type('populate') |
| 23 | + cy.get('#mui-2-label').should('contain.text', 'Label Id') |
| 24 | + cy.get('#mui-2').clear() |
| 25 | + cy.get('.app').click() |
| 26 | + cy.get('#mui-2-label').should('contain.text', 'Label Id') |
| 27 | + |
| 28 | + }); |
| 29 | + |
| 30 | + it('should display search/clear buttons under correct circumstances', () => { |
| 31 | + cy.getBySel('SearchIcon').should('exist') |
| 32 | + cy.getBySel('CloseIcon').should('not.exist') |
| 33 | + cy.get('#mui-2').type('populate') |
| 34 | + cy.getBySel('CloseIcon').should('exist') |
| 35 | + cy.get('#mui-2').clear() |
| 36 | + cy.get('.app').click() |
| 37 | + cy.getBySel('CloseIcon').should('not.exist') |
| 38 | + |
| 39 | + }); |
| 40 | + |
| 41 | + it('should display caption after populating search results', () => { |
| 42 | + cy.addSample(); |
| 43 | + cy.successModalTrue(); |
| 44 | + |
| 45 | + cy.get('caption') |
| 46 | + .should('exist') |
| 47 | + .contains('Table containing test kit shipping data, use the search bar above to search for your test kit'); |
| 48 | + |
| 49 | + }); |
| 50 | + |
| 51 | + it('should display id and shipping columns after populating search results', () => { |
| 52 | + cy.addSample(); |
| 53 | + cy.successModalTrue(); |
| 54 | + cy.get('.MuiTableHead-root') |
| 55 | + .should('exist') |
| 56 | + .and('contains.text', 'Label Id') |
| 57 | + .and('contains.text', 'Shipping Tracking Code'); |
| 58 | + |
| 59 | + }); |
| 60 | + |
| 61 | +}); |
| 62 | + |
| 63 | + |
| 64 | +describe('Common Scenarios', () => { |
| 65 | + beforeEach(() => { |
| 66 | + cy.visit(Cypress.env('mainUrl')); |
| 67 | + |
| 68 | + }); |
| 69 | + |
| 70 | + it('does exact search for random known id and confirms correct formatting', () => { |
| 71 | + |
| 72 | + cy.sampleByDataJson().then((sample) => |
| 73 | + cy.addSampleBySearch(sample) |
| 74 | + ); |
| 75 | + cy.successModalTrue(); |
| 76 | + cy.resultsTrue(); |
| 77 | + cy.regexLabelId(); |
| 78 | + cy.regexTrackingId(); |
| 79 | + |
| 80 | + }); |
| 81 | + |
| 82 | + it('does exact search for multiple random known ids and confirms correct formatting', () => { |
| 83 | + //this can be modified to change the number of label ids we want to grab or even update it to always run through the entire list. |
| 84 | + for (let i = 0; i < 5; i++) { |
| 85 | + cy.sampleByDataJson().then((sample) => |
| 86 | + cy.addSampleBySearch(sample) |
| 87 | + ); |
| 88 | + } |
| 89 | + cy.successModalTrue(); |
| 90 | + cy.resultsTrue(); |
| 91 | + cy.regexLabelId(); |
| 92 | + cy.regexTrackingId(); |
| 93 | + |
| 94 | + }); |
| 95 | + |
| 96 | + it('successfully populates a single kit id', () => { |
| 97 | + cy.addSample(); |
| 98 | + cy.successModalTrue(); |
| 99 | + cy.resultsTrue(); |
| 100 | + cy.regexLabelId(); |
| 101 | + cy.regexTrackingId(); |
| 102 | + |
| 103 | + }); |
| 104 | + |
| 105 | + it('successfully populates multiple kit ids', () => { |
| 106 | + //pass in however many we want to populate here. |
| 107 | + cy.addSample(5); |
| 108 | + cy.successModalTrue(); |
| 109 | + cy.resultsTrue(); |
| 110 | + cy.regexLabelId(); |
| 111 | + cy.regexTrackingId(); |
| 112 | + |
| 113 | + }); |
| 114 | + |
| 115 | + it('does partial search for known and existing kit id', () => { |
| 116 | + cy.addSampleBySearch('007') |
| 117 | + cy.successModalTrue(); |
| 118 | + cy.regexLabelId(); |
| 119 | + cy.regexTrackingId(); |
| 120 | + |
| 121 | + }); |
| 122 | + |
| 123 | + it('does partial search for multiple known and existing kit ids', () => { |
| 124 | + cy.addSampleBySearch('007') |
| 125 | + cy.successModalTrue() |
| 126 | + cy.addSampleBySearch('008') |
| 127 | + cy.successModalTrue(); |
| 128 | + cy.regexLabelId(); |
| 129 | + cy.regexTrackingId(); |
| 130 | + |
| 131 | + }); |
| 132 | + |
| 133 | + it('dismiss modal after approximately 7 seconds', () => { |
| 134 | + cy.addSample(); |
| 135 | + cy.successModalTrue(); |
| 136 | + |
| 137 | + cy.get('.Toastify__toast-container').should('exist') |
| 138 | + //normally try to avoid waits with cypress, but the goal here was just to make sure modals will always remain visible for at least 7 seconds. |
| 139 | + .wait(7000) |
| 140 | + .should('not.exist'); |
| 141 | + |
| 142 | + }); |
| 143 | + |
| 144 | + it('dimiss modal when user closes manually', () => { |
| 145 | + cy.addSample(); |
| 146 | + cy.successModalTrue(); |
| 147 | + |
| 148 | + cy.get('.Toastify__toast-container').should('exist') |
| 149 | + cy.get('.Toastify__close-button').click() |
| 150 | + cy.get('.Toastify__toast-container').should('not.exist'); |
| 151 | + |
| 152 | + }); |
| 153 | + |
| 154 | + it('clear button removes all previous results', () => { |
| 155 | + cy.addSample(5); |
| 156 | + cy.successModalTrue(); |
| 157 | + cy.addSampleBySearch('007'); |
| 158 | + cy.resultsTrue(); |
| 159 | + |
| 160 | + cy.get('.MuiButtonBase-root').click() |
| 161 | + cy.get('.results-container').should('not.exist'); |
| 162 | + |
| 163 | + }); |
| 164 | + |
| 165 | +}); |
| 166 | + |
| 167 | + |
| 168 | +describe('Exercise API directly', () => { |
| 169 | + |
| 170 | + it('gets an API response from shipping_data label_id', () => { |
| 171 | + const labelId = '22-252-1407' |
| 172 | + cy.request(Cypress.env('apiUrl') + '/shipping_data?label_id=' + labelId).as('apiReq') |
| 173 | + cy.get('@apiReq').then( |
| 174 | + (response) => { |
| 175 | + expect(response.status).to.eq(200) |
| 176 | + expect(response.body[0]).to.have.property('id') |
| 177 | + expect(response.body[0]).to.have.property('label_id', labelId) |
| 178 | + expect(response.body[0]).to.have.property('shipping_tracking_code'); |
| 179 | + }) |
| 180 | + }); |
| 181 | + |
| 182 | +}); |
| 183 | + |
| 184 | + |
| 185 | +describe('Error Scenarios', () => { |
| 186 | + beforeEach(() => { |
| 187 | + cy.visit(Cypress.env('mainUrl')); |
| 188 | + |
| 189 | + }); |
| 190 | + |
| 191 | + it('displays error modal for no results found', () => { |
| 192 | + cy.get('#mui-2').type('foo').type('{enter}') |
| 193 | + cy.errorModalTrue(); |
| 194 | + |
| 195 | + }); |
| 196 | + |
| 197 | + it('displays error modal when clicking search button without criteria', () => { |
| 198 | + //was expecting there to be more built in elements that used the data-testid attribute, but discovered there weren't many as it stands. |
| 199 | + //ideally we could add more of these data-testid attributes to help with maintenance. |
| 200 | + cy.getBySel('SearchIcon').click() |
| 201 | + cy.errorModalTrue(); |
| 202 | + |
| 203 | + }); |
| 204 | + |
| 205 | + it('should generate and search for common bad strings', () => { |
| 206 | + //this can be modified to change the number of bad strings we want to try here or even update it to always run through the entire list. |
| 207 | + for (let i = 0; i < 5; i++) { |
| 208 | + cy.badString().then((ns) => |
| 209 | + cy.addSampleBySearch(ns) |
| 210 | + ); |
| 211 | + } |
| 212 | + }); |
| 213 | + |
| 214 | + it('checks for common injections', () => { |
| 215 | + //arbitrarily picked a few common injection tests using different quote characters. |
| 216 | + cy.get('#mui-2').type(`‘ or 1=1;–`).type('{enter}') |
| 217 | + cy.errorModalTrue(); |
| 218 | + cy.get('#mui-2').clear() |
| 219 | + cy.get('#mui-2').type(`“ or 1=1;–`).type('{enter}') |
| 220 | + cy.errorModalTrue(); |
| 221 | + cy.get('#mui-2').clear() |
| 222 | + cy.get('#mui-2').type(`‘ or ‘abc‘=‘abc‘;–`).type('{enter}') |
| 223 | + cy.errorModalTrue(); |
| 224 | + cy.get('#mui-2').clear() |
| 225 | + cy.get('#mui-2').type(`‘ or ‘ ‘=‘ ‘;–`).type('{enter}') |
| 226 | + cy.errorModalTrue(); |
| 227 | + cy.get('#mui-2').clear() |
| 228 | + |
| 229 | + }); |
| 230 | + |
| 231 | +}); |
| 232 | + |
0 commit comments