Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const routes: Routes = [
pathMatch: 'full',
component: AuthDashboardComponent
},
{
path: 'auth',
pathMatch: 'full',
component: AuthDashboardComponent
},
{
path: 'cla/project/:projectId/user/:userId',
pathMatch: 'full',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,64 @@
// SPDX-License-Identifier: MIT

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';

import { AppSettings } from 'src/app/config/app-settings';
import { StorageService } from 'src/app/shared/services/storage.service';
import { AuthDashboardComponent } from './auth-dashboard.component';

describe('AuthDashboardComponent', () => {
let component: AuthDashboardComponent;
let fixture: ComponentFixture<AuthDashboardComponent>;
let routerSpy: jasmine.SpyObj<Router>;
let storageSpy: jasmine.SpyObj<StorageService>;

beforeEach(async () => {
routerSpy = jasmine.createSpyObj<Router>('Router', ['navigate']);
storageSpy = jasmine.createSpyObj<StorageService>('StorageService', ['getItem']);
storageSpy.getItem.and.returnValue(null);

await TestBed.configureTestingModule({
declarations: [ AuthDashboardComponent ]
})
.compileComponents();
declarations: [AuthDashboardComponent],
providers: [
{ provide: Router, useValue: routerSpy },
{ provide: StorageService, useValue: storageSpy }
]
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(AuthDashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
fixture.detectChanges();
expect(component).toBeTruthy();
});

it('navigates to /cla/project/:projectId/user/:userId with redirect query param on init', () => {
storageSpy.getItem.and.callFake(((key: string) => {
switch (key) {
case AppSettings.PROJECT_ID:
return JSON.stringify('proj-123');
case AppSettings.USER_ID:
return JSON.stringify('user-456');
case AppSettings.REDIRECT:
return JSON.stringify('https://github.com/foo/bar/pull/42');
default:
return null;
}
}) as <T>(key: string) => T);

fixture.detectChanges();

expect(storageSpy.getItem).toHaveBeenCalledWith(AppSettings.PROJECT_ID);
expect(storageSpy.getItem).toHaveBeenCalledWith(AppSettings.USER_ID);
expect(storageSpy.getItem).toHaveBeenCalledWith(AppSettings.REDIRECT);
expect(routerSpy.navigate).toHaveBeenCalledOnceWith(
['/cla/project/proj-123/user/user-456'],
{ queryParams: { redirect: 'https://github.com/foo/bar/pull/42' } }
);
});
});
Loading