-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from LCOGT/feature/calendar
Feature/calendar
- Loading branch information
Showing
11 changed files
with
206 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
<script setup> | ||
import { ref, watch, defineEmits } from 'vue' | ||
import VueDatePicker from '@vuepic/vue-datepicker' | ||
import '@vuepic/vue-datepicker/dist/main.css' | ||
import { ref, watch, defineEmits, onMounted } from 'vue' | ||
import { fetchSemesterData, currentSemesterEnd } from '../../utils/calendarUtils' | ||
const emits = defineEmits(['updateDateRange']) | ||
// here's the documentation for vuedatepicker: | ||
// https://vue3datepicker.com/props/general-configuration/ | ||
const dateRange = ref() | ||
const today = new Date() | ||
watch(dateRange, (newVal) => { | ||
emits('updateDateRange', newVal) | ||
}) | ||
const currentDate = new Date() | ||
onMounted(async () => { | ||
await fetchSemesterData() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="container"> | ||
<h3>Select a Date Range</h3> | ||
<VueDatePicker | ||
<VDatePicker | ||
v-model="dateRange" | ||
range | ||
:enable-time-picker="false" | ||
:min-date="new Date()" | ||
:max-date="new Date(currentDate.setDate(currentDate.getDate() + 15))" | ||
mode="date" | ||
is-range | ||
:min-date="today" | ||
:max-date="new Date(currentSemesterEnd)" | ||
placeholder="Select Dates" | ||
required | ||
:date-range="dateRange" | ||
class="custom-date-picker" | ||
is-required | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.custom-date-picker { | ||
width: 20%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import { describe, it, expect, vi, beforeEach } from 'vitest' | ||
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' | ||
})) | ||
|
||
describe('Calendar.vue', () => { | ||
let wrapper | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
|
||
const VDatePickerStub = { | ||
name: 'VDatePicker', | ||
template: '<div></div>', | ||
props: ['max-date'] | ||
} | ||
|
||
wrapper = shallowMount(Calendar, { | ||
global: { | ||
stubs: { | ||
VDatePicker: VDatePickerStub | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
it('calls fetchSemesterData on mount', () => { | ||
expect(fetchSemesterData).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('passes the correct max-date to VDatePicker', async () => { | ||
await flushPromises() | ||
const datePicker = wrapper.findComponent({ name: 'VDatePicker' }) | ||
expect(datePicker.exists()).toBe(true) | ||
// Note: The prop name 'maxDate' is camel-cased instead of using 'max-date' because Vue automatically converts kebab-case prop names to camelCase | ||
// when passing them in js. In templates, we use 'max-date', but when accessing props programmatically, we use 'maxDate' | ||
const maxDateProp = datePicker.props('maxDate') | ||
const maxDateIsoString = new Date(maxDateProp).toISOString().split('.')[0] + 'Z' | ||
expect(maxDateIsoString).toBe(currentSemesterEnd) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { vi, describe, it, expect, beforeEach } from 'vitest' | ||
import { fetchApiCall } from '../../../utils/api.js' | ||
import { fetchSemesterData, currentSemesterEnd, currentSemesterStart } from '../../../utils/calendarUtils.js' | ||
import { createTestStores } from '../../../utils/testUtils' | ||
|
||
vi.mock('@/utils/api.js', () => ({ | ||
fetchApiCall: vi.fn() | ||
})) | ||
|
||
describe('calendarUtils.js', () => { | ||
let configurationStore | ||
|
||
beforeEach(() => { | ||
const { configurationStore: store } = createTestStores() | ||
configurationStore = store | ||
fetchApiCall.mockClear() | ||
}) | ||
|
||
describe('fetchSemesterData', () => { | ||
it('sets currentSemesterStart and currentSemesterEnd after making the fetchApiCall', async () => { | ||
const mockResponse = { | ||
results: [ | ||
{ start: '2024-01-01', end: '2024-06-30' }, | ||
{ start: '2024-07-01', end: '2024-12-31' } | ||
] | ||
} | ||
|
||
// Mocking today's date to ensure the correct semester is selected | ||
const today = new Date('2024-08-15') | ||
// This sets the system time to the provided date | ||
vi.setSystemTime(today) | ||
|
||
fetchApiCall.mockImplementationOnce(({ successCallback }) => { | ||
successCallback(mockResponse) | ||
}) | ||
|
||
await fetchSemesterData() | ||
|
||
expect(fetchApiCall).toHaveBeenCalledTimes(1) | ||
expect(fetchApiCall).toHaveBeenCalledWith({ | ||
url: 'http://mock-api.com/semesters/', | ||
method: 'GET', | ||
successCallback: expect.any(Function) | ||
}) | ||
|
||
expect(currentSemesterStart).toBe('2024-07-01') | ||
expect(currentSemesterEnd).toBe('2024-12-31') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.