diff --git a/client/src/components/StreamField/blocks/ListBlock.test.js b/client/src/components/StreamField/blocks/ListBlock.test.js index 8f4c8a6df7..29a3622056 100644 --- a/client/src/components/StreamField/blocks/ListBlock.test.js +++ b/client/src/components/StreamField/blocks/ListBlock.test.js @@ -345,6 +345,23 @@ describe('telepath: wagtail.blocks.ListBlock with maxNum set', () => { }, ); + const assertCanAddBlock = () => { + // Test duplicate button + // querySelector always returns the first element it sees so this only checks the first block + expect( + document + .querySelector('button[title="Duplicate"]') + .getAttribute('disabled'), + ).toBe(null); + + // Test menu + expect( + document + .querySelector('button[data-streamfield-list-add]') + .getAttribute('disabled'), + ).toBe(null); + }; + const assertShowingErrorMessage = () => { expect(document.querySelector('p.help-block.help-critical').innerHTML).toBe( 'The maximum number of items is 3', @@ -363,6 +380,7 @@ describe('telepath: wagtail.blocks.ListBlock with maxNum set', () => { { value: 'Third value', id: '33333333-3333-3333-3333-333333333333' }, ]); + assertCanAddBlock(); assertNotShowingErrorMessage(); }); @@ -375,6 +393,7 @@ describe('telepath: wagtail.blocks.ListBlock with maxNum set', () => { { value: 'Fourth value', id: '44444444-4444-4444-4444-444444444444' }, ]); + assertCanAddBlock(); assertShowingErrorMessage(); }); @@ -401,10 +420,12 @@ describe('telepath: wagtail.blocks.ListBlock with maxNum set', () => { { value: 'Third value', id: '33333333-3333-3333-3333-333333333333' }, ]); + assertCanAddBlock(); assertNotShowingErrorMessage(); boundBlock.insert('Fourth value', 2); + assertCanAddBlock(); assertShowingErrorMessage(); }); @@ -417,10 +438,12 @@ describe('telepath: wagtail.blocks.ListBlock with maxNum set', () => { { value: 'Fourth value', id: '44444444-4444-4444-4444-444444444444' }, ]); + assertCanAddBlock(); assertShowingErrorMessage(); boundBlock.deleteBlock(2); + assertCanAddBlock(); assertNotShowingErrorMessage(); }); }); diff --git a/client/src/components/StreamField/blocks/StreamBlock.test.js b/client/src/components/StreamField/blocks/StreamBlock.test.js index eb7bfdc33d..162ad188e3 100644 --- a/client/src/components/StreamField/blocks/StreamBlock.test.js +++ b/client/src/components/StreamField/blocks/StreamBlock.test.js @@ -566,6 +566,23 @@ describe('telepath: wagtail.blocks.StreamBlock with maxNum set', () => { }, ); + const assertCanAddBlock = () => { + // Test duplicate button + // querySelector always returns the first element it sees so this only checks the first block + expect( + document + .querySelector('button[title="Duplicate"]') + .getAttribute('disabled'), + ).toBe(null); + + // Test menu + expect( + document + .querySelector('button[title="Insert a block"]') + .getAttribute('disabled'), + ).toBe(null); + }; + const assertShowingErrorMessage = () => { expect(document.querySelector('p.help-block.help-critical').innerHTML).toBe( 'The maximum number of items is 3', @@ -597,6 +614,7 @@ describe('telepath: wagtail.blocks.StreamBlock with maxNum set', () => { ]); boundBlock.inserters[0].open(); + assertCanAddBlock(); assertNotShowingErrorMessage(); }); @@ -626,6 +644,7 @@ describe('telepath: wagtail.blocks.StreamBlock with maxNum set', () => { ]); boundBlock.inserters[0].open(); + assertCanAddBlock(); assertShowingErrorMessage(); }); @@ -674,6 +693,7 @@ describe('telepath: wagtail.blocks.StreamBlock with maxNum set', () => { ]); boundBlock.inserters[0].open(); + assertCanAddBlock(); assertNotShowingErrorMessage(); boundBlock.insert( @@ -685,6 +705,7 @@ describe('telepath: wagtail.blocks.StreamBlock with maxNum set', () => { 2, ); + assertCanAddBlock(); assertShowingErrorMessage(); }); @@ -714,10 +735,12 @@ describe('telepath: wagtail.blocks.StreamBlock with maxNum set', () => { ]); boundBlock.inserters[0].open(); + assertCanAddBlock(); assertShowingErrorMessage(); boundBlock.deleteBlock(2); + assertCanAddBlock(); assertNotShowingErrorMessage(); }); });