diff --git a/src/components/Global/ProposalDropdown.vue b/src/components/Global/ProposalDropdown.vue new file mode 100644 index 0000000..23b7451 --- /dev/null +++ b/src/components/Global/ProposalDropdown.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/components/RealTimeInterface/TimePicker.vue b/src/components/RealTimeInterface/TimePicker.vue index 61901c1..f171d93 100644 --- a/src/components/RealTimeInterface/TimePicker.vue +++ b/src/components/RealTimeInterface/TimePicker.vue @@ -7,6 +7,7 @@ import { fetchApiCall } from '../../utils/api' import { formatToUTC, formatDate } from '../../utils/formatTime.js' import { useConfigurationStore } from '../../stores/configuration' import LeafletMap from './GlobeMap/LeafletMap.vue' +import ProposalDropdown from '../Global/ProposalDropdown.vue' const router = useRouter() const realTimeSessionsStore = useRealTimeSessionsStore() @@ -19,6 +20,7 @@ const errorMessage = ref(null) const selectedSite = ref(null) const availableTimes = ref({}) const localTimes = ref([]) +const selectedProposal = ref() const timeInterval = 15 const today = ref(new Date()) @@ -171,7 +173,7 @@ const blockRti = async () => { } const requestBody = { - proposal: 'LCORealtimeTest', + proposal: selectedProposal.value, name: 'Test Real Time', site: selectedSite.value.site, enclosure, @@ -254,8 +256,9 @@ onMounted(() => { diff --git a/src/components/Scheduling/BeginnerScheduling.vue b/src/components/Scheduling/BeginnerScheduling.vue index eb98af0..12d963b 100644 --- a/src/components/Scheduling/BeginnerScheduling.vue +++ b/src/components/Scheduling/BeginnerScheduling.vue @@ -3,6 +3,7 @@ import { ref, defineEmits } from 'vue' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import Calendar from './Calendar.vue' import SchedulingSettings from './SchedulingSettings.vue' +import ProposalDropdown from '../Global/ProposalDropdown.vue' import { fetchApiCall } from '../../utils/api.js' const emits = defineEmits(['selectionsComplete', 'showButton']) @@ -19,6 +20,7 @@ const loading = ref(false) const selectedTargets = ref([]) const startDate = ref('') const endDate = ref('') +const selectedProposal = ref() const categories = ref([ { @@ -81,7 +83,8 @@ const emitSelections = () => { target: targetSelection.value, settings: exposureSettings.value, startDate: startDate.value, - endDate: endDate.value + endDate: endDate.value, + proposal: selectedProposal.value }) // } } @@ -187,9 +190,10 @@ const handleExposuresUpdate = (exposures) => {
- + +
-
+

Schedule an Observation

What do you want to take pictures of?

diff --git a/src/components/Views/SchedulingView.vue b/src/components/Views/SchedulingView.vue index 38b35dd..de870d9 100644 --- a/src/components/Views/SchedulingView.vue +++ b/src/components/Views/SchedulingView.vue @@ -107,8 +107,7 @@ const sendObservationRequest = async () => { method: 'POST', body: { 'name': 'UserObservation', - // TO DO: get proposals from user and use the proposal ID here - 'proposal': 'LCOSchedulerTest', + 'proposal': observationData.value.proposal, 'ipp_value': 1.05, 'operator': operatorValue.value, 'observation_type': 'NORMAL', diff --git a/src/tests/integration/components/beginnerScheduling.test.js b/src/tests/integration/components/beginnerScheduling.test.js index 3415dd4..fe3fc21 100644 --- a/src/tests/integration/components/beginnerScheduling.test.js +++ b/src/tests/integration/components/beginnerScheduling.test.js @@ -5,7 +5,7 @@ import { fetchApiCall } from '../../../utils/api.js' import { createTestStores } from '../../../utils/testUtils' import flushPromises from 'flush-promises' -vi.mock('@/utils/api.js', () => ({ +vi.mock('../../../utils/api.js', () => ({ fetchApiCall: vi.fn() })) @@ -18,7 +18,16 @@ describe('BeginnerScheduling.vue', () => { wrapper = mount(BeginnerScheduling, { global: { - plugins: [pinia] + plugins: [pinia], + stubs: { + // Mock ProposalDropdown to control selectedProposal behavior + ProposalDropdown: { + template: '
', + methods: { + selectionsComplete: vi.fn() + } + } + } } }) }) @@ -41,10 +50,12 @@ describe('BeginnerScheduling.vue', () => { successCallback(mockResponse) }) + // Simulate setting a selected proposal + wrapper.vm.selectedProposal = 'TestProposal' + // Simulate selecting a date range (which triggers fetchTargets) const startDate = new Date() const endDate = new Date() - // Adds 15 days to the start date endDate.setDate(startDate.getDate() + 15) const newDateRange = { start: startDate, @@ -52,8 +63,7 @@ describe('BeginnerScheduling.vue', () => { } await wrapper.vm.handleDateRangeUpdate(newDateRange) - // Because the Calendar component is a child of BeginnerScheduling, this test also makes the api call to fetch semester data (which is not tested here) - expect(fetchApiCall).toHaveBeenCalledTimes(2) + expect(fetchApiCall).toHaveBeenCalledTimes(1) expect(fetchApiCall).toHaveBeenCalledWith({ url: `https://whatsup.lco.global/range/?start=${newDateRange.start.toISOString().split('.')[0]}&end=${newDateRange.end.toISOString().split('.')[0]}&aperture=0m4&mode=full`, method: 'GET', @@ -71,4 +81,26 @@ describe('BeginnerScheduling.vue', () => { expect(wrapper.vm.selectedTargets[0].filters[0].exposure).toBe(300) expect(wrapper.vm.selectedTargets[0].filters[0].count).toBe(5) }) + + it('emits selectionsComplete with selectedProposal and other values', async () => { + // Simulate setting selected values + wrapper.vm.targetSelection = { name: 'Target 1' } + wrapper.vm.exposureSettings = [{ filter: 'Filter 1', exposureTime: 300 }] + wrapper.vm.startDate = '2024-11-18T00:00:00' + wrapper.vm.endDate = '2024-11-19T00:00:00' + wrapper.vm.selectedProposal = 'TestProposal' + + // Call emitSelections + wrapper.vm.emitSelections() + + // Check if the selectionsComplete event was emitted with the correct data + expect(wrapper.emitted().selectionsComplete).toBeTruthy() + expect(wrapper.emitted().selectionsComplete[0][0]).toEqual({ + target: { name: 'Target 1' }, + settings: [{ filter: 'Filter 1', exposureTime: 300 }], + startDate: '2024-11-18T00:00:00', + endDate: '2024-11-19T00:00:00', + proposal: 'TestProposal' + }) + }) }) diff --git a/src/tests/integration/components/schedulingView.test.js b/src/tests/integration/components/schedulingView.test.js index 939b6a2..a912ad9 100644 --- a/src/tests/integration/components/schedulingView.test.js +++ b/src/tests/integration/components/schedulingView.test.js @@ -31,7 +31,8 @@ describe('SchedulingView.vue', () => { ], startDate: new Date(), // 1 hour later - endDate: new Date(new Date().getTime() + 3600 * 1000) + endDate: new Date(new Date().getTime() + 3600 * 1000), + proposal: 'Test Proposal' } const mockRequestList = [ @@ -114,7 +115,7 @@ describe('SchedulingView.vue', () => { method: 'POST', body: { name: 'UserObservation', - proposal: 'LCOSchedulerTest', + proposal: 'Test Proposal', ipp_value: 1.05, operator: 'SINGLE', observation_type: 'NORMAL',