@@ -21,7 +21,6 @@ import {
2121import { when } from 'vitest-when' ;
2222
2323import { permissionLevels } from '@/constants' ;
24- import { snackbar } from '@/utils/b3Tip' ;
2524
2625import { InvoiceStatusCode } from './components/InvoiceStatus' ;
2726import { triggerPdfDownload } from './components/triggerPdfDownload' ;
@@ -30,9 +29,6 @@ import Invoice from '.';
3029const { server } = startMockServer ( ) ;
3130
3231vi . mock ( './components/triggerPdfDownload' ) ;
33- vi . mock ( '@/utils/b3Tip' , ( ) => ( {
34- snackbar : { error : vi . fn ( ) } ,
35- } ) ) ;
3632
3733const buildInvoiceWith = builder ( ( ) => ( {
3834 node : {
@@ -353,7 +349,7 @@ it('can pay for multiple invoices', async () => {
353349 } ) ;
354350} ) ;
355351
356- it ( 'blocks selecting invoices that are in different currencies' , async ( ) => {
352+ it ( 'disables the Pay invoices button when selected invoices are in different currencies' , async ( ) => {
357353 server . use (
358354 graphql . query ( 'GetInvoices' , ( ) =>
359355 HttpResponse . json (
@@ -413,17 +409,27 @@ it('blocks selecting invoices that are in different currencies', async () => {
413409
414410 expect ( screen . getByText ( '1 invoices selected' ) ) . toBeInTheDocument ( ) ;
415411 expect ( screen . getByRole ( 'heading' , { name : 'Total payment: $433.00' } ) ) . toBeInTheDocument ( ) ;
412+ expect ( screen . getByRole ( 'button' , { name : 'Pay invoices' } ) ) . toBeEnabled ( ) ;
416413
417- // attempting to also select the EUR invoice should be blocked
414+ // selecting the EUR invoice too is now allowed
418415 await userEvent . click ( within ( secondRowCells [ 0 ] ) . getByRole ( 'checkbox' ) ) ;
419416
420- expect ( within ( secondRowCells [ 0 ] ) . getByRole ( 'checkbox' ) ) . not . toBeChecked ( ) ;
421- expect ( screen . getByText ( '1 invoices selected' ) ) . toBeInTheDocument ( ) ;
422- expect ( screen . getByRole ( 'heading' , { name : 'Total payment: $433.00' } ) ) . toBeInTheDocument ( ) ;
423- expect ( snackbar . error ) . toHaveBeenCalled ( ) ;
417+ expect ( within ( secondRowCells [ 0 ] ) . getByRole ( 'checkbox' ) ) . toBeChecked ( ) ;
418+ expect ( screen . getByText ( '2 invoices selected' ) ) . toBeInTheDocument ( ) ;
419+
420+ // the misleading flattened total is replaced with a warning...
421+ expect (
422+ screen . getByRole ( 'heading' , {
423+ name : 'You cannot pay multiple invoices in different currencies' ,
424+ } ) ,
425+ ) . toBeInTheDocument ( ) ;
426+ expect ( screen . queryByText ( / T o t a l p a y m e n t : / ) ) . not . toBeInTheDocument ( ) ;
427+
428+ // ...and paying is blocked while the selection mixes currencies
429+ expect ( screen . getByRole ( 'button' , { name : 'Pay invoices' } ) ) . toBeDisabled ( ) ;
424430} ) ;
425431
426- it ( 'blocks selecting all invoices when the page contains different currencies' , async ( ) => {
432+ it ( 'disables the Pay invoices button when selecting all invoices with different currencies' , async ( ) => {
427433 server . use (
428434 graphql . query ( 'GetInvoices' , ( ) =>
429435 HttpResponse . json (
@@ -477,15 +483,19 @@ it('blocks selecting all invoices when the page contains different currencies',
477483 const secondRow = within ( table ) . getByRole ( 'row' , { name : / 3 3 2 5 / } ) ;
478484 const secondRowCells = within ( secondRow ) . getAllByRole ( 'cell' ) ;
479485
480- // click the "select all" checkbox in the header, which would otherwise
481- // select both the USD and EUR invoices at once
486+ // click the "select all" checkbox in the header
482487 await userEvent . click ( within ( columnHeaders [ 0 ] ) . getByRole ( 'checkbox' ) ) ;
483488
484- // only the reference-currency invoice should end up selected
485- expect ( screen . getByText ( '1 invoices selected' ) ) . toBeInTheDocument ( ) ;
486- expect ( screen . getByRole ( 'heading' , { name : 'Total payment: $433.00' } ) ) . toBeInTheDocument ( ) ;
487- expect ( within ( secondRowCells [ 0 ] ) . getByRole ( 'checkbox' ) ) . not . toBeChecked ( ) ;
488- expect ( snackbar . error ) . toHaveBeenCalled ( ) ;
489+ // both invoices get selected even though currencies differ
490+ expect ( within ( secondRowCells [ 0 ] ) . getByRole ( 'checkbox' ) ) . toBeChecked ( ) ;
491+ expect ( screen . getByText ( '2 invoices selected' ) ) . toBeInTheDocument ( ) ;
492+
493+ expect (
494+ screen . getByRole ( 'heading' , {
495+ name : 'You cannot pay multiple invoices in different currencies' ,
496+ } ) ,
497+ ) . toBeInTheDocument ( ) ;
498+ expect ( screen . getByRole ( 'button' , { name : 'Pay invoices' } ) ) . toBeDisabled ( ) ;
489499} ) ;
490500
491501it ( 'can specify an amount to pay for the invoices' , async ( ) => {
0 commit comments