diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-02-08 09:50:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-08 01:50:48 +0000 |
commit | a4859dcfea0cf1c7818f3cb2dcbb6b83902cc9d5 (patch) | |
tree | 0de3f0eea888d67b87a68e8397e74148329945d2 /modules/contexttest/context_tests.go | |
parent | 5c0fc9087211f01375f208d679a1e6de0685320c (diff) | |
download | gitea-a4859dcfea0cf1c7818f3cb2dcbb6b83902cc9d5.tar.gz gitea-a4859dcfea0cf1c7818f3cb2dcbb6b83902cc9d5.zip |
Improve user experience for outdated comments (#29050)
Try to improve #28949
1. Make `ctx.Data["ShowOutdatedComments"] = true` by default: it brings
consistent user experience, and sometimes the "outdated (source
changed)" comments are still valuable.
2. Show a friendly message if the comment won't show, then the end users
won't fell that "the comment disappears" (it is the special case when
`ShowOutdatedComments = false`)
Diffstat (limited to 'modules/contexttest/context_tests.go')
-rw-r--r-- | modules/contexttest/context_tests.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/modules/contexttest/context_tests.go b/modules/contexttest/context_tests.go index 9ca028bb6e..c9bacf259f 100644 --- a/modules/contexttest/context_tests.go +++ b/modules/contexttest/context_tests.go @@ -40,8 +40,19 @@ func mockRequest(t *testing.T, reqPath string) *http.Request { return req } +type MockContextOption struct { + Render context.Render +} + // MockContext mock context for unit tests -func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.ResponseRecorder) { +func MockContext(t *testing.T, reqPath string, opts ...MockContextOption) (*context.Context, *httptest.ResponseRecorder) { + var opt MockContextOption + if len(opts) > 0 { + opt = opts[0] + } + if opt.Render == nil { + opt.Render = &MockRender{} + } resp := httptest.NewRecorder() req := mockRequest(t, reqPath) base, baseCleanUp := context.NewBaseContext(resp, req) @@ -49,7 +60,7 @@ func MockContext(t *testing.T, reqPath string) (*context.Context, *httptest.Resp base.Data = middleware.GetContextData(req.Context()) base.Locale = &translation.MockLocale{} - ctx := context.NewWebContext(base, &MockRender{}, nil) + ctx := context.NewWebContext(base, opt.Render, nil) chiCtx := chi.NewRouteContext() ctx.Base.AppendContextValue(chi.RouteCtxKey, chiCtx) |