| Conditions | 7 |
| Total Lines | 31 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package page_test |
||
| 12 | func TestHero(t *testing.T) { |
||
| 13 | r, w := io.Pipe() |
||
| 14 | const name = "John" |
||
| 15 | go func() { |
||
| 16 | _ = page.Hero(name).Render(context.Background(), w) |
||
| 17 | _ = w.Close() |
||
| 18 | }() |
||
| 19 | |||
| 20 | doc, err := goquery.NewDocumentFromReader(r) |
||
| 21 | if err != nil { |
||
| 22 | t.Fatalf("Error reading document: %s", err) |
||
| 23 | } |
||
| 24 | |||
| 25 | // Assert that the hero exists |
||
| 26 | if doc.Find(`[data-testid="hero"]`).Length() != 1 { |
||
| 27 | t.Errorf("Expected to find a hero") |
||
| 28 | } |
||
| 29 | |||
| 30 | // Assert that the hero has a hello component |
||
| 31 | if doc.Find(`[data-testid="helloComponent"]`).Length() != 1 { |
||
| 32 | t.Errorf("Expected to find a hello component") |
||
| 33 | } |
||
| 34 | |||
| 35 | // Assert that the h1 is the name |
||
| 36 | if doc.Find(`[data-testid="helloH1"]`).Text() != "Hello, "+name+" !" { |
||
| 37 | t.Errorf("Expected to find a h1 with the name: %s, but got %s", name, doc.Find(`[data-testid="helloH1"]`).Text()) |
||
| 38 | } |
||
| 39 | |||
| 40 | // Assert that there is only one h1 |
||
| 41 | if doc.Find(`[data-testid="helloH1"]`).Length() != 1 { |
||
| 42 | t.Errorf("Expected to find only one h1") |
||
| 43 | } |
||
| 45 |