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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 FetchActionTest(ctx *context.Context) {
  31. _ = ctx.Req.ParseForm()
  32. ctx.Flash.Info("fetch-action: " + ctx.Req.Method + " " + ctx.Req.RequestURI + "<br>" +
  33. "Form: " + ctx.Req.Form.Encode() + "<br>" +
  34. "PostForm: " + ctx.Req.PostForm.Encode(),
  35. )
  36. time.Sleep(2 * time.Second)
  37. ctx.JSONRedirect("")
  38. }
  39. func Tmpl(ctx *context.Context) {
  40. now := time.Now()
  41. ctx.Data["TimeNow"] = now
  42. ctx.Data["TimePast5s"] = now.Add(-5 * time.Second)
  43. ctx.Data["TimeFuture5s"] = now.Add(5 * time.Second)
  44. ctx.Data["TimePast2m"] = now.Add(-2 * time.Minute)
  45. ctx.Data["TimeFuture2m"] = now.Add(2 * time.Minute)
  46. ctx.Data["TimePast1y"] = now.Add(-1 * 366 * 86400 * time.Second)
  47. ctx.Data["TimeFuture1y"] = now.Add(1 * 366 * 86400 * time.Second)
  48. if ctx.Req.Method == "POST" {
  49. _ = ctx.Req.ParseForm()
  50. ctx.Flash.Info("form: "+ctx.Req.Method+" "+ctx.Req.RequestURI+"<br>"+
  51. "Form: "+ctx.Req.Form.Encode()+"<br>"+
  52. "PostForm: "+ctx.Req.PostForm.Encode(),
  53. true,
  54. )
  55. time.Sleep(2 * time.Second)
  56. }
  57. ctx.HTML(http.StatusOK, base.TplName("devtest"+path.Clean("/"+ctx.Params("sub"))))
  58. }