Files
chatwoot/app/javascript/dashboard/mixins/specs/fileUploadMixin.spec.js
Sivin Varghese b18cac77fb chore: Moved file upload methods to mixin (#7987)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2023-09-27 11:05:19 +05:30

76 lines
2.1 KiB
JavaScript

import fileUploadMixin from 'dashboard/mixins/fileUploadMixin';
import Vue from 'vue';
jest.mock('shared/helpers/FileHelper', () => ({
checkFileSizeLimit: jest.fn(),
}));
jest.mock('activestorage', () => ({
DirectUpload: jest.fn().mockImplementation(() => ({
create: jest.fn(),
})),
}));
describe('FileUploadMixin', () => {
let vm;
beforeEach(() => {
vm = new Vue(fileUploadMixin);
vm.isATwilioSMSChannel = false;
vm.globalConfig = {
directUploadsEnabled: true,
};
vm.accountId = 123;
vm.currentChat = {
id: 456,
};
vm.currentUser = {
access_token: 'token',
};
vm.$t = jest.fn(message => message);
vm.showAlert = jest.fn();
vm.attachFile = jest.fn();
});
it('should call onDirectFileUpload when direct uploads are enabled', () => {
vm.onDirectFileUpload = jest.fn();
vm.onFileUpload({});
expect(vm.onDirectFileUpload).toHaveBeenCalledWith({});
});
it('should call onIndirectFileUpload when direct uploads are disabled', () => {
vm.globalConfig.directUploadsEnabled = false;
vm.onIndirectFileUpload = jest.fn();
vm.onFileUpload({});
expect(vm.onIndirectFileUpload).toHaveBeenCalledWith({});
});
describe('onDirectFileUpload', () => {
it('returns early if no file is provided', () => {
const returnValue = vm.onDirectFileUpload(null);
expect(returnValue).toBeUndefined();
});
it('shows an alert if the file size exceeds the maximum limit', () => {
const fakeFile = { size: 999999999 };
vm.showAlert = jest.fn();
vm.onDirectFileUpload(fakeFile);
expect(vm.showAlert).toHaveBeenCalledWith(expect.any(String));
});
});
describe('onIndirectFileUpload', () => {
it('returns early if no file is provided', () => {
const returnValue = vm.onIndirectFileUpload(null);
expect(returnValue).toBeUndefined();
});
it('shows an alert if the file size exceeds the maximum limit', () => {
const fakeFile = { size: 999999999 };
vm.showAlert = jest.fn();
vm.onIndirectFileUpload(fakeFile);
expect(vm.showAlert).toHaveBeenCalledWith(expect.any(String));
});
});
});