mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 04:27:53 +00:00 
			
		
		
		
	# Pull Request Template ## Description Replace Hook mixin with useHook composable Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] 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 - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import { useIntegrationHook } from '../useIntegrationHook';
 | 
						|
import { useMapGetter } from 'dashboard/composables/store';
 | 
						|
import { nextTick } from 'vue';
 | 
						|
 | 
						|
vi.mock('dashboard/composables/store');
 | 
						|
 | 
						|
describe('useIntegrationHook', () => {
 | 
						|
  let integrationGetter;
 | 
						|
 | 
						|
  beforeEach(() => {
 | 
						|
    integrationGetter = vi.fn();
 | 
						|
    useMapGetter.mockReturnValue({ value: integrationGetter });
 | 
						|
  });
 | 
						|
 | 
						|
  it('should return the correct computed properties', async () => {
 | 
						|
    const mockIntegration = {
 | 
						|
      id: 1,
 | 
						|
      hook_type: 'inbox',
 | 
						|
      hooks: ['hook1', 'hook2'],
 | 
						|
      allow_multiple_hooks: true,
 | 
						|
    };
 | 
						|
    integrationGetter.mockReturnValue(mockIntegration);
 | 
						|
 | 
						|
    const hook = useIntegrationHook(1);
 | 
						|
 | 
						|
    await nextTick();
 | 
						|
 | 
						|
    expect(hook.integration.value).toEqual(mockIntegration);
 | 
						|
    expect(hook.integrationType.value).toBe('multiple');
 | 
						|
    expect(hook.isIntegrationMultiple.value).toBe(true);
 | 
						|
    expect(hook.isIntegrationSingle.value).toBe(false);
 | 
						|
    expect(hook.isHookTypeInbox.value).toBe(true);
 | 
						|
    expect(hook.hasConnectedHooks.value).toBe(true);
 | 
						|
  });
 | 
						|
 | 
						|
  it('should handle single integration type correctly', async () => {
 | 
						|
    const mockIntegration = {
 | 
						|
      id: 2,
 | 
						|
      hook_type: 'channel',
 | 
						|
      hooks: [],
 | 
						|
      allow_multiple_hooks: false,
 | 
						|
    };
 | 
						|
    integrationGetter.mockReturnValue(mockIntegration);
 | 
						|
 | 
						|
    const hook = useIntegrationHook(2);
 | 
						|
 | 
						|
    await nextTick();
 | 
						|
 | 
						|
    expect(hook.integration.value).toEqual(mockIntegration);
 | 
						|
    expect(hook.integrationType.value).toBe('single');
 | 
						|
    expect(hook.isIntegrationMultiple.value).toBe(false);
 | 
						|
    expect(hook.isIntegrationSingle.value).toBe(true);
 | 
						|
    expect(hook.isHookTypeInbox.value).toBe(false);
 | 
						|
    expect(hook.hasConnectedHooks.value).toBe(false);
 | 
						|
  });
 | 
						|
});
 |