Skip to content

Commit

Permalink
Merge pull request #91 from LCOGT/quick-fix/calendar
Browse files Browse the repository at this point in the history
fixes calendar bug
  • Loading branch information
capetillo authored Nov 19, 2024
2 parents 75e1226 + e46af8c commit 2364c63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/components/Scheduling/Calendar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { ref, watch, defineEmits, onMounted } from 'vue'
import { fetchSemesterData, currentSemesterEnd } from '../../utils/calendarUtils'
import { fetchSemesterData, currentSemesterEnd, parseISOString } from '../../utils/calendarUtils'
const emits = defineEmits(['updateDateRange'])
Expand All @@ -25,9 +25,13 @@ onMounted(async () => {
mode="date"
is-range
:min-date="today"
:max-date="new Date(currentSemesterEnd)"
:max-date="parseISOString(currentSemesterEnd)"
placeholder="Select Dates"
is-required
/>
@dayclick="
(_, event) => {
event.target.blur();
}
" />
</div>
</template>
19 changes: 15 additions & 4 deletions src/tests/integration/components/calendar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ import Calendar from '../../../components/Scheduling/Calendar.vue'
import { fetchSemesterData, currentSemesterEnd } from '../../../utils/calendarUtils'
import flushPromises from 'flush-promises'

vi.mock('../../../utils/calendarUtils', () => ({
fetchSemesterData: vi.fn(),
currentSemesterEnd: '2024-08-01T12:00:00Z'
}))
// Partially mock the calendarUtils module
// The terminal suggested using 'importOriginal' to do a partial mock.
// This is necessary because we want to mock some exports (like 'fetchSemesterData' and 'currentSemesterEnd')
// while keeping other exports (like 'parseISOString') unchanged and available.
// 'importOriginal' represents the original module with all its exports.
// Using 'actual' will hold all original exports, then spread them to preserve the original functionality.
vi.mock('../../../utils/calendarUtils', async (importOriginal) => {
const actual = await importOriginal()
return {
// Include all original exports
...actual,
fetchSemesterData: vi.fn(),
currentSemesterEnd: '2024-08-01T12:00:00Z'
}
})

describe('Calendar.vue', () => {
let wrapper
Expand Down
8 changes: 7 additions & 1 deletion src/utils/calendarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { useConfigurationStore } from '../stores/configuration.js'
let currentSemesterStart = null
let currentSemesterEnd = null

function parseISOString (s) {
if (s === null) return null
const b = s.split(/\D+/)
return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5], b[6]))
}

const getStartAndEndDatesOfCurrentSemester = (semesters) => {
const today = new Date()
const currentSemester = semesters.find(semester => {
Expand All @@ -30,4 +36,4 @@ const fetchSemesterData = async () => {
})
}

export { currentSemesterStart, currentSemesterEnd, fetchSemesterData }
export { currentSemesterStart, currentSemesterEnd, fetchSemesterData, parseISOString }

0 comments on commit 2364c63

Please sign in to comment.