Documentation
¶
Overview ¶
Package sitetest starts a complete WebThings app for end-to-end tests and drives its admin like a browser: sign in, submit forms, publish.
Its own templates are only the generic ones (layout, page, 404 and search). A module's tests bring the module's templates in their testdata folder:
s := sitetest.StartWith(t, sitetest.Options{Templates: "testdata/templates"}, publishing.Module("news", "News"))
Index ¶
- func HasToast(body, level, text string) bool
- func JPEG(t testing.TB, width, height int) []byte
- func PNG(t testing.TB, width, height int) []byte
- type File
- type Options
- type Site
- func (s *Site) As(email, password string) *Site
- func (s *Site) CrossSite(path string, values url.Values) int
- func (s *Site) Dashboard() string
- func (s *Site) DraftPage(title, draft, slug string)
- func (s *Site) Expect(path string, status int, parts ...string)
- func (s *Site) ExpectMissing(path, part string)
- func (s *Site) Fragment(path, id string) (int, string)
- func (s *Site) Get(path string) (int, string)
- func (s *Site) Mails(count int) []mail.Message
- func (s *Site) Mount(module, title, slug string) string
- func (s *Site) MountIn(module string, translations ...Translation) string
- func (s *Site) Post(formPage, action string, values url.Values) string
- func (s *Site) PostFiles(formPage, action string, values url.Values, files ...File) (int, string)
- func (s *Site) PostStatus(formPage, action string, values url.Values) (int, string)
- func (s *Site) Publish(path string)
- func (s *Site) Request(request *http.Request) *http.Response
- func (s *Site) Response(path string) (*http.Response, string)
- func (s *Site) Send(path string, values url.Values) (int, string, string)
- func (s *Site) SendHTMX(path string, values url.Values, target string) (int, string, string)
- func (s *Site) Submit(path string, values url.Values) string
- func (s *Site) Upload(name string, data []byte) media.Asset
- func (s *Site) Visitor() *Site
- type Translation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasToast ¶
HasToast reports whether an admin page shows text as a toast of level ("success", "info", "warn" or "error").
Types ¶
type File ¶
File is a file in a form PostFiles sends, as a browser sends the file of a file input: Field is the input's name.
type Options ¶
type Options struct {
// Templates is a template folder used on top of sitetest's generic
// templates, holding the module's own, for example comments/list.gohtml.
Templates string
// Files replace sitetest's templates entirely, for example a folder of
// themes.
Files fs.FS
// Prepare runs after the modules are added and before the app starts, for
// example to write templates with App.WriteTemplates.
Prepare func(app *webthings.App) error
// Configure changes the app's configuration before it is created, for
// example its CacheTTL. It runs after OutputCache is applied, so it can
// set Config.OutputCacheTTL itself.
Configure func(config *webthings.Config)
// OutputCache keeps the output cache on, as the site setting says
// (see webthings.Config.OutputCacheTTL). Sites in tests have it off,
// so a test that changes content from Go, outside a request, sees the
// change on the next page also where the app is not told about it.
OutputCache bool
// StartingPoints names module instances, such as "news", whose starting
// points App.WriteTemplates generates for the test. They come below
// Templates and above sitetest's generic templates, and as they are
// written for the instance key they take precedence over templates in
// Templates for the module type. Tests then render the generated
// templates, which can never drift from the generator, and need no
// copies of their own.
StartingPoints []string
// NoAccount starts the site without accounts, as a fresh install that
// offers the first-run setup; StartWith then returns a browser that is
// not signed in. The setup link is <AdminPath>/setup?token=<token> with
// the token from App.SetupToken, also posted as the form's Token field.
NoAccount bool
}
Options change how StartWith sets up the site.
type Site ¶
type Site struct {
App *webthings.App
// Mail holds the e-mail the site sent.
Mail *mail.Memory
// contains filtered or unexported fields
}
Site is a running app with a signed-in admin browser.
func (*Site) CrossSite ¶
CrossSite posts to path as a page on another website would and returns the status.
func (*Site) Dashboard ¶
Dashboard returns the admin dashboard with its panels loaded, as the browser shows it once they arrived.
func (*Site) DraftPage ¶
DraftPage saves a new, unpublished English title and slug for the page titled title, leaving its published version as it is.
func (*Site) ExpectMissing ¶
ExpectMissing checks that a page does not contain part.
func (*Site) Fragment ¶
Fragment returns the status and body of the part of the page at path with element ID id, asked for as HTMX does for an element that loads on its own, such as a panel of the admin dashboard.
func (*Site) Mails ¶
Mails waits until the site has sent at least count e-mails, as some are sent in the background, and returns all it sent. It fails the test after five seconds.
func (*Site) Mount ¶
Mount creates and publishes a page with a module below Home, in English, and returns its editor address.
func (*Site) MountIn ¶
func (s *Site) MountIn(module string, translations ...Translation) string
MountIn creates a page with a module below Home with a translation in every given language, publishes it and returns its editor address. The page is created in the first language.
func (*Site) Post ¶
Post opens the page at formPage and sends values to action from it, as a browser submits a form of that page.
func (*Site) PostFiles ¶
PostFiles opens formPage and sends values and files to action from it as a multipart form, as a browser submits a form with a file input. It returns the status and body after redirects instead of failing the test.
func (*Site) PostStatus ¶
PostStatus is Post for submissions that may fail: it returns the status and body instead of failing the test.
func (*Site) Request ¶
Request sends request with the browser's cookies, its URL being a path of the site such as App.AdminURL("admin.presence"), and returns the response unread, for streams and other responses a test reads itself. Close its body.
func (*Site) Response ¶
Response returns the response to a GET of path, with its headers, and its body.
func (*Site) Send ¶
Send posts a visitor's form to path, as a public form of the site does, without opening a page first, and returns the status, body and final path.
func (*Site) SendHTMX ¶
SendHTMX is Send for a form that posts with HTMX and swaps the element with ID target: the post and the redirect HTMX follows carry its request headers. It returns the status, the body, which is a part of the page without the layout, and the final path.
func (*Site) Submit ¶
Submit opens the form at path, posts values to it and returns the page it ended on. It fails the test on any error status.
type Translation ¶
Translation is a page's title and slug in one language, for MountIn.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package catalogtest checks in tests that the admin's catalogues translate every text of a section's forms in each language the admin comes with, so a label or description added to a form cannot go untranslated:
|
Package catalogtest checks in tests that the admin's catalogues translate every text of a section's forms in each language the admin comes with, so a label or description added to a form cannot go untranslated: |