Reinstate canAddBlock assertions for StreamBlock and ListBlock's max_num

pull/12023/head
Sage Abdullah 2024-07-18 15:03:05 +01:00
rodzic 6eacfec4ec
commit 9ac9a93e54
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
2 zmienionych plików z 46 dodań i 0 usunięć

Wyświetl plik

@ -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();
});
});

Wyświetl plik

@ -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();
});
});