Created
October 11, 2025 20:26
-
-
Save Sambhunath-Sahoo/5d62715d45dcd3b59a3b7da12b2269ba to your computer and use it in GitHub Desktop.
ParentCompanyField.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { describe, it, expect, vi, beforeEach } from 'vitest' | |
| import { mount } from '@vue/test-utils' | |
| import { createPinia, setActivePinia } from 'pinia' | |
| import ParentCompanyField from '@/components/cell_renderers/common/ParentCompanyField.vue' | |
| import SingleEntityField from '@/components/cell_renderers/common/SingleEntityField.vue' | |
| import { ICellRendererParams } from '@ag-grid-community/core' | |
| // ─── Mocks ─────────────────────────────────────────────── | |
| beforeEach(() => { | |
| setActivePinia(createPinia()) | |
| }) | |
| vi.mock('@recruitcrm/webapp-utility', () => ({ | |
| getLocale: vi.fn().mockResolvedValue({ | |
| common: { | |
| default: 'test' | |
| } | |
| }) | |
| })) | |
| vi.mock('@/plugins/i18n', () => ({ | |
| i18n: { | |
| global: { | |
| locale: 'en', | |
| setLocaleMessage: vi.fn(), | |
| t: vi.fn((key: string) => key) | |
| } | |
| }, | |
| setLocale: vi.fn(), | |
| setAppLanguageForUser: vi.fn(), | |
| getLocaleText: vi.fn((key: string) => key), | |
| t: vi.fn((key: string) => key), | |
| tc: vi.fn((key: string) => key) | |
| })) | |
| vi.mock('@/stores/modules/common/advancedSearchStore', () => ({ | |
| useAdvancedSearch: () => ({ | |
| getAdvancedSearchData: vi.fn().mockReturnValue({}), | |
| filterSearchList: [], | |
| activePageView: null | |
| }) | |
| })) | |
| vi.mock('@/stores/common/pageViewStore', () => ({ | |
| usePageViewStore: () => ({ | |
| getSelectedPageView: vi.fn().mockReturnValue(null), | |
| selectedPageView: null | |
| }) | |
| })) | |
| vi.mock('@/stores/modules/common/EntityTableData', () => ({ | |
| useEntityTableData: () => ({ | |
| getDataSourceKey: vi.fn().mockReturnValue('data'), | |
| currentViewEntityColumns: [], | |
| orderBy: null, | |
| orderDirection: null | |
| }) | |
| })) | |
| vi.mock('@/components/cell_renderers/common/utils/tooltip', () => ({ | |
| setTooltip: vi.fn() | |
| })) | |
| vi.mock('@/composables/common/useUniversalEntityActions', () => ({ | |
| useUniversalEntityActions: () => ({ | |
| openEntityQuickView: vi.fn() | |
| }) | |
| })) | |
| vi.mock('@/utils/global', () => ({ | |
| getEnvironmentValue: vi.fn((key: string) => `mock-${key}`), | |
| getCommaSeparatedPhoto: vi.fn((photo: string) => photo || ''), | |
| removeTrailingSpace: vi.fn((value: string | null | undefined) => { | |
| if (!value) return '' | |
| return value.replace(/\s+$/, '') | |
| }) | |
| })) | |
| vi.mock('@/components/RouteComponent.vue', () => ({ | |
| default: { | |
| name: 'ROUTE_COMPONENT', | |
| props: ['path'], | |
| template: '<div class="route-component-stub"><slot /></div>' | |
| } | |
| })) | |
| vi.mock('recruitcrm-ui-kit-v2', () => ({ | |
| AvatarComponent: { | |
| name: 'AvatarComponent', | |
| props: ['type', 'avatar', 'size', 'image', 'class'], | |
| template: '<div class="avatar-stub"></div>' | |
| }, | |
| ROverlayPanel: { | |
| name: 'ROverlayPanel', | |
| props: ['pt', 'pt-options'], | |
| template: '<div class="overlay-panel-stub"><slot /></div>' | |
| } | |
| })) | |
| vi.mock('recruitcrm-ui-kit-v2/svg', () => ({ | |
| SvgIconWrapper: { | |
| name: 'SvgIconWrapper', | |
| props: ['iconName', 'iconType', 'style'], | |
| template: '<div class="svg-icon-stub"></div>' | |
| } | |
| })) | |
| vi.mock('@/components/cell_renderers/empty_cells/NotAvailable.vue', () => ({ | |
| default: { | |
| name: 'NotAvailable', | |
| template: '<div class="not-available-stub">Not Available</div>' | |
| } | |
| })) | |
| vi.mock('@/components/cell_renderers/common/EntityInfoCard.vue', () => ({ | |
| default: { | |
| name: 'InvoiceEntityInfoCard', | |
| props: ['entity'], | |
| template: '<div class="entity-info-stub"></div>' | |
| } | |
| })) | |
| // ─── Factory ───────────────────────────────────────────── | |
| const createMockParams = (parentCompanyData: any): ICellRendererParams => ({ | |
| value: null, | |
| data: parentCompanyData, | |
| valueFormatted: '', | |
| node: { | |
| setSelected: vi.fn(), | |
| isSelected: vi.fn(), | |
| isRowPinned: vi.fn(), | |
| isExpandable: vi.fn() | |
| } as any, | |
| eGridCell: {} as HTMLElement, | |
| api: { | |
| dispatchEvent: vi.fn(), | |
| getGridId: vi.fn(), | |
| destroy: vi.fn(), | |
| isDestroyed: vi.fn() | |
| } as any, | |
| colDef: {}, | |
| context: {}, | |
| column: { | |
| getUserProvidedColDef: vi.fn(), | |
| isRowGroupDisplayed: vi.fn(), | |
| isPrimary: vi.fn(), | |
| isFilterAllowed: vi.fn() | |
| } as any, | |
| eParentOfValue: {} as HTMLElement, | |
| registerRowDragger: vi.fn(), | |
| setTooltip: vi.fn() | |
| }) | |
| const createWrapper = (params: ICellRendererParams) => { | |
| return mount(ParentCompanyField, { | |
| props: { params }, | |
| global: { | |
| plugins: [createPinia()] | |
| } | |
| }) | |
| } | |
| // ─── Test Suite ────────────────────────────────────────── | |
| describe('ParentCompanyField.vue - SingleEntityField Rendering', () => { | |
| it('renders SingleEntityField component when parent company data is provided', () => { | |
| // Arrange: Create mock parent company data | |
| const mockParentCompanyData = { | |
| parentcompanyid: 123, | |
| parentcompanyname: 'Acme Corporation', | |
| parentLogo: 'https://example.com/logo.jpg', | |
| parentcompanyslug: 'acme-corporation' | |
| } | |
| const params = createMockParams(mockParentCompanyData) | |
| // Act: Mount parent component | |
| const wrapper = createWrapper(params) | |
| // Assert: Verify SingleEntityField is rendered | |
| const childComponent = wrapper.findComponent(SingleEntityField) | |
| expect(childComponent.exists()).toBe(true) | |
| }) | |
| it('renders SingleEntityField component even with minimal data', () => { | |
| // Arrange: Create params with minimal data | |
| const mockParentCompanyData = { | |
| parentcompanyid: null, | |
| parentcompanyname: null | |
| } | |
| const params = createMockParams(mockParentCompanyData) | |
| // Act: Mount parent component | |
| const wrapper = createWrapper(params) | |
| // Assert: Verify SingleEntityField is still rendered | |
| const childComponent = wrapper.findComponent(SingleEntityField) | |
| expect(childComponent.exists()).toBe(true) | |
| }) | |
| it('renders SingleEntityField component with empty data', () => { | |
| // Arrange: Create params with empty data | |
| const mockParentCompanyData = {} | |
| const params = createMockParams(mockParentCompanyData) | |
| // Act: Mount parent component | |
| const wrapper = createWrapper(params) | |
| // Assert: Verify SingleEntityField is still rendered | |
| const childComponent = wrapper.findComponent(SingleEntityField) | |
| expect(childComponent.exists()).toBe(true) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment