mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-07 13:25:33 +00:00
# Pull Request Template ## Description This PR will replace the usage of `alertMixin` from the code base with the `useAlert` composable. Fixes https://linear.app/chatwoot/issue/CW-3462/replace-alertmixin-usage-with-usealert ## Type of change - [x] Breaking change (fix or feature that would cause existing functionality not to work as expected) ## How Has This Been Tested? Please refer this issue description https://linear.app/chatwoot/issue/CW-3462/replace-alertmixin-usage-with-usealert ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
import Vue from 'vue';
|
|
import { useAlert } from 'dashboard/composables';
|
|
import fileUploadMixin from 'dashboard/mixins/fileUploadMixin';
|
|
|
|
vi.mock('shared/helpers/FileHelper', () => ({
|
|
checkFileSizeLimit: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('activestorage', () => ({
|
|
DirectUpload: vi.fn().mockImplementation(() => ({
|
|
create: vi.fn(),
|
|
})),
|
|
}));
|
|
|
|
vi.mock('dashboard/composables', () => ({
|
|
useAlert: vi.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 = vi.fn(message => message);
|
|
vm.showAlert = vi.fn();
|
|
vm.attachFile = vi.fn();
|
|
});
|
|
|
|
it('should call onDirectFileUpload when direct uploads are enabled', () => {
|
|
vm.onDirectFileUpload = vi.fn();
|
|
vm.onFileUpload({});
|
|
expect(vm.onDirectFileUpload).toHaveBeenCalledWith({});
|
|
});
|
|
|
|
it('should call onIndirectFileUpload when direct uploads are disabled', () => {
|
|
vm.globalConfig.directUploadsEnabled = false;
|
|
vm.onIndirectFileUpload = vi.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.onDirectFileUpload(fakeFile);
|
|
expect(useAlert).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.onIndirectFileUpload(fakeFile);
|
|
expect(useAlert).toHaveBeenCalledWith(expect.any(String));
|
|
});
|
|
});
|
|
});
|