Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add tests
- Loading branch information
1 parent
95683b3
commit b45d4a0
Showing
8 changed files
with
154 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,67 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { OktaAuthStateService } from '@okta/okta-angular'; | ||
import { UserClaims, IDToken, AuthState } from '@okta/okta-auth-js'; | ||
import { of } from 'rxjs'; | ||
|
||
import { ProfileComponent } from './profile.component'; | ||
|
||
describe('ProfileComponent', () => { | ||
let component: ProfileComponent; | ||
let fixture: ComponentFixture<ProfileComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ ProfileComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
const claims: UserClaims = { | ||
sub: 'sub', | ||
name: 'Test Name' | ||
}; | ||
|
||
const idToken: IDToken = { | ||
idToken: 'token', | ||
clientId: 'client', | ||
issuer: 'issuer', | ||
authorizeUrl: 'authorize', | ||
expiresAt: 123, | ||
scopes: [], | ||
claims | ||
}; | ||
|
||
const authState: AuthState = { | ||
isAuthenticated: true, | ||
idToken | ||
}; | ||
|
||
let authStateSpy = jasmine.createSpyObj<OktaAuthStateService>([],['authState$']); | ||
|
||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ProfileComponent ], | ||
providers: [ | ||
{ provide: OktaAuthStateService, useValue: authStateSpy } | ||
] | ||
}); | ||
}); | ||
|
||
it('should show text that welcomes the user by name', () => { | ||
(Object.getOwnPropertyDescriptor(authStateSpy, 'authState$')?.get as jasmine.Spy).and.returnValue(of(authState)); | ||
fixture = TestBed.createComponent(ProfileComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
const spanEl = fixture.debugElement.query(By.css('span')); | ||
expect(spanEl).toBeTruthy(); | ||
expect(spanEl.nativeElement.innerHTML).toEqual('Test Name'); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
it('should show text that welcomes a user with no name', () => { | ||
(Object.getOwnPropertyDescriptor(authStateSpy, 'authState$')?.get as jasmine.Spy).and.returnValue(of({ | ||
isAuthenticated: true, | ||
idToken: {...idToken, claims: {sub: 'sub'}} | ||
})); | ||
|
||
fixture = TestBed.createComponent(ProfileComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
const spanEl = fixture.debugElement.query(By.css('span')); | ||
expect(spanEl).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters