(t *testing.T)
| 537 | } |
| 538 | |
| 539 | func TestSelectDynamic(t *testing.T) { |
| 540 | trigger := "initial" |
| 541 | |
| 542 | field1 := NewSelect[string](). |
| 543 | TitleFunc(func() string { |
| 544 | return "field1 title " + trigger |
| 545 | }, &trigger). |
| 546 | DescriptionFunc(func() string { |
| 547 | return "field1 desc " + trigger |
| 548 | }, &trigger). |
| 549 | OptionsFunc(func() []Option[string] { |
| 550 | return []Option[string]{NewOption("field1 opt "+trigger, "field1 opt "+trigger)} |
| 551 | }, &trigger) |
| 552 | field2 := NewSelect[string](). |
| 553 | TitleFunc(func() string { |
| 554 | return "field2 title " + trigger |
| 555 | }, &trigger). |
| 556 | DescriptionFunc(func() string { |
| 557 | return "field2 desc " + trigger |
| 558 | }, &trigger). |
| 559 | OptionsFunc(func() []Option[string] { |
| 560 | return []Option[string]{NewOption("field2 opt "+trigger, "field2 opt "+trigger)} |
| 561 | }, &trigger) |
| 562 | field1.WithHeight(5) |
| 563 | field2.WithHeight(5) |
| 564 | f := NewForm(NewGroup(field1, field2)).WithHeight(10) |
| 565 | |
| 566 | doAllUpdates(f, f.Init()) |
| 567 | |
| 568 | view := viewModel(f) |
| 569 | |
| 570 | expectedStrings := []string{ |
| 571 | "field1 title initial", |
| 572 | "field1 desc initial", |
| 573 | "field1 opt initial", |
| 574 | "field2 title initial", |
| 575 | "field2 desc initial", |
| 576 | "field2 opt initial", |
| 577 | } |
| 578 | for _, expected := range expectedStrings { |
| 579 | if !strings.Contains(view, expected) { |
| 580 | t.Log(pretty.Render(view)) |
| 581 | t.Error("Expected view to contain " + expected) |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | if field1.GetValue() != "field1 opt initial" { |
| 586 | t.Errorf("Expected field1 value to be field1 opt initial but was %s", field1.GetValue()) |
| 587 | } |
| 588 | if field2.GetValue() != "field2 opt initial" { |
| 589 | t.Errorf("Expected field2 value to be field2 opt initial but was %s", field2.GetValue()) |
| 590 | } |
| 591 | |
| 592 | trigger = "updated" |
| 593 | _, cmd := f.Update(nil) |
| 594 | doAllUpdates(f, cmd) |
| 595 | view = viewModel(f) |
| 596 |
nothing calls this directly
no test coverage detected
searching dependent graphs…