|
| 1 | +import { MockComponents } from 'ng-mocks'; |
| 2 | + |
1 | 3 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 4 | +import { ActivatedRoute } from '@angular/router'; |
| 5 | + |
| 6 | +import { UserSelectors } from '@core/store/user'; |
| 7 | +import { LoadingSpinnerComponent, SubHeaderComponent } from '@osf/shared/components'; |
| 8 | +import { MOCK_USER } from '@shared/mocks'; |
| 9 | +import { AddonsSelectors } from '@shared/stores'; |
2 | 10 |
|
3 | 11 | import { LinkedServicesComponent } from './linked-services.component'; |
4 | 12 |
|
5 | | -describe.skip('LinkedServicesComponent', () => { |
| 13 | +import { getConfiguredAddonsMappedData } from '@testing/data/addons/addons.configured.data'; |
| 14 | +import { getResourceReferencesData } from '@testing/data/files/resource-references.data'; |
| 15 | +import { OSFTestingModule } from '@testing/osf.testing.module'; |
| 16 | +import { ActivatedRouteMockBuilder } from '@testing/providers/route-provider.mock'; |
| 17 | +import { provideMockStore } from '@testing/providers/store-provider.mock'; |
| 18 | + |
| 19 | +describe('LinkedServicesComponent', () => { |
6 | 20 | let component: LinkedServicesComponent; |
7 | 21 | let fixture: ComponentFixture<LinkedServicesComponent>; |
8 | 22 |
|
| 23 | + const mockProjectId = 'test-project-123'; |
| 24 | + const mockCurrentUser = MOCK_USER; |
| 25 | + const mockAddonsResourceReference = getResourceReferencesData(); |
| 26 | + const mockConfiguredLinkAddons = getConfiguredAddonsMappedData(); |
| 27 | + |
9 | 28 | beforeEach(async () => { |
| 29 | + const activatedRouteMock = ActivatedRouteMockBuilder.create().withParams({ id: mockProjectId }).build(); |
| 30 | + |
10 | 31 | await TestBed.configureTestingModule({ |
11 | | - imports: [LinkedServicesComponent], |
| 32 | + imports: [ |
| 33 | + LinkedServicesComponent, |
| 34 | + OSFTestingModule, |
| 35 | + ...MockComponents(SubHeaderComponent, LoadingSpinnerComponent), |
| 36 | + ], |
| 37 | + providers: [ |
| 38 | + { provide: ActivatedRoute, useValue: activatedRouteMock }, |
| 39 | + provideMockStore({ |
| 40 | + signals: [ |
| 41 | + { selector: UserSelectors.getCurrentUser, value: mockCurrentUser }, |
| 42 | + { selector: UserSelectors.getCurrentUserLoading, value: false }, |
| 43 | + { selector: AddonsSelectors.getAddonsResourceReference, value: mockAddonsResourceReference }, |
| 44 | + { selector: AddonsSelectors.getAddonsResourceReferenceLoading, value: false }, |
| 45 | + { selector: AddonsSelectors.getConfiguredLinkAddons, value: mockConfiguredLinkAddons }, |
| 46 | + { selector: AddonsSelectors.getConfiguredLinkAddonsLoading, value: false }, |
| 47 | + ], |
| 48 | + }), |
| 49 | + ], |
12 | 50 | }).compileComponents(); |
13 | 51 |
|
14 | 52 | fixture = TestBed.createComponent(LinkedServicesComponent); |
15 | 53 | component = fixture.componentInstance; |
16 | | - fixture.detectChanges(); |
17 | 54 | }); |
18 | 55 |
|
19 | 56 | it('should create', () => { |
| 57 | + fixture.detectChanges(); |
20 | 58 | expect(component).toBeTruthy(); |
21 | 59 | }); |
| 60 | + |
| 61 | + it('should initialize with correct computed values', () => { |
| 62 | + fixture.detectChanges(); |
| 63 | + |
| 64 | + expect(component.isLoading()).toBe(false); |
| 65 | + expect(component.convertedConfiguredLinkAddons()).toHaveLength(1); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should display table when addons are available', () => { |
| 69 | + fixture.detectChanges(); |
| 70 | + |
| 71 | + const compiled = fixture.nativeElement; |
| 72 | + expect(compiled.querySelector('p-table')).toBeTruthy(); |
| 73 | + expect(compiled.textContent).toContain('Google Drive'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should show no services message when no addons are available', () => { |
| 77 | + Object.defineProperty(component, 'convertedConfiguredLinkAddons', { |
| 78 | + value: () => [], |
| 79 | + writable: true, |
| 80 | + }); |
| 81 | + |
| 82 | + fixture.detectChanges(); |
| 83 | + |
| 84 | + const compiled = fixture.nativeElement; |
| 85 | + expect(compiled.textContent).toContain('project.linkedServices.noLinkedServices'); |
| 86 | + expect(compiled.textContent).toContain('project.linkedServices.redirectMessage'); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should convert service names correctly', () => { |
| 90 | + fixture.detectChanges(); |
| 91 | + |
| 92 | + const convertedAddons = component.convertedConfiguredLinkAddons(); |
| 93 | + expect(convertedAddons[0].serviceName).toBe('Google Drive'); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should convert resource types correctly', () => { |
| 97 | + fixture.detectChanges(); |
| 98 | + |
| 99 | + const convertedAddons = component.convertedConfiguredLinkAddons(); |
| 100 | + expect(convertedAddons[0].convertedResourceType).toBe(''); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should call getAddonsResourceReference on ngOnInit when project ID exists', () => { |
| 104 | + expect(() => component.ngOnInit()).not.toThrow(); |
| 105 | + }); |
| 106 | + |
| 107 | + it('should have actions defined', () => { |
| 108 | + expect(component.actions).toBeDefined(); |
| 109 | + expect(component.actions.getAddonsResourceReference).toBeDefined(); |
| 110 | + expect(component.actions.getConfiguredLinkAddons).toBeDefined(); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should handle empty resource reference', () => { |
| 114 | + Object.defineProperty(component, 'addonsResourceReference', { |
| 115 | + value: () => [], |
| 116 | + writable: true, |
| 117 | + }); |
| 118 | + Object.defineProperty(component, 'resourceReferenceId', { |
| 119 | + value: () => undefined, |
| 120 | + writable: true, |
| 121 | + }); |
| 122 | + |
| 123 | + fixture.detectChanges(); |
| 124 | + |
| 125 | + expect(component.resourceReferenceId()).toBeUndefined(); |
| 126 | + }); |
22 | 127 | }); |
0 commit comments