|
1 | 1 | import * as React from 'react'
|
2 |
| -import { render, screen, waitFor } from 'support/test-utils' |
| 2 | +import { render, screen, waitFor, within } from 'support/test-utils' |
3 | 3 | import userEvent from '@testing-library/user-event'
|
4 | 4 |
|
5 | 5 | import {
|
@@ -260,4 +260,151 @@ describe('SpecsView', () => {
|
260 | 260 | expect(queryByText('Cancel')).not.toBeInTheDocument()
|
261 | 261 | })
|
262 | 262 | })
|
| 263 | + |
| 264 | + describe('Approve button', () => { |
| 265 | + let specs: ReadonlyArray<JobProposal_SpecsFields> |
| 266 | + let proposal: JobProposalPayloadFields |
| 267 | + |
| 268 | + beforeEach(() => { |
| 269 | + specs = [ |
| 270 | + buildJobProposalSpec({ id: '106', version: 6, status: 'CANCELLED' }), |
| 271 | + buildJobProposalSpec({ id: '105', version: 5, status: 'PENDING' }), |
| 272 | + buildJobProposalSpec({ id: '104', version: 4, status: 'CANCELLED' }), |
| 273 | + buildJobProposalSpec({ id: '103', version: 3, status: 'CANCELLED' }), |
| 274 | + buildJobProposalSpec({ id: '102', version: 2, status: 'APPROVED' }), |
| 275 | + buildJobProposalSpec({ id: '101', version: 1, status: 'REVOKED' }), |
| 276 | + ] |
| 277 | + }) |
| 278 | + |
| 279 | + it('is visible in latest two cancelled specs if proposal is not deleted or revoked', async () => { |
| 280 | + proposal = buildJobProposal({ status: 'PENDING' }) |
| 281 | + renderComponent(specs, proposal) |
| 282 | + |
| 283 | + const panels = screen.getAllByTestId('expansion-panel') |
| 284 | + expect(panels).toHaveLength(6) |
| 285 | + expect( |
| 286 | + within(panels[0]).queryByRole('button', { |
| 287 | + name: 'Approve', |
| 288 | + hidden: false, |
| 289 | + }), |
| 290 | + ).toBeInTheDocument() |
| 291 | + expect( |
| 292 | + within(panels[1]).queryByRole('button', { |
| 293 | + name: 'Approve', |
| 294 | + hidden: true, |
| 295 | + }), |
| 296 | + ).not.toBeInTheDocument() |
| 297 | + expect( |
| 298 | + within(panels[2]).queryByRole('button', { |
| 299 | + name: 'Approve', |
| 300 | + hidden: true, |
| 301 | + }), |
| 302 | + ).toBeInTheDocument() |
| 303 | + expect( |
| 304 | + within(panels[3]).queryByRole('button', { |
| 305 | + name: 'Approve', |
| 306 | + hidden: true, |
| 307 | + }), |
| 308 | + ).not.toBeInTheDocument() |
| 309 | + expect( |
| 310 | + within(panels[4]).queryByRole('button', { |
| 311 | + name: 'Approve', |
| 312 | + hidden: true, |
| 313 | + }), |
| 314 | + ).not.toBeInTheDocument() |
| 315 | + expect( |
| 316 | + within(panels[5]).queryByRole('button', { |
| 317 | + name: 'Approve', |
| 318 | + hidden: true, |
| 319 | + }), |
| 320 | + ).not.toBeInTheDocument() |
| 321 | + }) |
| 322 | + |
| 323 | + it('is visible in latest pending spec if proposal is not deleted or revoked', async () => { |
| 324 | + specs = [ |
| 325 | + buildJobProposalSpec({ id: '103', version: 3, status: 'PENDING' }), |
| 326 | + buildJobProposalSpec({ id: '102', version: 2, status: 'PENDING' }), |
| 327 | + buildJobProposalSpec({ id: '101', version: 1, status: 'CANCELLED' }), |
| 328 | + ] |
| 329 | + proposal = buildJobProposal({ status: 'PENDING' }) |
| 330 | + renderComponent(specs, proposal) |
| 331 | + |
| 332 | + const panels = screen.getAllByTestId('expansion-panel') |
| 333 | + expect(panels).toHaveLength(3) |
| 334 | + expect( |
| 335 | + within(panels[0]).queryByRole('button', { |
| 336 | + name: 'Approve', |
| 337 | + hidden: false, |
| 338 | + }), |
| 339 | + ).toBeInTheDocument() |
| 340 | + expect( |
| 341 | + within(panels[1]).queryByRole('button', { |
| 342 | + name: 'Approve', |
| 343 | + hidden: true, |
| 344 | + }), |
| 345 | + ).not.toBeInTheDocument() |
| 346 | + expect( |
| 347 | + within(panels[2]).queryByRole('button', { |
| 348 | + name: 'Approve', |
| 349 | + hidden: true, |
| 350 | + }), |
| 351 | + ).toBeInTheDocument() |
| 352 | + }) |
| 353 | + |
| 354 | + it('is not visible in any specs if proposal is deleted', async () => { |
| 355 | + proposal = buildJobProposal({ status: 'DELETED' }) |
| 356 | + renderComponent(specs, proposal) |
| 357 | + |
| 358 | + const panels = screen.getAllByTestId('expansion-panel') |
| 359 | + expect(panels).toHaveLength(6) |
| 360 | + expect( |
| 361 | + screen.queryByRole('button', { name: 'Approve', hidden: false }), |
| 362 | + ).not.toBeInTheDocument() |
| 363 | + }) |
| 364 | + |
| 365 | + it('is not visible in any specs if proposal is revoked', async () => { |
| 366 | + proposal = buildJobProposal({ status: 'REVOKED' }) |
| 367 | + renderComponent(specs, proposal) |
| 368 | + |
| 369 | + const panels = screen.getAllByTestId('expansion-panel') |
| 370 | + expect(panels).toHaveLength(6) |
| 371 | + expect( |
| 372 | + screen.queryByRole('button', { name: 'Approve', hidden: false }), |
| 373 | + ).not.toBeInTheDocument() |
| 374 | + }) |
| 375 | + |
| 376 | + it('is visible with single pending job', async () => { |
| 377 | + proposal = buildJobProposal({ status: 'PENDING' }) |
| 378 | + specs = [ |
| 379 | + buildJobProposalSpec({ id: '101', version: 1, status: 'PENDING' }), |
| 380 | + ] |
| 381 | + renderComponent(specs, proposal) |
| 382 | + |
| 383 | + const panels = screen.getAllByTestId('expansion-panel') |
| 384 | + expect(panels).toHaveLength(1) |
| 385 | + expect( |
| 386 | + within(panels[0]).queryByRole('button', { |
| 387 | + name: 'Approve', |
| 388 | + hidden: false, |
| 389 | + }), |
| 390 | + ).toBeInTheDocument() |
| 391 | + }) |
| 392 | + |
| 393 | + it('is visible with single cancelled job', async () => { |
| 394 | + proposal = buildJobProposal({ status: 'PENDING' }) |
| 395 | + specs = [ |
| 396 | + buildJobProposalSpec({ id: '101', version: 1, status: 'CANCELLED' }), |
| 397 | + ] |
| 398 | + renderComponent(specs, proposal) |
| 399 | + |
| 400 | + const panels = screen.getAllByTestId('expansion-panel') |
| 401 | + expect(panels).toHaveLength(1) |
| 402 | + expect( |
| 403 | + within(panels[0]).queryByRole('button', { |
| 404 | + name: 'Approve', |
| 405 | + hidden: false, |
| 406 | + }), |
| 407 | + ).toBeInTheDocument() |
| 408 | + }) |
| 409 | + }) |
263 | 410 | })
|
0 commit comments