MCPcopy
hub / github.com/benbjohnson/wtf / TestCreateDial

Function TestCreateDial

cmd/wtfd/dial_test.go:15–83  ·  view source on GitHub ↗

TestCreateDial creates a new dial by navigating from the dials page, clicking the "Create Dial" button, filling out the form, and submitting it.

(t *testing.T)

Source from the content-addressed store, hash-verified

13// TestCreateDial creates a new dial by navigating from the dials page, clicking
14// the "Create Dial" button, filling out the form, and submitting it.
15func TestCreateDial(t *testing.T) {
16 t.Parallel()
17
18 // Start our test program. Defer close to clean up execution.
19 m := MustRunMain(t)
20 defer MustCloseMain(t, m)
21
22 // Generate a user directly in the database and attach the user to the context.
23 _, ctx0 := MustCreateUser(t, m, &wtf.User{Name: "USER0"})
24 ctx0, cancel := chromedp.NewContext(ctx0, chromedp.WithLogf(log.Printf))
25 defer cancel()
26
27 // Navigate to dial list page & click "Create new dial" button
28 if err := chromedp.Run(ctx0,
29 Login(ctx0, m),
30 chromedp.Navigate(m.HTTPServer.URL()+`/dials`),
31 chromedp.WaitVisible(`body > footer`),
32 chromedp.Click(`.btn-new-dial`, chromedp.NodeVisible),
33 ); err != nil {
34 t.Fatal(err)
35 }
36
37 // Fill out 'Create Dial' form & submit.
38 if err := chromedp.Run(ctx0,
39 chromedp.WaitVisible(`body > footer`),
40 chromedp.SendKeys(`#name`, "NEWDIAL", chromedp.NodeVisible),
41 chromedp.Submit(`#name`),
42 ); err != nil {
43 t.Fatal(err)
44 }
45
46 // Verify that we see the dial page and the dial exists.
47 var location, title, name string
48 if err := chromedp.Run(ctx0,
49 chromedp.WaitVisible(`body > footer`),
50 chromedp.Location(&location),
51 chromedp.Title(&title),
52 chromedp.Text(`h2 .dial-name`, &name),
53 ); err != nil {
54 t.Fatal(err)
55 } else if u, err := url.Parse(location); err != nil {
56 t.Fatal(err)
57 } else if got, want := u.Path, `/dials/1`; got != want {
58 t.Fatalf("location.path=%q, want %q", got, want)
59 } else if got, want := title, `NEWDIAL Dial`; got != want {
60 t.Fatalf("title=%q, want %q", got, want)
61 } else if got, want := strings.TrimSpace(name), `NEWDIAL`; got != want {
62 t.Fatalf("name=%q, want %q", got, want)
63 }
64
65 // Navigate to dial list page and verify that new dial is listed in table.
66 var tableName, tableUserName, tableValue string
67 if err := chromedp.Run(ctx0,
68 // Return to dials page & verify dial is shown.
69 chromedp.Navigate(m.HTTPServer.URL()+`/dials`),
70 chromedp.WaitVisible(`body > footer`),
71 chromedp.Text(`th.dial-name`, &tableName),
72 chromedp.Text(`td.dial-user-name`, &tableUserName),

Callers

nothing calls this directly

Calls 6

MustRunMainFunction · 0.85
MustCloseMainFunction · 0.85
LoginFunction · 0.85
URLMethod · 0.80
MustCreateUserFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected