48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
vi.mock('@inertiajs/vue3', async () => import('../../stubs/inertia.js'));
|
|
|
|
import Create from '../../../../resources/js/Pages/Prompts/Create.vue';
|
|
import { inertiaMock, resetInertiaMock } from '../../stubs/inertia.js';
|
|
|
|
describe('Pages/Prompts/Create', () => {
|
|
beforeEach(() => {
|
|
resetInertiaMock();
|
|
});
|
|
|
|
it('wires PromptForm for creating a prompt', () => {
|
|
const wrapper = mount(Create, {
|
|
props: {
|
|
initial: { name: '', description: null, body: '', tags: [] },
|
|
suggestedTags: ['chat', 'code'],
|
|
},
|
|
});
|
|
|
|
expect(inertiaMock.headCalls.at(-1).title).toBe('New Prompt');
|
|
expect(wrapper.find('h1').text()).toBe('New prompt');
|
|
expect(wrapper.text()).toContain('{{variable}}');
|
|
|
|
expect(wrapper.find('button[type="submit"]').text()).toBe('Create prompt');
|
|
expect(wrapper.find('a[data-inertia]').attributes('href')).toBe('/prompts');
|
|
});
|
|
|
|
it('submits the form via POST to /prompts', async () => {
|
|
const wrapper = mount(Create, {
|
|
props: {
|
|
initial: { name: '', description: null, body: '', tags: [] },
|
|
suggestedTags: [],
|
|
},
|
|
});
|
|
|
|
await wrapper.find('#prompt-name').setValue('Greeter');
|
|
await wrapper.find('#prompt-body').setValue('Hi {{ name }}!');
|
|
await wrapper.find('form').trigger('submit');
|
|
|
|
const submission = inertiaMock.formSubmissions[0];
|
|
expect(submission.method).toBe('post');
|
|
expect(submission.url).toBe('/prompts');
|
|
expect(submission.data).toMatchObject({ name: 'Greeter', body: 'Hi {{ name }}!' });
|
|
});
|
|
});
|