package handlers_test import ( "net/http" "net/http/httptest" "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sneak.berlin/go/upaas/internal/service/app" ) // TestAppPageLayout checks the app page's width, the order of its sections, // and the height of its two log boxes. func TestAppPageLayout(t *testing.T) { t.Parallel() testCtx := setupTestHandlers(t) createdApp, err := testCtx.appSvc.CreateApp(t.Context(), app.CreateAppInput{ Name: "layout-app", RepoURL: "git@example.com:user/layout-app.git", }) require.NoError(t, err) request := httptest.NewRequestWithContext( t.Context(), http.MethodGet, "/apps/"+createdApp.ID, nil, ) request = addChiURLParams(request, map[string]string{"id": createdApp.ID}) recorder := httptest.NewRecorder() testCtx.handlers.HandleAppDetail().ServeHTTP(recorder, request) require.Equal(t, http.StatusOK, recorder.Code) body := recorder.Body.String() _, afterMain, found := strings.Cut(body, "") assert.Contains(t, mainTag, "max-width: 84rem;") sectionTitles := []string{ "Container Logs", "Deploy Key", "Webhook URL", "Last Deployment Build Logs", "Environment Variables", "Docker Labels", "Volume Mounts", "Port Mappings", "Recent Deployments", "Danger Zone", } previousIndex := -1 for _, title := range sectionTitles { index := strings.Index(body, ">"+title+"") require.NotEqual(t, -1, index, "app page has no %q section", title) assert.Greater(t, index, previousIndex, "%q section is out of order", title) previousIndex = index } for _, logBox := range []string{"containerLogsWrapper", "buildLogsWrapper"} { _, afterRef, found := strings.Cut(body, `x-ref="`+logBox+`"`) require.True(t, found, "app page has no %s", logBox) logBoxTag, _, _ := strings.Cut(afterRef, ">") assert.Contains(t, logBoxTag, "max-height: 800px;", logBox) } }