2022-09-14 13:17:12 +00:00
|
|
|
import PrimeVue from '../config/PrimeVue';
|
2022-09-14 11:26:01 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
import ConfirmDialog from './ConfirmDialog.vue';
|
|
|
|
|
|
|
|
describe('ConfirmDialog', () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
it('should exist', async () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
const wrapper = mount(ConfirmDialog, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true,
|
|
|
|
transition: false
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
confirmation: {
|
|
|
|
message: 'Are you sure you want to proceed?',
|
|
|
|
header: 'Confirmation',
|
|
|
|
icon: 'pi pi-exclamation-triangle'
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.setData({ visible: true });
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(wrapper.find('.p-dialog-mask .p-dialog.p-component').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('.p-dialog-title').text()).toBe('Confirmation');
|
|
|
|
expect(wrapper.find('.p-confirm-dialog-message').text()).toBe('Are you sure you want to proceed?');
|
|
|
|
|
|
|
|
await wrapper.vm.reject();
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
expect(wrapper.find('.p-dialog-mask .p-dialog.p-component').exists()).toBe(true);
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
it('should dialog trigger the accept function', async () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
const wrapper = mount(ConfirmDialog, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true,
|
|
|
|
transition: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
confirmation: {
|
|
|
|
message: 'Are you sure you want to proceed?',
|
|
|
|
header: 'Confirmation',
|
|
|
|
icon: 'pi pi-exclamation-triangle',
|
|
|
|
accept: () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('accept');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
reject: () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2022-09-06 12:03:37 +00:00
|
|
|
console.log('reject');
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-14 13:17:12 +00:00
|
|
|
const acceptTriggered = vi.spyOn(wrapper.componentVM.confirmation, 'accept');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
await wrapper.setData({ visible: true });
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
const CDAcceptBtn = wrapper.find('.p-confirm-dialog-accept');
|
|
|
|
|
|
|
|
await CDAcceptBtn.trigger('click');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(acceptTriggered).toBeCalled();
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
it('should dialog trigger the reject function', async () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
const wrapper = mount(ConfirmDialog, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true,
|
|
|
|
transition: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
confirmation: {
|
|
|
|
message: 'Are you sure you want to proceed?',
|
|
|
|
header: 'Confirmation',
|
|
|
|
icon: 'pi pi-exclamation-triangle',
|
|
|
|
accept: () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('accept');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
reject: () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2022-09-06 12:03:37 +00:00
|
|
|
console.log('reject');
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-14 13:17:12 +00:00
|
|
|
const rejectTriggered = vi.spyOn(wrapper.componentVM.confirmation, 'reject');
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
await wrapper.setData({ visible: true });
|
|
|
|
|
|
|
|
const CDRejectBtn = wrapper.find('.p-confirm-dialog-reject');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
await CDRejectBtn.trigger('click');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
expect(rejectTriggered).toBeCalled();
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
it('should dialog close button work', async () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
const wrapper = mount(ConfirmDialog, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true,
|
|
|
|
transition: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
confirmation: {
|
|
|
|
message: 'Are you sure you want to proceed?',
|
|
|
|
header: 'Confirmation',
|
|
|
|
icon: 'pi pi-exclamation-triangle'
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.setData({ visible: true });
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
const dialogCloseBtn = wrapper.find('.p-dialog-header-close');
|
|
|
|
|
|
|
|
await dialogCloseBtn.trigger('click');
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
expect(wrapper.find('.p-dialog-mask .p-dialog.p-component').exists()).toBe(true);
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should position work', async () => {
|
|
|
|
const wrapper = mount(ConfirmDialog, {
|
|
|
|
global: {
|
|
|
|
plugins: [PrimeVue],
|
|
|
|
stubs: {
|
|
|
|
teleport: true,
|
|
|
|
transition: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
confirmation: {
|
|
|
|
group: 'positionDialog',
|
|
|
|
message: 'Do you want to delete this record?',
|
|
|
|
header: 'Delete Confirmation',
|
|
|
|
icon: 'pi pi-info-circle',
|
|
|
|
position: 'bottom'
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.setData({ visible: true });
|
|
|
|
|
|
|
|
expect(wrapper.find('.p-dialog-mask.p-dialog-bottom').exists()).toBe(true);
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
});
|