Skip to content

Commit

Permalink
Updated login test following the updated login
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Jan 14, 2025
1 parent 4dd45a8 commit 05177bf
Showing 1 changed file with 3 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,22 @@ import { TranslateModule } from '@ngx-translate/core';
import { LogInPasswordComponent } from './log-in-password.component';
import { authReducer } from '../../../../core/auth/auth.reducer';
import { AuthService } from '../../../../core/auth/auth.service';
import { AuthServiceStub } from '../../../testing/auth-service.stub';
import { storeModuleConfig } from '../../../../app.reducer';
import { AuthMethod } from '../../../../core/auth/models/auth.method';
import { AuthMethodType } from '../../../../core/auth/models/auth.method-type';
import { HardRedirectService } from '../../../../core/services/hard-redirect.service';
import { BrowserOnlyMockPipe } from '../../../testing/browser-only-mock.pipe';
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
import { AuthorizationDataServiceStub } from '../../../testing/authorization-service.stub';
import {of, of as observableOf} from 'rxjs';
import { ConfigurationDataService } from '../../../../core/data/configuration-data.service';
import { ActivatedRoute , Router} from '@angular/router';
import { RouterMock } from '../../../mocks/router.mock';
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
import { CookieService } from '../../../../core/services/cookie.service';
import { CookieServiceMock } from '../../../mocks/cookie.service.mock';
import { NotificationsService } from '../../../notifications/notifications.service';
import { NotificationsServiceStub } from '../../../testing/notifications-service.stub';

describe('LogInPasswordComponent', () => {
const uiUrl = 'localhost:4000';
const redirectUrl = '/items/someId';

let component: LogInPasswordComponent;
let fixture: ComponentFixture<LogInPasswordComponent>;
let page: Page;
let initialState: any;
let hardRedirectService: HardRedirectService;
let authService: any;
let configurationDataService: ConfigurationDataService;
let notificationService: NotificationsServiceStub;

beforeEach(() => {
hardRedirectService = jasmine.createSpyObj('hardRedirectService', {
Expand All @@ -56,23 +43,6 @@ describe('LogInPasswordComponent', () => {
}
}
};

authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true),
setRedirectUrl: {},
setRedirectUrlIfNotSet: {},
getRedirectUrl: of(redirectUrl),
});
configurationDataService = jasmine.createSpyObj('configurationDataService', {
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
name: 'dspace.ui.url',
values: [
uiUrl
]
}))
});
notificationService = new NotificationsServiceStub();

});

beforeEach(waitForAsync(() => {
Expand All @@ -89,24 +59,11 @@ describe('LogInPasswordComponent', () => {
BrowserOnlyMockPipe,
],
providers: [
{ provide: AuthService, useValue: authService },
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub },
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Password, 0) },
{ provide: 'isStandalonePage', useValue: true },
{ provide: HardRedirectService, useValue: hardRedirectService },
{ provide: ConfigurationDataService, useValue: configurationDataService },
{ provide: ActivatedRoute, useValue: {
params: observableOf({}),
data: observableOf({ metadata: 'title' }),
snapshot: {
queryParams: new Map([
['redirectUrl', redirectUrl],
])
}
} },
{ provide: Router, useValue: new RouterMock() },
{ provide: CookieService, useClass: CookieServiceMock },
{ provide: NotificationsService, useValue: notificationService },
provideMockStore({ initialState }),
],
schemas: [
Expand Down Expand Up @@ -151,23 +108,6 @@ describe('LogInPasswordComponent', () => {
expect(page.navigateSpy.calls.any()).toBe(true, 'Store.dispatch not invoked');
});

it('should authenticate and redirect', waitForAsync(() => {
fixture.detectChanges();

// set FormControl values
component.form.controls.email.setValue('user');
component.form.controls.password.setValue('password');

// verify the fixture is stable (no pending tasks)
void fixture.whenStable().then(() => {
component.redirectUrl = redirectUrl;
component.baseUrl = uiUrl;
// submit form
component.submit();
expect(authService.setRedirectUrl).toHaveBeenCalledWith(redirectUrl);
});
}));

});

/**
Expand Down

0 comments on commit 05177bf

Please sign in to comment.