@@ -171,6 +171,46 @@ func TestDashboardHandlerBuildsCalendarAlignedFilter(t *testing.T) {
171171 }
172172}
173173
174+ func TestDashboardHandlerBuildsYearlyCalendarAlignedFilter (t * testing.T ) {
175+ t .Setenv ("TZ" , "Asia/Shanghai" )
176+ now := time .Date (2026 , 6 , 16 , 9 , 30 , 0 , 0 , time .FixedZone ("CST" , 8 * 3600 ))
177+ previousLocal := time .Local
178+ time .Local = now .Location ()
179+ defer func () {
180+ time .Local = previousLocal
181+ }()
182+
183+ stub := & dashboardUsageStub {
184+ summary : usage.EventSummary {RequestCount : 1 },
185+ }
186+ handler := api .NewDashboardHandler (stub )
187+
188+ req := httptest .NewRequest (http .MethodGet , "/dashboard/summary?range=1y" , nil )
189+ rec := httptest .NewRecorder ()
190+
191+ restore := api .SetDashboardNowForTest (func () time.Time { return now })
192+ defer restore ()
193+
194+ handler .ServeHTTP (rec , req )
195+ if rec .Code != http .StatusOK {
196+ t .Fatalf ("GET /dashboard/summary status = %d, want %d" , rec .Code , http .StatusOK )
197+ }
198+ if stub .lastFilter .From == nil || stub .lastFilter .To == nil {
199+ t .Fatalf ("expected filter bounds to be set" )
200+ }
201+ wantFrom := time .Date (2025 , 6 , 16 , 16 , 0 , 0 , 0 , time .UTC )
202+ wantTo := time .Date (2026 , 6 , 16 , 16 , 0 , 0 , 0 , time .UTC )
203+ if ! stub .lastFilter .From .Equal (wantFrom ) || ! stub .lastFilter .To .Equal (wantTo ) {
204+ t .Fatalf ("filter bounds = %v..%v, want %v..%v" , stub .lastFilter .From , stub .lastFilter .To , wantFrom , wantTo )
205+ }
206+ if stub .lastFilter .BucketSize != 24 * time .Hour {
207+ t .Fatalf ("BucketSize = %v, want %v" , stub .lastFilter .BucketSize , 24 * time .Hour )
208+ }
209+ if stub .lastFilter .BucketLocation != time .Local {
210+ t .Fatalf ("BucketLocation = %v, want time.Local" , stub .lastFilter .BucketLocation )
211+ }
212+ }
213+
174214func TestDashboardHandlerBuildsServerUserFilter (t * testing.T ) {
175215 t .Parallel ()
176216
0 commit comments