Skip to content

Commit

Permalink
test: add unit tests (#14)
Browse files Browse the repository at this point in the history
* test(radio): unit tests

* test(tabs): update unit tests

* test(calendar): week unit tests
  • Loading branch information
shawalli authored Oct 27, 2024
1 parent 5803841 commit b286802
Show file tree
Hide file tree
Showing 28 changed files with 1,563 additions and 48 deletions.
14 changes: 14 additions & 0 deletions calendar/testdata/TestWeekModel_View/five-day-work-week.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
╭───────────────┬───────────────┬───────────────┬───────────────┬───────────────╮
│ │ │ │ │ │
│ │ │ │ │ │
│ 9/23 │ 9/24 │ 9/25 │ 9/26 │ 9/27 │
│ │ │ │ │ │
├───────────────┼───────────────┼───────────────┼───────────────┼───────────────┤
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
╰───────────────┴───────────────┴───────────────┴───────────────┴───────────────╯
14 changes: 14 additions & 0 deletions calendar/testdata/TestWeekModel_View/seven-day-week-monday.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
╭───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────╮
│ │ │ │ │ │ │ │
│ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │
│ 9/23 │ 9/24 │ 9/25 │ 9/26 │ 9/27 │ 9/28 │ 9/29 │
│ │ │ │ │ │ │ │
├───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
╰───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────╯
14 changes: 14 additions & 0 deletions calendar/testdata/TestWeekModel_View/seven-day-week.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
╭───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────┬───────────────╮
│ │ │ │ │ │ │ │
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
│ 9/22 │ 9/23 │ 9/24 │ 9/25 │ 9/26 │ 9/27 │ 9/28 │
│ │ │ │ │ │ │ │
├───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┼───────────────┤
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
╰───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────┴───────────────╯
14 changes: 14 additions & 0 deletions calendar/testdata/TestWeekModel_View/weekend.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
╭───────────────┬───────────────┬───────────────╮
│ │ │ │
│ │ │ │
│ 9/22 │ 9/27 │ 9/28 │
│ │ │ │
├───────────────┼───────────────┼───────────────┤
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
╰───────────────┴───────────────┴───────────────╯
10 changes: 1 addition & 9 deletions calendar/week.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ func (w Weekdays) Last(startDate time.Time) time.Weekday {

// Next returns the next visible weekday based on the start date.
func (w Weekdays) Next(startDate time.Time) time.Weekday {
startDate = time.Date(startDate.Year(), startDate.Month(), startDate.Day(), 0, 0, 0, 0, time.UTC)
startDate = startDate.AddDate(0, 0, 1)
return w.First((startDate))
}

// Previous returns the prior visible weekday based on the start date.
func (w Weekdays) Previous(startDate time.Time) time.Weekday {
startDate = time.Date(startDate.Year(), startDate.Month(), startDate.Day(), 0, 0, 0, 0, time.UTC)
return w.Last(startDate)
}

Expand Down Expand Up @@ -197,15 +195,9 @@ func (m WeekModel) NextDate() WeekModel {
}

var nextWeekday time.Weekday
for d := 0; d < 7; d++ {
for d := 1; d < 7; d++ {
nw := time.Weekday((int(ad.Weekday()) + d) % 7)
if m.weekdays.IsVisible(nw) {
// If it is the "same" day and it is not directly after being initialized, skip it.
// Placing the initialization logic inside the loop allows [WeekModel] to have a startDate that is before
// the first visible day. For example, the week starts on Sunday but the first visible day is Monday.
if (d == 0) && (m.activeDate != (time.Time{})) {
continue
}
nextWeekday = nw
break
}
Expand Down
Loading

0 comments on commit b286802

Please sign in to comment.