import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
import LimitBulkDialog from '../../resources/js/components/projects/LimitBulkDialog.vue';
const mountDialog = (count = 5) =>
mount(LimitBulkDialog, {
props: { modelValue: true, count },
global: { plugins: [createVuetify()], stubs: { VDialog: { template: '
' } } },
});
describe('LimitBulkDialog', () => {
it('emits apply with positive delta when only add filled', async () => {
const wrapper = mountDialog();
await wrapper.find('[data-testid="add-input"] input').setValue('100');
await wrapper.find('[data-testid="apply"]').trigger('click');
expect(wrapper.emitted('apply')?.[0]).toEqual([{ delta: 100 }]);
});
it('emits apply with negative delta when only remove filled', async () => {
const wrapper = mountDialog();
await wrapper.find('[data-testid="remove-input"] input').setValue('50');
await wrapper.find('[data-testid="apply"]').trigger('click');
expect(wrapper.emitted('apply')?.[0]).toEqual([{ delta: -50 }]);
});
it('emits apply with combined delta when both filled', async () => {
const wrapper = mountDialog();
await wrapper.find('[data-testid="add-input"] input').setValue('100');
await wrapper.find('[data-testid="remove-input"] input').setValue('30');
await wrapper.find('[data-testid="apply"]').trigger('click');
expect(wrapper.emitted('apply')?.[0]).toEqual([{ delta: 70 }]);
});
it('emits apply with replace when replace mode toggled', async () => {
const wrapper = mountDialog();
await wrapper.find('[data-testid="replace-toggle"] input').setValue(true);
await wrapper.find('[data-testid="replace-input"] input').setValue('500');
await wrapper.find('[data-testid="apply"]').trigger('click');
expect(wrapper.emitted('apply')?.[0]).toEqual([{ replace: 500 }]);
});
it('apply disabled when neither input is filled', () => {
const wrapper = mountDialog();
expect(wrapper.find('[data-testid="apply"]').attributes('disabled')).toBeDefined();
});
});