diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index ac74d207e..0fd7606a0 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -2,20 +2,34 @@ import { TestBed, async } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; import { TranslateModule } from '@ngx-translate/core'; -import { ElectronService } from './core/services'; +import { ElectronService } from './services/electron.service'; +import { ElectronServiceStub } from './home/home.component.spec'; -describe('AppComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [AppComponent], - providers: [ElectronService], - imports: [RouterTestingModule, TranslateModule.forRoot()] - }).compileComponents(); - })); - - it('should create the app', async(() => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; - expect(app).toBeTruthy(); - })); +jest.mock('custom-electron-titlebar', () => { + return { + Titlebar: jest.fn().mockImplementation(() => { + return {}; + }), + Color: { + fromHex: jest.fn(), + }, + }; +}); + +describe('AppComponen t', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [AppComponent], + providers: [ + { provide: ElectronService, useClass: ElectronServiceStub }, + ], + imports: [RouterTestingModule, TranslateModule.forRoot()], + }).compileComponents(); + })); + + it('should create the app', async(() => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + expect(app).toBeTruthy(); + })); }); diff --git a/src/app/home/file-upload/file-upload.component.spec.ts b/src/app/home/file-upload/file-upload.component.spec.ts index 2e2640462..584d4c11a 100644 --- a/src/app/home/file-upload/file-upload.component.spec.ts +++ b/src/app/home/file-upload/file-upload.component.spec.ts @@ -1,28 +1,27 @@ -/* tslint:disable:no-unused-variable */ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; - import { FileUploadComponent } from './file-upload.component'; +import { MatIconModule } from '@angular/material/icon'; +import { MockModule } from 'ng-mocks'; +import { NgxUploaderModule } from 'ngx-uploader'; describe('FileUploadComponent', () => { - let component: FileUploadComponent; - let fixture: ComponentFixture; + let component: FileUploadComponent; + let fixture: ComponentFixture; - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ FileUploadComponent ] - }) - .compileComponents(); - })); + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [FileUploadComponent], + imports: [MockModule(MatIconModule), NgxUploaderModule], + }).compileComponents(); + })); - beforeEach(() => { - fixture = TestBed.createComponent(FileUploadComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + beforeEach(() => { + fixture = TestBed.createComponent(FileUploadComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + it('should create', () => { + expect(component).toBeTruthy(); + }); }); diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts index 6d3706366..1ace13f9b 100644 --- a/src/app/home/home.component.spec.ts +++ b/src/app/home/home.component.spec.ts @@ -1,21 +1,65 @@ -/* tslint:disable:no-unused-variable */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MockComponent, MockModule } from 'ng-mocks'; import { HomeComponent } from './home.component'; +import { HeaderComponent } from '../shared/components/header/header.component'; +import { RecentPlaylistsComponent } from '../home/recent-playlists/recent-playlists.component'; +import { FileUploadComponent } from '../home/file-upload/file-upload.component'; +import { UrlUploadComponent } from '../home/url-upload/url-upload.component'; +import { MatTabsModule } from '@angular/material/tabs'; +import { MatIconModule } from '@angular/material/icon'; +import { MatProgressBarModule } from '@angular/material/progress-bar'; +import { RouterTestingModule } from '@angular/router/testing'; +import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; +import { ElectronService } from '../services/electron.service'; + +class MatSnackBarStub { + open(): void {} +} + +export class ElectronServiceStub { + ipcRenderer = { + send: jest.fn(), + on: jest.fn(), + }; + remote = { + process: { + platform: 'linux', + argv: [0, 1], + }, + }; +} describe('HomeComponent', () => { let component: HomeComponent; let fixture: ComponentFixture; - beforeEach(async(() => { + beforeEach(() => { TestBed.configureTestingModule({ - declarations: [HomeComponent], + declarations: [ + HomeComponent, + MockComponent(HeaderComponent), + MockComponent(FileUploadComponent), + MockComponent(RecentPlaylistsComponent), + MockComponent(UrlUploadComponent), + ], + imports: [ + MockModule(MatTabsModule), + MockModule(MatIconModule), + MockModule(MatProgressBarModule), + MockModule(MatSnackBarModule), + RouterTestingModule, + ], + providers: [ + { provide: MatSnackBar, useClass: MatSnackBarStub }, + { provide: ElectronService, useClass: ElectronServiceStub }, + ], }).compileComponents(); - })); + }); beforeEach(() => { fixture = TestBed.createComponent(HomeComponent); component = fixture.componentInstance; + TestBed.inject(ElectronService); fixture.detectChanges(); });