Skip to content

Commit 52197b0

Browse files
authored
test(linked-services): added tests (#383)
1 parent 92c591c commit 52197b0

File tree

1 file changed

+108
-3
lines changed

1 file changed

+108
-3
lines changed
Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,127 @@
1+
import { MockComponents } from 'ng-mocks';
2+
13
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';
210

311
import { LinkedServicesComponent } from './linked-services.component';
412

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', () => {
620
let component: LinkedServicesComponent;
721
let fixture: ComponentFixture<LinkedServicesComponent>;
822

23+
const mockProjectId = 'test-project-123';
24+
const mockCurrentUser = MOCK_USER;
25+
const mockAddonsResourceReference = getResourceReferencesData();
26+
const mockConfiguredLinkAddons = getConfiguredAddonsMappedData();
27+
928
beforeEach(async () => {
29+
const activatedRouteMock = ActivatedRouteMockBuilder.create().withParams({ id: mockProjectId }).build();
30+
1031
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+
],
1250
}).compileComponents();
1351

1452
fixture = TestBed.createComponent(LinkedServicesComponent);
1553
component = fixture.componentInstance;
16-
fixture.detectChanges();
1754
});
1855

1956
it('should create', () => {
57+
fixture.detectChanges();
2058
expect(component).toBeTruthy();
2159
});
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+
});
22127
});

0 commit comments

Comments
 (0)