// Some stuff
const mockRouterPush = vi.fn();
mockNuxtImport('useRouter', () => {
return () => ({
push: mockRouterPush,
});
});
describe('CreateDaytisticContent', () => {
beforeEach(() => {
vi.clearAllMocks();
// Setup successful API response
mockCreateDaytistic.mockResolvedValue({
status: 201,
_data: { id: '123' },
});
});
it('submits form successfully when date is selected', async () => {
const wrapper = await mountSuspended(CreateDaytisticContent);
const testDate = new Date('2024-01-01');
// First, set the modelValue prop
await wrapper.findComponent(DatePicker).setValue(testDate);
// Then emit the update event
await wrapper.findComponent(DatePicker).vm.$emit('update', testDate);
// Wait for Vue to process the updates
await wrapper.vm.$nextTick();
// Trigger form submission
await wrapper.find('form').trigger('submit');
// Wait for all promises to resolve
await flushPromises();
// Verify API call was made with correct date
expect(mockCreateDaytistic).toHaveBeenCalledWith(testDate);
// Verify success flow
expect(mockRouterPush).toHaveBeenCalled();
expect(mockSuccess).toHaveBeenCalled();
});
});