Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more timeable tests #161

Merged
merged 8 commits into from
Jan 16, 2025
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI - ESLint, Prettier, Jest, and Codecov
name: CI - ESLint, Prettier, Tests
on:
push:
branches: [develop, main]
Expand All @@ -12,7 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 3

- name: Set up Bun
uses: oven-sh/setup-bun@v2
Expand All @@ -30,11 +30,10 @@ jobs:
run: bunx jest --coverage --reporters=jest-junit

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v4
with:
directory: ${{ github.action_path }}
token: ${{ secrets.CODECOV_TOKEN }}
slug: getsentry/self-hosted

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
Expand Down
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ coverage:
base: auto
paths:
- 'src'
comment:
layout: ' diff, flags, files'
behavior: default
require_changes: false # if true: only post the comment if coverage changes
require_base: false # [true :: must have a base report to post]
require_head: true # [true :: must have a head report to post]
hide_project_coverage: false
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)"
],
"coverageReporters": ["text", "cobertura"],
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{ts,tsx,js,jsx}",
Expand Down
3 changes: 3 additions & 0 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export interface TimetableSections {
}

export interface CalendarEvent {
start: Date
end: Date
title: string
textColor: string
color: string
location?: string
Expand Down
79 changes: 78 additions & 1 deletion src/utils/__tests__/timetable-utils-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Exam, FriendlyTimetableEntry, TimetableSections } from '@/types/utils'
import {
CalendarEvent,
Exam,
FriendlyTimetableEntry,
TimetableSections,
} from '@/types/utils'
import moment from 'moment'

import {
convertTimetableToWeekViewEvents,
generateKey,
getGroupedTimetable,
isValidRoom,
Expand Down Expand Up @@ -175,8 +181,79 @@ describe('isValidRoom', () => {
it('should return false for invalid room strings', () => {
expect(isValidRoom('101')).toBe(false)
expect(isValidRoom('Online')).toBe(false)
expect(isValidRoom('Campuswiese')).toBe(false)
expect(isValidRoom('AB1234')).toBe(false)
expect(isValidRoom('A1U01')).toBe(false)
expect(isValidRoom('')).toBe(false)
})
})

describe('convertTimetableToWeekViewEvents', () => {
it('should convert timetable entries to calendar events', () => {
const entries: FriendlyTimetableEntry[] = [
{
date: new Date('2023-10-01T10:00:00Z'),
startDate: new Date('2023-10-01T10:00:00Z'),
endDate: new Date('2023-10-01T11:00:00Z'),
name: 'Lecture 1',
shortName: 'Lec 1',
rooms: ['Room 1'],
lecturer: 'Dr. Smith',
course: 'Course 1',
studyGroup: 'Group 1',
sws: '2',
ects: '3',
goal: 'Goal 1',
contents: 'Contents 1',
literature: 'Literature 1',
},
{
date: new Date('2023-10-02T12:00:00Z'),
startDate: new Date('2023-10-02T12:00:00Z'),
endDate: new Date('2023-10-02T13:00:00Z'),
name: 'Lecture 2',
shortName: 'Lec 2',
rooms: ['Room 2'],
lecturer: 'Dr. Johnson',
course: 'Course 2',
studyGroup: 'Group 2',
sws: '2',
ects: '3',
goal: 'Goal 2',
contents: 'Contents 2',
literature: 'Literature 2',
},
]

const color = 'blue'
const textColor = 'white'

const expectedOutput: CalendarEvent[] = [
{
start: entries[0].startDate,
end: entries[0].endDate,
title: entries[0].shortName,
color,
textColor,
location: 'Room 1',
entry: entries[0],
},
{
start: entries[1].startDate,
end: entries[1].endDate,
title: entries[1].shortName,
color,
textColor,
location: 'Room 2',
entry: entries[1],
},
]

const result = convertTimetableToWeekViewEvents(
entries,
color,
textColor
)
expect(result).toEqual(expectedOutput)
})
})
Loading