|
| 1 | +import persistentCacheTasks from '../../../fixtures/resource/persistent-cache-task/persistent-cache-tasks.json'; |
| 2 | +import persistentCacheTask from '../../../fixtures/resource/persistent-cache-task/persistent-cache-task.json'; |
| 3 | +import failedPersistentCacheTask from '../../../fixtures/resource/persistent-cache-task/failed-persistent-cache-task.json'; |
| 4 | + |
| 5 | +describe('Persistent Cache Tasks', () => { |
| 6 | + beforeEach(() => { |
| 7 | + cy.signin(); |
| 8 | + |
| 9 | + cy.intercept( |
| 10 | + { |
| 11 | + method: 'GET', |
| 12 | + url: '/api/v1/persistent-cache-tasks?page=1&per_page=10000000&scheduler_cluster_id=1', |
| 13 | + }, |
| 14 | + (req) => { |
| 15 | + req.reply({ |
| 16 | + statusCode: 200, |
| 17 | + body: persistentCacheTasks, |
| 18 | + }); |
| 19 | + }, |
| 20 | + ); |
| 21 | + |
| 22 | + cy.intercept( |
| 23 | + { |
| 24 | + method: 'GET', |
| 25 | + url: '/api/v1/persistent-cache-tasks/2865345332?scheduler_cluster_id=1', |
| 26 | + }, |
| 27 | + (req) => { |
| 28 | + req.reply({ |
| 29 | + statusCode: 200, |
| 30 | + body: persistentCacheTask, |
| 31 | + }); |
| 32 | + }, |
| 33 | + ); |
| 34 | + |
| 35 | + cy.visit('/resource/persistent-cache-task/clusters/1/2865345332'); |
| 36 | + cy.viewport(1440, 1080); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('when data is loaded', () => { |
| 40 | + it('click the breadcrumb', () => { |
| 41 | + // Display is loading. |
| 42 | + cy.get('[data-testid="isloading"]').should('be.exist'); |
| 43 | + |
| 44 | + // Check for breadcrumb. |
| 45 | + cy.get('#scheduler-cluster-1').should('be.visible').and('contain', 'scheduler-cluster-1'); |
| 46 | + |
| 47 | + cy.get('#task-id-2865345332').should('have.text', 2865345332); |
| 48 | + cy.get('#scheduler-cluster-1').click(); |
| 49 | + |
| 50 | + // Then I see that the current page is the clusters/1! |
| 51 | + cy.url().should('include', '/resource/persistent-cache-task/clusters/1'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('can display success persistent cache task', () => { |
| 55 | + cy.get('#id').should('have.text', '2865345332'); |
| 56 | + cy.get('#success-task').should('exist'); |
| 57 | + cy.get('#persistent-replica-count').should('have.text', '2'); |
| 58 | + cy.get('#ttl').should('have.text', '7 Days'); |
| 59 | + cy.get('#content-length').should('have.text', '1.59 KiB'); |
| 60 | + cy.get('#piece-length').should('have.text', '4 MiB'); |
| 61 | + cy.get('#application').should('have.text', 'application-1'); |
| 62 | + cy.get('#tag').should('have.text', 'tag-1'); |
| 63 | + |
| 64 | + // Display peers. |
| 65 | + cy.get('#peers').should('exist'); |
| 66 | + |
| 67 | + cy.get('#id-0').should('have.text', '2'); |
| 68 | + cy.get('#hostname-0').should('have.text', 'hostname-2'); |
| 69 | + cy.get('#os-0').should('have.text', 'ios'); |
| 70 | + cy.get('#persistent-0').should('contain', 'Yes'); |
| 71 | + cy.get('#type-0').should('have.text', 'Super'); |
| 72 | + cy.get('#ip-0').should('have.text', '112.3325.44'); |
| 73 | + cy.get('#port-0').should('have.text', '8001'); |
| 74 | + cy.get('#download-port-0').should('have.text', '4001'); |
| 75 | + |
| 76 | + // Go to last page. |
| 77 | + cy.get('.MuiPagination-ul > :nth-child(3) > .MuiButtonBase-root').click(); |
| 78 | + |
| 79 | + cy.get('#hostname-0').should('have.text', 'hostname-5'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('can display failed persistent cache task', () => { |
| 83 | + cy.visit('/resource/persistent-cache-task/clusters/1'); |
| 84 | + |
| 85 | + cy.get('.MuiPagination-ul > :nth-child(3)').click(); |
| 86 | + |
| 87 | + cy.get('#failed-task-1').should('exist'); |
| 88 | + |
| 89 | + cy.intercept( |
| 90 | + { |
| 91 | + method: 'GET', |
| 92 | + url: '/api/v1/persistent-cache-tasks/3870122508?scheduler_cluster_id=1', |
| 93 | + }, |
| 94 | + (req) => { |
| 95 | + req.reply({ |
| 96 | + statusCode: 200, |
| 97 | + body: failedPersistentCacheTask, |
| 98 | + }); |
| 99 | + }, |
| 100 | + ); |
| 101 | + |
| 102 | + // Click the persistent cache task details button. |
| 103 | + cy.get('#card-id-1').click(); |
| 104 | + |
| 105 | + cy.get('#peers').should('not.exist'); |
| 106 | + |
| 107 | + cy.get('#failure-task').should('exist'); |
| 108 | + |
| 109 | + cy.get('#scheduler-cluster-1').click(); |
| 110 | + |
| 111 | + cy.get('#operation-0').click(); |
| 112 | + cy.get(':nth-child(11) > .MuiPaper-root > .MuiList-root > .information_menu__CXV1V > #view-3810320977').click(); |
| 113 | + |
| 114 | + // Then I see that the current page is the persistent cache task details! |
| 115 | + cy.url().should('include', '/resource/persistent-cache-task/clusters/1/3810320977'); |
| 116 | + |
| 117 | + // Then I see that the current page is the persistent cache tasks! |
| 118 | + cy.get('#scheduler-cluster-1').click(); |
| 119 | + |
| 120 | + // Display a list of persistent cache tasks. |
| 121 | + cy.get('#table').click(); |
| 122 | + |
| 123 | + cy.get('#operation-3810320977').click(); |
| 124 | + |
| 125 | + cy.get(':nth-child(12) > .MuiPaper-root > .MuiList-root > .information_menu__CXV1V > #view-3810320977').click(); |
| 126 | + |
| 127 | + // Then I see that the current page is the persistent cache task details! |
| 128 | + cy.url().should('include', '/resource/persistent-cache-task/clusters/1/3810320977'); |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + describe('when no data is loaded', () => { |
| 133 | + beforeEach(() => { |
| 134 | + cy.intercept( |
| 135 | + { |
| 136 | + method: 'GET', |
| 137 | + url: '/api/v1/persistent-cache-tasks/2865345332?scheduler_cluster_id=1', |
| 138 | + }, |
| 139 | + (req) => { |
| 140 | + req.reply({ |
| 141 | + statusCode: 200, |
| 142 | + body: {}, |
| 143 | + }); |
| 144 | + }, |
| 145 | + ); |
| 146 | + }); |
| 147 | + |
| 148 | + it('unable to display breadcrumb', () => { |
| 149 | + cy.get('#task-id-2865345332').should('have.text', '2865345332'); |
| 150 | + }); |
| 151 | + |
| 152 | + it('persistent cache task render empty status', () => { |
| 153 | + cy.get('#id').should('have.text', '0'); |
| 154 | + cy.get('#failure-task').should('exist'); |
| 155 | + cy.get('#create-at').should('have.text', '-'); |
| 156 | + cy.get('#persistent-replica-count').should('have.text', '-'); |
| 157 | + cy.get('#ttl').should('have.text', '-'); |
| 158 | + cy.get('#content-length').should('have.text', '-'); |
| 159 | + cy.get('#piece-length').should('have.text', '-'); |
| 160 | + cy.get('#application').should('have.text', '-'); |
| 161 | + cy.get('#tag').should('have.text', '-'); |
| 162 | + cy.get('#peers').should('not.exist'); |
| 163 | + }); |
| 164 | + }); |
| 165 | + |
| 166 | + describe('should handle API error response', () => { |
| 167 | + beforeEach(() => { |
| 168 | + cy.intercept( |
| 169 | + { |
| 170 | + method: 'GET', |
| 171 | + url: '/api/v1/persistent-cache-tasks/3810320977?scheduler_cluster_id=1', |
| 172 | + }, |
| 173 | + (req) => { |
| 174 | + req.reply({ |
| 175 | + forceNetworkError: true, |
| 176 | + }); |
| 177 | + }, |
| 178 | + ); |
| 179 | + cy.visit('/resource/persistent-cache-task/clusters/1/3810320977'); |
| 180 | + }); |
| 181 | + |
| 182 | + it('show error message', () => { |
| 183 | + // Show error message. |
| 184 | + cy.get('#error-message').should('be.visible').and('contain', 'Failed to fetch'); |
| 185 | + |
| 186 | + // Close error message. |
| 187 | + cy.get('.MuiAlert-action > .MuiButtonBase-root').click(); |
| 188 | + cy.get('#error-message').should('not.exist'); |
| 189 | + }); |
| 190 | + |
| 191 | + it('persistent cache task render empty status', () => { |
| 192 | + cy.get('#id').should('have.text', '0'); |
| 193 | + cy.get('#failure-task').should('exist'); |
| 194 | + cy.get('#create-at').should('have.text', '-'); |
| 195 | + cy.get('#persistent-replica-count').should('have.text', '-'); |
| 196 | + cy.get('#ttl').should('have.text', '-'); |
| 197 | + cy.get('#content-length').should('have.text', '-'); |
| 198 | + cy.get('#piece-length').should('have.text', '-'); |
| 199 | + cy.get('#application').should('have.text', '-'); |
| 200 | + cy.get('#tag').should('have.text', '-'); |
| 201 | + cy.get('#peers').should('not.exist'); |
| 202 | + }); |
| 203 | + }); |
| 204 | + |
| 205 | + describe('delete', () => { |
| 206 | + it('persistent cache tasks can be deleted', () => { |
| 207 | + cy.get('#open-dialog').should('not.exist'); |
| 208 | + cy.get('#delete-task').click(); |
| 209 | + |
| 210 | + cy.get('#open-dialog').should('exist'); |
| 211 | + |
| 212 | + // Cancel delete task. |
| 213 | + cy.get('#cancel-delete-task').click(); |
| 214 | + |
| 215 | + cy.get('#open-dialog').should('not.exist'); |
| 216 | + |
| 217 | + cy.get('#delete-task').click(); |
| 218 | + |
| 219 | + cy.get('#delete-task-input').type('delete'); |
| 220 | + |
| 221 | + cy.get('#save-delete-task').click(); |
| 222 | + |
| 223 | + // Shoe help text. |
| 224 | + cy.get('#delete-task-input-helper-text').should('have.text', 'Please enter "DELETE"'); |
| 225 | + |
| 226 | + cy.get('#delete-task-input').clear(); |
| 227 | + |
| 228 | + cy.get('#delete-task-input').type('DELETE'); |
| 229 | + |
| 230 | + cy.get('#delete-task-input-helper-text').should('not.exist'); |
| 231 | + |
| 232 | + cy.intercept( |
| 233 | + { |
| 234 | + method: 'DELETE', |
| 235 | + url: '/api/v1/persistent-cache-tasks/2865345332?scheduler_cluster_id=1', |
| 236 | + }, |
| 237 | + (req) => { |
| 238 | + req.reply({ |
| 239 | + statusCode: 200, |
| 240 | + }); |
| 241 | + }, |
| 242 | + ); |
| 243 | + |
| 244 | + cy.get('#save-delete-task').click(); |
| 245 | + |
| 246 | + cy.url().should('include', '/resource/persistent-cache-task/clusters/1'); |
| 247 | + }); |
| 248 | + |
| 249 | + it('should handle API error response', () => { |
| 250 | + cy.get('#delete-task').click(); |
| 251 | + |
| 252 | + cy.get('#delete-task-input').type('DELETE'); |
| 253 | + |
| 254 | + cy.get('#delete-task-input-helper-text').should('not.exist'); |
| 255 | + |
| 256 | + cy.intercept( |
| 257 | + { |
| 258 | + method: 'DELETE', |
| 259 | + url: '/api/v1/persistent-cache-tasks/2865345332?scheduler_cluster_id=1', |
| 260 | + }, |
| 261 | + (req) => { |
| 262 | + req.reply({ |
| 263 | + forceNetworkError: true, |
| 264 | + }); |
| 265 | + }, |
| 266 | + ); |
| 267 | + |
| 268 | + cy.get('#save-delete-task').click(); |
| 269 | + |
| 270 | + // Show error message. |
| 271 | + cy.get('#error-message').should('be.visible').and('contain', 'Failed to fetch'); |
| 272 | + }); |
| 273 | + }); |
| 274 | +}); |
0 commit comments