Skip to content

Commit

Permalink
adds functionality to delete session, added class, and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
capetillo committed Sep 3, 2024
1 parent 2f0aa82 commit 9138285
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/Dashboard/UpcomingBookings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ onMounted(() => {
<h3 v-else>No Real-Time Sessions Booked</h3>
<div class="table-summary">
<div v-for="session in sortedSessions" :key="session.id">
<div><a @click.prevent="selectSession(session.id)">{{ formatDate(session.start) }}</a></div><div>{{ formatTime(session.start) }}</div>
<div><a @click.prevent="selectSession(session.id)" class="date">{{ formatDate(session.start) }}</a></div><div>{{ formatTime(session.start) }}</div>
<button @click="deleteSession(session.id)" class="deleteButton">x</button>
</div>
</div>
Expand Down
18 changes: 18 additions & 0 deletions src/tests/integration/components/upcomingBookings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ describe('UpcomingBookings.vue', () => {
const h3Text = wrapper.find('h3').text()
expect(h3Text).toBe('Upcoming Bookings')
})

it('deletes a session on click', async () => {
fetchApiCall.mockImplementation(({ url }) => {
if (url.includes('session1')) {
sessionsStore.sessions.results = sessionsStore.sessions.results.filter(session => session.id !== 'session1')
}
})
const deleteButtons = wrapper.findAll('.deleteButton')
expect(deleteButtons.length).toBe(2)
await deleteButtons.at(0).trigger('click')
expect(fetchApiCall).toHaveBeenCalledWith(
expect.objectContaining({
url: 'http://mock-api.com/realtime/session1/',
method: 'DELETE'
})
)
expect(sessionsStore.sessions.results.length).toBe(1)
})
})

0 comments on commit 9138285

Please sign in to comment.