-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MB-6682 create and use new 404 page design (#9226)
* Redesign the 404 page and update the tests * Add route to not found to the office app * Add in middleware routing that directly disables the static and downloads paths, but not the subpaths * Change the SPA handler rather than routing_init * Return an error instead of the static directory * Revert "Return an error instead of the static directory" This reverts commit a5b27fb. * Add in font family so that the styles look the same between the office app and the customer app * Add test for 404 page on the office side * Add a custom fileSystem and use that inside of routing_init instead of the spaHandler * Fix routing so to use the build root - include the build root when building the custom file system - add more logging and error messages in the cutom file system * Use path.join instead of appending stuff together * Refactor the spa_handler to use the custom_filesystem - delete the custom_filesystem file and just directly have it inside of the spa_handler - use the custom_filesystem inside of the spa_handler to handle directory listing * Expose the custom filesystem so that it can be mocked in the tests * Add initial suite of tests * Fix test cases - remove the if check from the test since it should be ok without - fix test case so that it actually tests what is being said - add missing slashes * Fix tests for spa handler - use both afero's MemMapFs and OsFs to create the tests files - add a cleanup function * Add debugging statements to see what's going on * Remove the os check and adjust tests * Remove all the debug statements and unused code - take out the os check inside of ServeHTTP since it is already being covered by the custom file system's open * Adjust font size and spacing for the not found pages * Remove the prose designation * Fix spacing issues - adjust all the spacing between text, header, and footer * Remove the font famiy since it was creating unexpected behavior * Fix additional spacing discrepancies and how the go back button works - change the go back button to navigate to the queue instead of going back * Fix font size for mobile Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b46b8e1
commit 63f86c7
Showing
10 changed files
with
343 additions
and
37 deletions.
There are no files selected for viewing
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
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
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,155 @@ | ||
package handlers | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/suite" | ||
"go.uber.org/zap" | ||
|
||
"github.com/transcom/mymove/pkg/testingsuite" | ||
) | ||
|
||
type SpaHandlerSuite struct { | ||
*testingsuite.PopTestSuite | ||
logger *zap.Logger | ||
mfs afero.HttpFs | ||
} | ||
|
||
func setupMockFileSystem() *afero.HttpFs { | ||
afs := afero.NewMemMapFs() | ||
|
||
errMkdir := afs.MkdirAll("test", 0755) | ||
|
||
if errMkdir != nil { | ||
log.Panic(errMkdir) | ||
} | ||
|
||
errWriteFile := afero.WriteFile(afs, "/test/a", []byte("file a"), 0644) | ||
|
||
if errWriteFile != nil { | ||
log.Panic(errWriteFile) | ||
} | ||
|
||
errWriteFile = afero.WriteFile(afs, "/test/index.html", []byte("index html file"), 0644) | ||
|
||
if errWriteFile != nil { | ||
log.Panic(errWriteFile) | ||
} | ||
|
||
errMkdir = afs.MkdirAll("/test/noIndexDir", 0755) | ||
|
||
if errMkdir != nil { | ||
log.Panic(errMkdir) | ||
} | ||
|
||
errWriteFile = afero.WriteFile(afs, "/test/noIndexDir/b", []byte("file b"), 0644) | ||
|
||
if errWriteFile != nil { | ||
log.Panic(errWriteFile) | ||
} | ||
|
||
ahttpFs := afero.NewHttpFs(afs) | ||
return ahttpFs | ||
} | ||
|
||
func TestSpaHandlerSuite(t *testing.T) { | ||
logger, err := zap.NewDevelopment() | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
|
||
mfs := setupMockFileSystem() | ||
|
||
hs := &SpaHandlerSuite{ | ||
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()), | ||
logger: logger, | ||
mfs: *mfs, | ||
} | ||
suite.Run(t, hs) | ||
hs.PopTestSuite.TearDown() | ||
} | ||
|
||
type testCase struct { | ||
name string | ||
request string | ||
expectedStatusCode int | ||
expectedBody string | ||
} | ||
|
||
func (suite *SpaHandlerSuite) TestSpaHandlerServeHttp() { | ||
cases := []testCase{ | ||
{ | ||
name: "A directory without a trailing slash and that has an index.html", | ||
request: "test", | ||
expectedStatusCode: http.StatusMovedPermanently, | ||
expectedBody: "", | ||
}, | ||
{ | ||
name: "A directory with a trailing slash and that has an index.html", | ||
request: "test/", | ||
expectedStatusCode: http.StatusOK, | ||
expectedBody: "index html file", | ||
}, | ||
{ | ||
name: "A directory without a trailing slash and that does not have an index.html", | ||
request: "test/noIndexDir", | ||
expectedStatusCode: http.StatusNotFound, | ||
expectedBody: "404 page not found\n", | ||
}, | ||
{ | ||
name: "A directory with a trailing slash and that does not have an index.html", | ||
request: "test/noIndexDir/", | ||
expectedStatusCode: http.StatusNotFound, | ||
expectedBody: "404 page not found\n", | ||
}, | ||
{ | ||
name: "A file that exists in a directory that does have an index.html", | ||
request: "test/a", | ||
expectedStatusCode: http.StatusOK, | ||
expectedBody: "file a", | ||
}, | ||
{ | ||
name: "A file that exists in a directory that does not have an index.html", | ||
request: "test/noIndexDir/b", | ||
expectedStatusCode: http.StatusOK, | ||
expectedBody: "file b", | ||
}, | ||
{ | ||
name: "A file that does not exist", | ||
request: "test/c", | ||
expectedStatusCode: http.StatusNotFound, | ||
expectedBody: "404 page not found\n", | ||
}, | ||
} | ||
|
||
cfs := NewCustomFileSystem( | ||
suite.mfs, | ||
"index.html", | ||
suite.logger, | ||
) | ||
|
||
for _, testCase := range cases { | ||
suite.T().Run(testCase.name, func(t *testing.T) { | ||
|
||
req, err := http.NewRequest("GET", testCase.request, nil) | ||
suite.NoError(err) | ||
|
||
// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response. | ||
rr := httptest.NewRecorder() | ||
|
||
// Our handlers satisfy http.Handler, so we can call their ServeHTTP method | ||
// directly and pass in our Request and ResponseRecorder. | ||
sh := NewSpaHandler("", "index.html", cfs) | ||
sh.ServeHTTP(rr, req) | ||
|
||
suite.Equal(testCase.expectedStatusCode, rr.Code, "Status codes did not match when retreiving %v for request %v: expected %v, got %v", testCase.name, testCase.request, testCase.expectedStatusCode, rr.Code) | ||
|
||
// Check the response body is what we expect. | ||
suite.Equal(testCase.expectedBody, rr.Body.String(), "Handler returned unexpected body when retrieving %v: expected %v, got %v", testCase.name, testCase.expectedBody, rr.Body.String()) | ||
}) | ||
} | ||
} |
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.