Skip to content

Commit 0f4fce3

Browse files
130715: Made generate:decorator:registries compatible with new @DSpace imports
1 parent e404968 commit 0f4fce3

3 files changed

Lines changed: 34 additions & 21 deletions

File tree

scripts/generate-decorator-registries.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import {
55
readFileSync,
66
rmSync,
77
writeFileSync,
8-
} from 'fs';
9-
import { sync } from 'glob';
8+
} from 'node:fs';
109
import {
1110
basename,
1211
dirname,
1312
join,
1413
relative,
1514
resolve,
16-
} from 'path';
15+
} from 'node:path';
16+
17+
import { sync } from 'glob';
1718
import {
1819
createSourceFile,
1920
forEachChild,
@@ -28,6 +29,7 @@ import {
2829
isNumericLiteral,
2930
isPropertyAccessExpression,
3031
isStringLiteral,
32+
Node,
3133
ScriptTarget,
3234
SourceFile,
3335
StringLiteral,
@@ -203,7 +205,7 @@ const writeRegistryFile = (
203205
const mapName = getDecoratorConstName(decoratorConfig.name) + '_MAP';
204206
const functionName = `${decoratorConfig.name}CreateMap`;
205207
const mapVarName = `${decoratorConfig.name}Map`;
206-
let content = '';
208+
let content: string;
207209

208210
// Start the registry file with the import statements, if any.
209211
content = generateImportStatements(components);
@@ -250,11 +252,14 @@ const generateImportsMap = (file: SourceFile): Map<string, string> => {
250252
* Then resolve that to a relative path, relative to the decorator registries directory.
251253
*/
252254
const parseImportPath = (allImports: Map<string, string>, arg: any, filePath: string): string => {
253-
let absoluteImportPath = allImports.get(arg.text);
254-
if (!absoluteImportPath.includes('src/app')) {
255-
absoluteImportPath = resolve(dirname(filePath), allImports.get(arg.text));
255+
const absoluteImportPath = allImports.get(arg.text);
256+
if (absoluteImportPath.startsWith('.')) {
257+
return relative(REGISTRY_OUTPUT_DIR, resolve(dirname(filePath), allImports.get(arg.text)));
258+
}
259+
if (absoluteImportPath.startsWith('src/app')) {
260+
return relative(REGISTRY_OUTPUT_DIR, absoluteImportPath);
256261
}
257-
return relative(REGISTRY_OUTPUT_DIR, absoluteImportPath);
262+
return absoluteImportPath;
258263
};
259264

260265
/**
@@ -266,7 +271,7 @@ const parseDecoratorArguments = (
266271
) => {
267272
const args: any[] = [];
268273
const argImports: Map<string, string> = new Map();
269-
decorator.expression.arguments.forEach((arg) => {
274+
decorator.expression.arguments.forEach((arg: Node) => {
270275
// e.g. @decorator('range')
271276
if (isStringLiteral(arg)) {
272277
args.push(arg.text);

src/app/external-log-in/external-log-in/external-log-in.component.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { of } from 'rxjs';
2626

2727
import { storeModuleConfig } from '../../app.reducer';
2828
import { AlertComponent } from '../../shared/alert/alert.component';
29-
import { AuthMethodsService } from '../../shared/log-in/services/auth-methods.service';
29+
import { ThemedLogInComponent } from '../../shared/log-in/themed-log-in.component';
3030
import { getMockThemeService } from '../../shared/theme-support/test/theme-service.mock';
3131
import { ThemeService } from '../../shared/theme-support/theme.service';
3232
import { ConfirmEmailComponent } from '../email-confirmation/confirm-email/confirm-email.component';
@@ -36,9 +36,13 @@ import { ExternalLogInComponent } from './external-log-in.component';
3636
describe('ExternalLogInComponent', () => {
3737
let component: ExternalLogInComponent;
3838
let fixture: ComponentFixture<ExternalLogInComponent>;
39-
let modalService: NgbModal = jasmine.createSpyObj('modalService', ['open']);
40-
let authServiceStub: jasmine.SpyObj<AuthService>;
41-
let authMethodsServiceStub: jasmine.SpyObj<AuthMethodsService>;
39+
let modalRef = Object.defineProperty({
40+
close: jasmine.createSpy('close'),
41+
},
42+
'dismissed', {
43+
get: () => of(),
44+
});
45+
let modalService = jasmine.createSpyObj('modalService', ['open']);
4246
let mockAuthMethodsArray: AuthMethod[] = [
4347
{ id: 'password', authMethodType: AuthMethodType.Password, position: 2 } as AuthMethod,
4448
{ id: 'shibboleth', authMethodType: AuthMethodType.Shibboleth, position: 1 } as AuthMethod,
@@ -81,6 +85,8 @@ describe('ExternalLogInComponent', () => {
8185
};
8286

8387
beforeEach(async () => {
88+
modalService.open.and.returnValue(modalRef);
89+
8490
await TestBed.configureTestingModule({
8591
imports: [
8692
TranslateModule.forRoot(),
@@ -103,14 +109,15 @@ describe('ExternalLogInComponent', () => {
103109
ConfirmEmailComponent,
104110
ProvideEmailComponent,
105111
AlertComponent,
112+
ThemedLogInComponent,
106113
],
107114
},
108115
}).compileComponents();
109116
});
110117
beforeEach(() => {
111118
fixture = TestBed.createComponent(ExternalLogInComponent);
112119
component = fixture.componentInstance;
113-
component.registrationData = Object.assign(new Registration(), registrationDataMock);
120+
component.registrationData = Object.assign(new Registration(), registrationDataMock, { email: 'user@institution.edu' });
114121
component.registrationType = registrationDataMock.registrationType;
115122
fixture.detectChanges();
116123
});
@@ -120,12 +127,6 @@ describe('ExternalLogInComponent', () => {
120127
expect(component).toBeTruthy();
121128
});
122129

123-
beforeEach(() => {
124-
component.registrationData = Object.assign(new Registration(), registrationDataMock, { email: 'user@institution.edu' });
125-
126-
fixture.detectChanges();
127-
});
128-
129130
it('should set registrationType and informationText correctly when email is present', () => {
130131
expect(component.registrationType).toBe(registrationDataMock.registrationType);
131132
expect(component.informationText).toBeDefined();

src/app/external-log-in/external-log-in/external-log-in.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import {
3131
from,
3232
Observable,
33+
Subscription,
3334
} from 'rxjs';
3435
import { map } from 'rxjs/operators';
3536

@@ -111,6 +112,8 @@ export class ExternalLogInComponent implements OnInit, OnDestroy {
111112
*/
112113
externalLoginConfirmationComponent$: Observable<GenericConstructor<Component>>;
113114

115+
sub: Subscription;
116+
114117
constructor(
115118
protected injector: Injector,
116119
protected translate: TranslateService,
@@ -161,9 +164,12 @@ export class ExternalLogInComponent implements OnInit, OnDestroy {
161164
* @param content - The content to be displayed in the modal.
162165
*/
163166
openLoginModal(content: any) {
167+
if (hasValue(this.sub)) {
168+
this.sub.unsubscribe();
169+
}
164170
this.modalRef = this.modalService.open(content);
165171
this.authService.setRedirectUrl(`/review-account/${this.token}`);
166-
this.modalRef.dismissed.subscribe(() => {
172+
this.sub = this.modalRef.dismissed.subscribe(() => {
167173
this.clearRedirectUrl();
168174
});
169175
}
@@ -176,6 +182,7 @@ export class ExternalLogInComponent implements OnInit, OnDestroy {
176182
}
177183

178184
ngOnDestroy(): void {
185+
this.sub?.unsubscribe();
179186
this.modalRef?.close();
180187
}
181188

0 commit comments

Comments
 (0)