81 lines
3.1 KiB
JavaScript
81 lines
3.1 KiB
JavaScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import ItemModal from '../src/components/ItemModal.vue'
|
|
|
|
vi.mock('../src/api.js', () => ({
|
|
updateItem: vi.fn(async (id, fields) => ({ id, ...fields })),
|
|
}))
|
|
|
|
function makeItem(overrides = {}) {
|
|
return {
|
|
id: 1,
|
|
modality: 'bh_email',
|
|
sender_id: 'jane@example.com',
|
|
raw_content: 'I have some books to donate.',
|
|
type: null,
|
|
stage: 'new',
|
|
notes: '',
|
|
follow_up_date: '',
|
|
direction: 'inbound',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('ItemModal', () => {
|
|
it('offers the donation stages when item.type is donation', () => {
|
|
const wrapper = mount(ItemModal, { props: { item: makeItem({ type: 'donation', stage: 'new' }) } })
|
|
const options = wrapper.findAll('select')[1].findAll('option').map((o) => o.element.value)
|
|
expect(options).toEqual([
|
|
'new', 'replied', 'pickup_scheduled', 'picked_up', 'logged_in_bookmark',
|
|
])
|
|
})
|
|
|
|
it('offers only new/done stages when item.type is other', () => {
|
|
const wrapper = mount(ItemModal, { props: { item: makeItem({ type: 'other', stage: 'new' }) } })
|
|
const options = wrapper.findAll('select')[1].findAll('option').map((o) => o.element.value)
|
|
expect(options).toEqual(['new', 'done'])
|
|
})
|
|
|
|
it('offers only the new stage when item.type is unset/null', () => {
|
|
const wrapper = mount(ItemModal, { props: { item: makeItem({ type: null, stage: 'new' }) } })
|
|
const options = wrapper.findAll('select')[1].findAll('option').map((o) => o.element.value)
|
|
expect(options).toEqual(['new'])
|
|
})
|
|
|
|
it('resets stage to new when type changes away from donation while stage is pickup_scheduled', async () => {
|
|
const wrapper = mount(ItemModal, {
|
|
props: { item: makeItem({ type: 'donation', stage: 'pickup_scheduled' }) },
|
|
})
|
|
const stageSelect = wrapper.findAll('select')[1]
|
|
expect(stageSelect.element.value).toBe('pickup_scheduled')
|
|
|
|
const typeSelect = wrapper.findAll('select')[0]
|
|
await typeSelect.setValue('other')
|
|
|
|
expect(wrapper.findAll('select')[1].element.value).toBe('new')
|
|
})
|
|
|
|
it('offers outbound stages when item.direction is outbound, regardless of type', () => {
|
|
const wrapper = mount(ItemModal, {
|
|
props: { item: makeItem({ direction: 'outbound', type: 'donation', stage: 'new' }) },
|
|
})
|
|
const options = wrapper.findAll('select')[1].findAll('option').map((o) => o.element.value)
|
|
expect(options).toEqual([
|
|
'new', 'reviewed', 'outreach_drafted', 'outreach_sent',
|
|
'replied', 'pickup_scheduled', 'picked_up', 'logged_in_bookmark',
|
|
])
|
|
})
|
|
|
|
it('does not reset an outbound item stage when type changes', async () => {
|
|
const wrapper = mount(ItemModal, {
|
|
props: { item: makeItem({ direction: 'outbound', type: 'donation', stage: 'outreach_sent' }) },
|
|
})
|
|
const stageSelect = wrapper.findAll('select')[1]
|
|
expect(stageSelect.element.value).toBe('outreach_sent')
|
|
|
|
const typeSelect = wrapper.findAll('select')[0]
|
|
await typeSelect.setValue('other')
|
|
|
|
expect(wrapper.findAll('select')[1].element.value).toBe('outreach_sent')
|
|
})
|
|
})
|