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

Nacho #55

Merged
merged 7 commits into from
Mar 31, 2019
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
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