lots of changes
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestLoginAttendanceAndReportFlow(t *testing.T) {
|
||||
@@ -85,6 +86,48 @@ func TestLoginAttendanceAndReportFlow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttendanceTimesUseConfiguredTimezoneAndShowCheckout(t *testing.T) {
|
||||
s, err := New(Config{
|
||||
Addr: ":0",
|
||||
BaseURL: "http://example.test",
|
||||
DatabasePath: filepath.Join(t.TempDir(), "timezone.db"),
|
||||
Timezone: "Asia/Tehran",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
day := time.Now().Format("2006-01-02")
|
||||
legacyCheckIn := day + " 11:48:51.004976173 +0330 +0330 m=+18.184759346"
|
||||
checkOut := day + " 11:49:32.496818296 +0330 +0330 m=+59.676601465"
|
||||
if _, err := s.store.db.Exec(
|
||||
`INSERT INTO attendance(user_id,day,check_in,check_out,mode) VALUES(?,?,?,?,?)`,
|
||||
1, day, legacyCheckIn, checkOut, "office",
|
||||
); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, _, err := s.store.CreateSession(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
request.AddCookie(&http.Cookie{Name: "teammate_session", Value: token})
|
||||
response := httptest.NewRecorder()
|
||||
s.http.Handler.ServeHTTP(response, request)
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("dashboard status: %d body %s", response.Code, response.Body.String())
|
||||
}
|
||||
for _, expected := range []string{"11:48", "11:49", "Day complete"} {
|
||||
if !strings.Contains(response.Body.String(), expected) {
|
||||
t.Fatalf("dashboard does not include %q: %s", expected, response.Body.String())
|
||||
}
|
||||
}
|
||||
if strings.Contains(response.Body.String(), `action="/attendance/check-out"`) {
|
||||
t.Fatal("completed attendance still shows the checkout action")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPersianRequestDateParsing(t *testing.T) {
|
||||
got, ok := parseUserDate("1405-05-06")
|
||||
if !ok || got != "2026-07-28" {
|
||||
@@ -166,6 +209,9 @@ func TestPublicRegistrationAndIdentifierLogin(t *testing.T) {
|
||||
t.Fatalf("register page does not include %q", expected)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(registerView.Body.String(), `/static/favicon.svg`) {
|
||||
t.Fatal("register page does not include the favicon")
|
||||
}
|
||||
|
||||
themeRequest := httptest.NewRequest(http.MethodGet, "/static/theme.js", nil)
|
||||
themeResponse := httptest.NewRecorder()
|
||||
@@ -174,6 +220,13 @@ func TestPublicRegistrationAndIdentifierLogin(t *testing.T) {
|
||||
t.Fatalf("theme asset: got %d, body %s", themeResponse.Code, themeResponse.Body.String())
|
||||
}
|
||||
|
||||
faviconRequest := httptest.NewRequest(http.MethodGet, "/static/favicon.svg", nil)
|
||||
faviconResponse := httptest.NewRecorder()
|
||||
s.http.Handler.ServeHTTP(faviconResponse, faviconRequest)
|
||||
if faviconResponse.Code != http.StatusOK || !strings.Contains(faviconResponse.Body.String(), `<svg`) {
|
||||
t.Fatalf("favicon asset: got %d, body %s", faviconResponse.Code, faviconResponse.Body.String())
|
||||
}
|
||||
|
||||
register := formRequest(t, s.http.Handler, "/register", url.Values{
|
||||
"display_name": {"Neda Karimi"},
|
||||
"email": {"neda@example.test"},
|
||||
@@ -294,6 +347,31 @@ func TestTeamDayShowsPresentRemoteAndAbsent(t *testing.T) {
|
||||
t.Fatalf("day page does not include %q", expected)
|
||||
}
|
||||
}
|
||||
|
||||
weekRequest := httptest.NewRequest(http.MethodGet, "/day?date="+selectedDay+"&view=week", nil)
|
||||
weekRequest.AddCookie(&http.Cookie{Name: "teammate_session", Value: token})
|
||||
weekResponse := httptest.NewRecorder()
|
||||
s.http.Handler.ServeHTTP(weekResponse, weekRequest)
|
||||
if weekResponse.Code != http.StatusOK {
|
||||
t.Fatalf("week page status: %d, body %s", weekResponse.Code, weekResponse.Body.String())
|
||||
}
|
||||
body := weekResponse.Body.String()
|
||||
if !strings.Contains(body, "TEAM WEEK") || !strings.Contains(body, "SATURDAY — FRIDAY") {
|
||||
t.Fatalf("week page header is missing: %s", body)
|
||||
}
|
||||
if count := strings.Count(body, `class="week-day-column`); count != 7 {
|
||||
t.Fatalf("week page has %d day columns, want 7", count)
|
||||
}
|
||||
saturday := strings.Index(body, ">Saturday<")
|
||||
friday := strings.Index(body, ">Friday<")
|
||||
if saturday < 0 || friday < 0 || saturday >= friday {
|
||||
t.Fatal("week page is not ordered Saturday through Friday")
|
||||
}
|
||||
for _, expected := range []string{"Workspace Admin", "Remote Teammate", "Absent Teammate", "Approved remote day", "Approved time off"} {
|
||||
if !strings.Contains(body, expected) {
|
||||
t.Fatalf("week page does not include %q", expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkUpdateSubmissionFeedAndCSV(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user