You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

devtest.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package devtest
  4. import (
  5. "net/http"
  6. "path"
  7. "strings"
  8. "time"
  9. "code.gitea.io/gitea/modules/base"
  10. "code.gitea.io/gitea/modules/context"
  11. "code.gitea.io/gitea/modules/templates"
  12. )
  13. // List all devtest templates, they will be used for e2e tests for the UI components
  14. func List(ctx *context.Context) {
  15. templateNames, err := templates.AssetFS().ListFiles("devtest", true)
  16. if err != nil {
  17. ctx.ServerError("AssetFS().ListFiles", err)
  18. return
  19. }
  20. var subNames []string
  21. for _, tmplName := range templateNames {
  22. subName := strings.TrimSuffix(tmplName, ".tmpl")
  23. if subName != "list" {
  24. subNames = append(subNames, subName)
  25. }
  26. }
  27. ctx.Data["SubNames"] = subNames
  28. ctx.HTML(http.StatusOK, "devtest/list")
  29. }
  30. func Tmpl(ctx *context.Context) {
  31. now := time.Now()
  32. ctx.Data["TimeNow"] = now
  33. ctx.Data["TimePast5s"] = now.Add(-5 * time.Second)
  34. ctx.Data["TimeFuture5s"] = now.Add(5 * time.Second)
  35. ctx.Data["TimePast2m"] = now.Add(-2 * time.Minute)
  36. ctx.Data["TimeFuture2m"] = now.Add(2 * time.Minute)
  37. ctx.Data["TimePast1y"] = now.Add(-1 * 366 * 86400 * time.Second)
  38. ctx.Data["TimeFuture1y"] = now.Add(1 * 366 * 86400 * time.Second)
  39. if ctx.Req.Method == "POST" {
  40. _ = ctx.Req.ParseForm()
  41. ctx.Flash.Info("form: "+ctx.Req.Method+" "+ctx.Req.RequestURI+"<br>"+
  42. "Form: "+ctx.Req.Form.Encode()+"<br>"+
  43. "PostForm: "+ctx.Req.PostForm.Encode(),
  44. true,
  45. )
  46. time.Sleep(2 * time.Second)
  47. }
  48. ctx.HTML(http.StatusOK, base.TplName("devtest"+path.Clean("/"+ctx.Params("sub"))))
  49. }