|
255 | 255 | end |
256 | 256 | end |
257 | 257 |
|
258 | | - context "validates" do |
| 258 | + context "validations" do |
259 | 259 | it { is_expected.to validate_length_of(:private_metadata).is_at_most(3000).allow_nil } |
260 | 260 | it { is_expected.to validate_length_of(:callback_id).is_at_most(255).allow_nil } |
261 | 261 | it { is_expected.to validate_length_of(:external_id).is_at_most(255).allow_nil } |
|
340 | 340 | expect(modal.errors["blocks[2].elements[0]"]).to include("is invalid: can't set focus_on_load when other elements have set focus_on_load") |
341 | 341 | expect(modal.errors["blocks[2].elements[2]"]).to include("is invalid: can't set focus_on_load when other elements have set focus_on_load") |
342 | 342 | end |
| 343 | + |
| 344 | + it "validates that a submit button is present if there are inputs" do |
| 345 | + modal.header(text: "Header text") |
| 346 | + modal.section(text: "Info text") |
| 347 | + |
| 348 | + expect(modal).to be_valid |
| 349 | + |
| 350 | + modal.input(label: "Input label", element: BlockKit::Elements::PlainTextInput.new) |
| 351 | + |
| 352 | + expect(modal).not_to be_valid |
| 353 | + expect(modal.errors[:submit]).to include("can't be blank when blocks contain input elements") |
| 354 | + |
| 355 | + modal.submit = "Submit" |
| 356 | + expect(modal).to be_valid |
| 357 | + expect(modal.errors[:submit]).to be_empty |
| 358 | + end |
343 | 359 | end |
344 | 360 |
|
345 | 361 | it "fixes individually-contained blocks" do |
|
417 | 433 | }.from(true).to(false) |
418 | 434 | end |
419 | 435 |
|
| 436 | + it "fixes missing submit buttons when blocks contain inputs" do |
| 437 | + modal.header(text: "Header text") |
| 438 | + modal.section(text: "Info text") |
| 439 | + modal.input(label: "Input label", element: BlockKit::Elements::PlainTextInput.new) |
| 440 | + |
| 441 | + expect { |
| 442 | + modal.fix_validation_errors |
| 443 | + }.to change { |
| 444 | + modal.submit |
| 445 | + }.from(nil).to(BlockKit::Composition::PlainText.new(text: "Submit")) |
| 446 | + |
| 447 | + expect(modal).to be_valid |
| 448 | + end |
| 449 | + |
420 | 450 | it "can raise unfixed validation errors" do |
421 | 451 | modal.header(text: "") |
422 | 452 | modal.divider |
|
0 commit comments