Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
Merge 294693e into 41e7533
Browse files Browse the repository at this point in the history
  • Loading branch information
Nacho888 committed Mar 31, 2019
2 parents 41e7533 + 294693e commit 55b3641
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 37 deletions.
15 changes: 15 additions & 0 deletions src/app/message/message.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MessageComponent } from './message.component';
import { ChatService } from '../services/chat.service';
import { ToastrModule } from 'ngx-toastr';
import {By} from '@angular/platform-browser';

describe('MessageComponent', () => {
let component: MessageComponent;
Expand All @@ -26,4 +27,18 @@ describe('MessageComponent', () => {
it('should be created', () => {
expect(component).toBeTruthy();
});

it('should remove message (case a)', () => {
component.messageContent = '';
component.removeMessage();
expect(By.css('#toastr-container'));
});

it('should remove message (case b)', () => {
component.messageContent = 'a';
component.isOwnMessage = true;
component.removeMessage();
expect(By.css('#toastr-container'));
expect(component.messageContent === '');
});
});
118 changes: 82 additions & 36 deletions src/app/settings/settings.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,82 @@

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

import { SettingsComponent } from './settings.component';
import { FormsModule } from '@angular/forms';
import { ChatService } from '../services/chat.service';
import { NgSelectModule } from '@ng-select/ng-select';
import { ToastrService, ToastrModule } from 'ngx-toastr';
import { RouterTestingModule } from '@angular/router/testing';
import {By} from '@angular/platform-browser';

describe('SettingsComponent', () => {

let component: SettingsComponent;
let fixture: ComponentFixture<SettingsComponent>;
let spy: any;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SettingsComponent ],
imports: [ FormsModule , ToastrModule.forRoot(), NgSelectModule, RouterTestingModule ],
providers: [ ChatService , ToastrService ]
})
.compileComponents();
}));

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

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

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

import { SettingsComponent } from './settings.component';
import { FormsModule } from '@angular/forms';
import { ChatService } from '../services/chat.service';
import { NgSelectModule } from '@ng-select/ng-select';
import { ToastrService, ToastrModule } from 'ngx-toastr';
import { RouterTestingModule } from '@angular/router/testing';
import {By} from '@angular/platform-browser';

describe('SettingsComponent', () => {

let component: SettingsComponent;
let fixture: ComponentFixture<SettingsComponent>;
let spy: any;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SettingsComponent ],
imports: [ FormsModule , ToastrModule.forRoot(), NgSelectModule, RouterTestingModule ],
providers: [ ChatService , ToastrService ]
})
.compileComponents();
}));

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

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

it('should display input error (add)', () => {

spy = spyOn(component.chat, 'addFriend').and.callFake(function(friend) {
return null;
});

component.webIdAddFriend = 'test';
component.addFriend();
expect(!By.css('#toastr-container'));

component.webIdAddFriend = null;
component.addFriend();
expect(By.css('#toastr-container'));

component.webIdAddFriend = '';
component.addFriend();
expect(By.css('#toastr-container'));
});

it('should display input error (remove)', () => {

spy = spyOn(component.chat, 'removeFriend').and.callFake(function(friend) {
return null;
});

component.webIdRemoveFriend = 'test';
component.removeFriend();
expect(!By.css('#toastr-container'));

component.webIdRemoveFriend = null;
component.removeFriend();
expect(By.css('#toastr-container'));

component.webIdRemoveFriend = '';
component.removeFriend();
expect(By.css('#toastr-container'));

});

it('should click intro', () => {
component.webIdAddFriend = null;
component.handleSubmit({keyCode: 13});
expect(By.css('#toastr-container'));
});

});
2 changes: 1 addition & 1 deletion src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SettingsComponent implements OnInit {
urlAddedFriend: string;
customProviderUrl: string;

constructor(private chat: ChatService, private toastr: ToastrService, private auth: AuthService, private sdv: Router) { }
constructor(public chat: ChatService, private toastr: ToastrService, private auth: AuthService, private sdv: Router) { }

ngOnInit() {
this.identityProviders = this.auth.getIdentityProviders();
Expand Down

0 comments on commit 55b3641

Please sign in to comment.