Browse Source

test(template): add home.component.spec

pull/2079/head
mehmet-erim 7 years ago
parent
commit
9acf888135
  1. 3
      templates/app/angular/src/app/home/home.component.html
  2. 51
      templates/app/angular/src/app/home/home.component.spec.ts

3
templates/app/angular/src/app/home/home.component.html

@ -14,6 +14,7 @@
[state]="{ redirectUrl: '/' }"
class="px-4 btn btn-primary ml-1"
role="button"
><i class="fa fa-sign-in"></i> {{ 'AbpIdentity::Login' | abpLocalization }}</a
id="login-button"
><i class="fa fa-sign-in"></i> {{ 'AbpAccount::Login' | abpLocalization }}</a
>
</div>

51
templates/app/angular/src/app/home/home.component.spec.ts

@ -0,0 +1,51 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { OAuthService } from 'angular-oauth2-oidc';
import { HomeComponent } from './home.component';
import { HomeModule } from './home.module';
import { RouterTestingModule } from '@angular/router/testing';
import { NgxsModule } from '@ngxs/store';
import { By } from '@angular/platform-browser';
describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
let mockOAuthService: { hasValidAccessToken: () => boolean };
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HomeModule, NgxsModule.forRoot(), RouterTestingModule],
providers: [{ provide: OAuthService, useValue: { hasValidAccessToken: () => false } }],
});
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
mockOAuthService = TestBed.get(OAuthService);
fixture.detectChanges();
});
describe('#hasLoggedIn', () => {
it('should return the hasValidAccessToken method of oAuthService', () => {
const spy = spyOn(mockOAuthService, 'hasValidAccessToken');
spy.and.returnValue(false);
expect(component.hasLoggedIn).toBe(false);
expect(spy).toHaveBeenCalled();
});
});
describe('login button', () => {
it('should display', () => {
const button = fixture.debugElement.query(By.css('[routerLink="/account/login"]'));
expect(button).toBeTruthy();
expect(button.nativeElement.textContent).toContain('AbpAccount::Login');
});
it('should not display when user logged in', () => {
const spy = spyOn(mockOAuthService, 'hasValidAccessToken');
spy.and.returnValue(true);
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('#login-button'));
expect(button).toBeFalsy();
});
});
});
Loading…
Cancel
Save