2023-04-27 12:11:08 +00:00
|
|
|
import { createWrapper } from 'app/test/vitest/helper';
|
2024-09-23 20:09:37 +00:00
|
|
|
import VnSmsDialog from 'src/components/common/VnSmsDialog.vue';
|
2023-04-27 12:11:08 +00:00
|
|
|
import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest';
|
|
|
|
|
|
|
|
describe('VnSmsDialog', () => {
|
|
|
|
let vm;
|
|
|
|
const orderId = 1;
|
|
|
|
const shipped = new Date();
|
|
|
|
const phone = '012345678';
|
2024-09-23 20:09:37 +00:00
|
|
|
const promise = (response) => {
|
|
|
|
return response;
|
|
|
|
};
|
2023-04-27 12:11:08 +00:00
|
|
|
const template = 'minAmount';
|
|
|
|
const locale = 'en';
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
vm = createWrapper(VnSmsDialog, {
|
|
|
|
propsData: {
|
|
|
|
data: {
|
|
|
|
orderId,
|
2024-09-23 20:09:37 +00:00
|
|
|
shipped,
|
2023-04-27 12:11:08 +00:00
|
|
|
},
|
|
|
|
template,
|
|
|
|
locale,
|
|
|
|
phone,
|
2024-09-23 20:09:37 +00:00
|
|
|
promise,
|
|
|
|
},
|
2023-04-27 12:11:08 +00:00
|
|
|
}).vm;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vi.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateMessage()', () => {
|
|
|
|
it('should update the message value with the correct template and parameters', () => {
|
|
|
|
vm.updateMessage();
|
|
|
|
|
2024-09-23 20:09:37 +00:00
|
|
|
expect(vm.message).toEqual(
|
|
|
|
`A minimum amount of 50€ (VAT excluded) is required for your order ${orderId} of ${shipped} to receive it without additional shipping costs.`
|
|
|
|
);
|
2023-04-27 12:11:08 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('send()', async () => {
|
|
|
|
it('should send the message', async () => {
|
|
|
|
vi.spyOn(vm.props, 'promise');
|
|
|
|
vm.message = 'Example message';
|
|
|
|
const response = {
|
|
|
|
orderId,
|
|
|
|
shipped,
|
|
|
|
destination: phone,
|
2024-09-23 20:09:37 +00:00
|
|
|
message: vm.message,
|
2023-04-27 12:11:08 +00:00
|
|
|
};
|
|
|
|
await vm.send();
|
|
|
|
|
|
|
|
expect(vm.isLoading).toEqual(false);
|
|
|
|
expect(vm.props.promise).toHaveBeenCalledWith(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|