-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* year-agnostic interop pages * interchangeable prose and issue URL * lint * eslint changes * last linting update * add date limiter * typo * 2021 uses same csv parser * comments * change view by year * redirect compat2021 to interop-2021 * redirect for invalid years * Add tests for interop handler * changes suggested by @jcscottiii * Update webapp/components/interop.js Co-authored-by: Kyle Ju <[email protected]> * remove unused variable * Reference all year info from the data manager Co-authored-by: Kyle Ju <[email protected]>
- Loading branch information
1 parent
859f043
commit 9c7b693
Showing
8 changed files
with
604 additions
and
347 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
548 changes: 277 additions & 271 deletions
548
webapp/components/interop-2022.js → webapp/components/interop.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 The WPT Dashboard Project. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package webapp | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/web-platform-tests/wpt.fyi/shared" | ||
) | ||
|
||
type interopData struct { | ||
Embedded bool | ||
Year string | ||
} | ||
|
||
// Set of years that are valid for Interop 20XX. | ||
var validYears = map[string]bool{"2021": true, "2022": true} | ||
|
||
// Year that any invalid year will redirect to. | ||
const defaultRedirectYear = "2022" | ||
|
||
// interopHandler handles GET requests to /interop-20XX and /compat20XX | ||
func interopHandler(w http.ResponseWriter, r *http.Request) { | ||
name := mux.Vars(r)["name"] | ||
year := mux.Vars(r)["year"] | ||
|
||
// /compat20XX redirects to /interop-20XX | ||
needsRedirect := name == "compat" | ||
// TODO(danielrsmith): Change this redirect for next year's interop page. | ||
if _, ok := validYears[year]; !ok { | ||
year = defaultRedirectYear | ||
needsRedirect = true | ||
} | ||
|
||
if needsRedirect { | ||
destination := *(r.URL) | ||
|
||
destination.Path = fmt.Sprintf("interop-%s", year) | ||
http.Redirect(w, r, destination.String(), http.StatusTemporaryRedirect) | ||
return | ||
} | ||
|
||
if r.Method != "GET" { | ||
http.Error(w, "Only GET is supported.", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
q := r.URL.Query() | ||
embedded, err := shared.ParseBooleanParam(q, "embedded") | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
data := interopData{ | ||
Embedded: embedded != nil && *embedded, | ||
Year: year, | ||
} | ||
RenderTemplate(w, r, "interop.html", data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// +build small | ||
|
||
package webapp | ||
|
||
// Copyright 2022 The WPT Dashboard Project. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInteropHandler_redirect(t *testing.T) { | ||
// 1999 is an invalid interop year and should be redirected. | ||
req := httptest.NewRequest("GET", "/interop-1999?embedded", strings.NewReader("{}")) | ||
req = mux.SetURLVars(req, map[string]string{ | ||
"name": "interop", | ||
"year": "1999", | ||
"embedded": "true", | ||
}) | ||
|
||
w := httptest.NewRecorder() | ||
interopHandler(w, req) | ||
resp := w.Result() | ||
assert.Equal(t, resp.StatusCode, http.StatusTemporaryRedirect) | ||
|
||
loc, err := resp.Location() | ||
assert.Nil(t, err) | ||
// Check if embedded param is maintained after redirect. | ||
assert.NotEqual(t, loc.Path, "interop-2022?embedded") | ||
} | ||
|
||
func TestInteropHandler_compatRedirect(t *testing.T) { | ||
// "/compat20XX" paths should redirect to the interop version of the given year. | ||
req := httptest.NewRequest("GET", "/compat2021", strings.NewReader("{}")) | ||
req = mux.SetURLVars(req, map[string]string{ | ||
"name": "compat", | ||
"year": "2021", | ||
}) | ||
|
||
w := httptest.NewRecorder() | ||
interopHandler(w, req) | ||
resp := w.Result() | ||
assert.Equal(t, resp.StatusCode, http.StatusTemporaryRedirect) | ||
} | ||
|
||
func TestInteropHandler_success(t *testing.T) { | ||
// A typical "/interop-20XX" path with a valid year should not redirect. | ||
req := httptest.NewRequest("GET", "/interop-"+defaultRedirectYear, strings.NewReader("{}")) | ||
req = mux.SetURLVars(req, map[string]string{ | ||
"name": "interop", | ||
"year": defaultRedirectYear, | ||
}) | ||
|
||
w := httptest.NewRecorder() | ||
interopHandler(w, req) | ||
resp := w.Result() | ||
assert.Equal(t, resp.StatusCode, http.StatusOK) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.