remove premade tests and testconfig
parent
dc735e8091
commit
cf971413b3
|
@ -1,28 +0,0 @@
|
|||
# This file is a template, and might need editing before it works on your project.
|
||||
# Official framework image. Look for the different tagged releases at:
|
||||
# https://hub.docker.com/r/library/node/tags/
|
||||
image: node:latest
|
||||
|
||||
# Pick zero or more services to be used on all builds.
|
||||
# Only needed when using a docker container to run your tests in.
|
||||
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
|
||||
services:
|
||||
- mysql:latest
|
||||
- redis:latest
|
||||
- postgres:latest
|
||||
|
||||
# This folder is cached between builds
|
||||
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
|
||||
cache:
|
||||
paths:
|
||||
- node_modules/
|
||||
|
||||
test_async:
|
||||
script:
|
||||
- npm install
|
||||
- node ./specs/start.js ./specs/async.spec.js
|
||||
|
||||
test_db:
|
||||
script:
|
||||
- npm install
|
||||
- node ./specs/start.js ./specs/db-postgres.spec.js
|
|
@ -44,11 +44,6 @@
|
|||
"config": "./protractor.conf.js"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"karma": {
|
||||
"config": "./karma.conf.js"
|
||||
}
|
||||
},
|
||||
"defaults": {
|
||||
"styleExt": "css",
|
||||
"prefixInterfaces": false,
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
import { browser, element, by } from 'protractor';
|
||||
|
||||
describe('Dashboard', function() {
|
||||
|
||||
beforeEach(() => {
|
||||
browser.get('/')
|
||||
});
|
||||
|
||||
it('should display the correct heading', () => {
|
||||
const heading = element(by.css('h1')).getText();
|
||||
const headings = element.all(by.css('h1')).getText();
|
||||
console.log(headings)
|
||||
heading.then((headingText) => {
|
||||
console.log(headingText);
|
||||
});
|
||||
expect(heading).toEqual('Dashboard');
|
||||
expect(headings).toContain('Dashboard');
|
||||
});
|
||||
|
||||
it('should redirect to /dashboard', () => {
|
||||
expect(browser.getCurrentUrl()).toContain('/dashboard');
|
||||
});
|
||||
|
||||
});
|
|
@ -1,12 +0,0 @@
|
|||
import { browser} from 'protractor';
|
||||
import * as fs from 'fs';
|
||||
|
||||
declare var Buffer, module: any;
|
||||
|
||||
export function takeScreenshot(filename: string) {
|
||||
return browser.takeScreenshot().then((data) => {
|
||||
const stream = fs.createWriteStream(filename);
|
||||
stream.write(new Buffer(data, 'base64'));
|
||||
stream.end();
|
||||
})
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
import {takeScreenshot} from '../helpers/take_screenshot';
|
||||
import { browser } from 'protractor';
|
||||
import {EditTaskPage} from './edit-task.po';
|
||||
|
||||
describe('Edit Tasks', function() {
|
||||
|
||||
let page: EditTaskPage;
|
||||
beforeEach(() => {
|
||||
page = new EditTaskPage();
|
||||
page.navigateToNewPage();
|
||||
});
|
||||
|
||||
it('should change page when accepting alert', () => {
|
||||
page.fillForm('New Task', 'BACKLOG');
|
||||
page.cancel();
|
||||
page.getAlert().accept(); // Klick auf OK
|
||||
expect(browser.getCurrentUrl()).not.toContain(page.newUrl);
|
||||
});
|
||||
|
||||
it('should stay on page when discarding alert', () => {
|
||||
page.fillForm('New Task', 'IN_PROGRESS');
|
||||
page.cancel();
|
||||
page.getAlert().dismiss(); // Klick auf Abbrechen
|
||||
expect(browser.getCurrentUrl()).toContain(page.newUrl);
|
||||
});
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
import { browser, element, by, protractor} from 'protractor';
|
||||
|
||||
export class EditTaskPage {
|
||||
newUrl = '/tasks/new';
|
||||
navigateToNewPage() {
|
||||
return browser.get(this.newUrl);
|
||||
}
|
||||
|
||||
navigateToEditPage(id: number) {
|
||||
return browser.get(`tasks/edit/${id}`);
|
||||
}
|
||||
|
||||
fillForm(title: string, state: string) {
|
||||
element(by.name('title')).sendKeys(title);
|
||||
element(by.name('state')).element(by.css(`[value="${state}"]`))
|
||||
.click();
|
||||
//Firefox HACK:
|
||||
browser.actions().sendKeys( protractor.Key.ENTER ).perform();
|
||||
}
|
||||
|
||||
save() {
|
||||
element(by.id('save')).click();
|
||||
}
|
||||
|
||||
cancel() {
|
||||
return element(by.id('cancel')).click();
|
||||
}
|
||||
|
||||
getAlert() {
|
||||
return browser.switchTo().alert();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
import { browser, element, by } from 'protractor';
|
||||
import {takeScreenshot} from '../helpers/take_screenshot';
|
||||
|
||||
describe('Task List (without Page Object)', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
browser.get('/tasks')
|
||||
});
|
||||
|
||||
it('should allow searching for tasks', () => {
|
||||
element(by.css('#search-tasks')).sendKeys('Ersten');
|
||||
browser.sleep(500);
|
||||
const count = element.all(by.className('task-list-entry')).count();
|
||||
expect(count).toEqual(1);
|
||||
});
|
||||
|
||||
it('should work with no search results', () => {
|
||||
element(by.css('#search-tasks')).sendKeys('Ich existiere nicht');
|
||||
browser.sleep(500);
|
||||
const count = element.all(by.className('task-list-entry')).count();
|
||||
expect(count).toEqual(0);
|
||||
});
|
||||
|
||||
|
||||
});
|
|
@ -1,54 +0,0 @@
|
|||
|
||||
import {takeScreenshot} from '../helpers/take_screenshot';
|
||||
import {TaskListPage} from './task-list.po';
|
||||
import { browser } from 'protractor';
|
||||
|
||||
|
||||
describe('TaskList', function () {
|
||||
|
||||
let page: TaskListPage;
|
||||
beforeEach(() => {
|
||||
page = new TaskListPage();
|
||||
page.navigateTo();
|
||||
});
|
||||
|
||||
xit('should allow to create new tasks (forgot to press save)', () => {
|
||||
|
||||
const editPage = page.gotoNewTaskView();
|
||||
editPage.fillForm('New Task', 'BACKLOG');
|
||||
// editPage.save();
|
||||
|
||||
expect(page.checkTaskDisplayed('New Task')).not.toBeNull();
|
||||
|
||||
});
|
||||
|
||||
it('should allow searching for tasks', () => {
|
||||
page.searchForTasks('Ersten');
|
||||
expect(page.getTaskCount()).toEqual(1);
|
||||
});
|
||||
|
||||
it('should work with no search results', () => {
|
||||
page.searchForTasks('Ich existiere nicht.');
|
||||
expect(page.getTaskCount()).toEqual(0);
|
||||
});
|
||||
|
||||
|
||||
it('should allow to create new tasks', () => {
|
||||
const taskTitle = `New Task ${new Date().getTime()}`;
|
||||
const editPage = page.gotoNewTaskView();
|
||||
editPage.fillForm(taskTitle, 'IN_PROGRESS');
|
||||
editPage.save();
|
||||
takeScreenshot('createTaskFailure.png');
|
||||
page.checkTaskDisplayed(taskTitle);
|
||||
});
|
||||
|
||||
it('should add new tasks to the displayed list', () => {
|
||||
page.getTaskCount().then(count => {
|
||||
const editPage = page.gotoNewTaskView();
|
||||
editPage.fillForm('New Task', 'IN_PROGRESS');
|
||||
editPage.save();
|
||||
expect(page.getTaskCount()).toEqual(count + 1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
import { browser, element, by} from 'protractor';
|
||||
import { ExpectedConditions as EC} from 'protractor';
|
||||
import {EditTaskPage} from './edit-task.po';
|
||||
|
||||
export class TaskListPage {
|
||||
|
||||
navigateTo() {
|
||||
return browser.get('/tasks');
|
||||
}
|
||||
|
||||
searchForTasks(term: string) {
|
||||
element(by.css('#search-tasks')).sendKeys(term);
|
||||
browser.sleep(500);
|
||||
}
|
||||
|
||||
getTaskCount() {
|
||||
return element.all(by.className('task-list-entry')).count();
|
||||
}
|
||||
|
||||
gotoNewTaskView() {
|
||||
element(by.linkText('Neue Aufgabe anlegen')).click();
|
||||
return new EditTaskPage();
|
||||
}
|
||||
|
||||
checkTaskDisplayed(text: string) {
|
||||
const taskLink = element(by.linkText(text));
|
||||
browser.wait(EC.presenceOf(taskLink), 10000);
|
||||
return taskLink.isDisplayed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"declaration": false,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../dist/out-tsc-e2e",
|
||||
"sourceMap": true,
|
||||
"target": "es5",
|
||||
"typeRoots": [
|
||||
"../node_modules/@types"
|
||||
],
|
||||
"types": [
|
||||
"jasmine", "node"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/0.13/config/configuration-file.html
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', 'angular-cli'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-remap-istanbul'),
|
||||
require('karma-spec-reporter'),
|
||||
require('angular-cli/plugins/karma')
|
||||
],
|
||||
files: [
|
||||
{ pattern: './src/test.ts', watched: false }
|
||||
],
|
||||
preprocessors: {
|
||||
'./src/test.ts': ['angular-cli']
|
||||
},
|
||||
mime: {
|
||||
'text/x-typescript': ['ts','tsx']
|
||||
},
|
||||
remapIstanbulReporter: {
|
||||
reports: {
|
||||
html: 'coverage',
|
||||
lcovonly: './coverage/coverage.lcov'
|
||||
}
|
||||
},
|
||||
angularCli: {
|
||||
config: './angular-cli.json',
|
||||
environment: 'dev'
|
||||
},
|
||||
reporters: config.angularCli && config.angularCli.codeCoverage
|
||||
? ['spec', 'karma-remap-istanbul']
|
||||
: ['spec'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false
|
||||
});
|
||||
};
|
|
@ -44,16 +44,6 @@
|
|||
"@types/node": "^6.0.42",
|
||||
"angular-cli": "1.0.0-beta.25.5",
|
||||
"codelyzer": "~2.0.0-beta.1",
|
||||
"jasmine-core": "2.5.2",
|
||||
"jasmine-spec-reporter": "2.5.0",
|
||||
"karma-spec-reporter": "0.0.26",
|
||||
"karma": "1.2.0",
|
||||
"karma-chrome-launcher": "^2.0.0",
|
||||
"karma-cli": "^1.0.1",
|
||||
"karma-jasmine": "^1.0.2",
|
||||
"karma-remap-istanbul": "^0.2.1",
|
||||
"protractor": "~4.0.13",
|
||||
"protractor-jasmine2-screenshot-reporter": "^0.3.2",
|
||||
"ts-node": "1.2.1",
|
||||
"tslint": "^4.3.0",
|
||||
"typescript": "~2.0.3"
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
// Protractor configuration file, see link for more information
|
||||
// https://github.com/angular/protractor/blob/master/lib/config.ts
|
||||
|
||||
/*global jasmine */
|
||||
var SpecReporter = require('jasmine-spec-reporter');
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
specs: [
|
||||
'./e2e/**/*.e2e-spec.ts'
|
||||
],
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
directConnect: true,
|
||||
baseUrl: 'http://localhost:4200/',
|
||||
framework: 'jasmine',
|
||||
jasmineNodeOpts: {
|
||||
showColors: true,
|
||||
defaultTimeoutInterval: 30000,
|
||||
print: function() {}
|
||||
},
|
||||
useAllAngular2AppRoots: true,
|
||||
beforeLaunch: function() {
|
||||
require('ts-node').register({
|
||||
project: 'e2e'
|
||||
});
|
||||
},
|
||||
onPrepare: function() {
|
||||
jasmine.getEnv().addReporter(new SpecReporter());
|
||||
}
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
import {EmailValidatorDirective} from "./app-validators";
|
||||
|
||||
|
||||
describe('EMail-Validator', () => {
|
||||
let validator = null;
|
||||
beforeEach(() => {
|
||||
validator = new EmailValidatorDirective();
|
||||
});
|
||||
|
||||
it('should accept valid email addresses', () => {
|
||||
const control = <any> {value: "foo@bar.com"};
|
||||
const result = validator.validate(control);
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
it('should not accept invalid email addresses', () => {
|
||||
const control = <any> {value: "foobar.com"};
|
||||
const result = validator.validate(control);
|
||||
expect(result['invalidEMail']).toBeTruthy();
|
||||
});
|
||||
it('should accept empty email addresses', () => {
|
||||
const control = <any> {value: ""};
|
||||
const result = validator.validate(control);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
|
@ -1,90 +0,0 @@
|
|||
import {TestBed, inject, fakeAsync} from '@angular/core/testing';
|
||||
import { BaseRequestOptions, Http, ConnectionBackend, Response, ResponseOptions, RequestMethod } from '@angular/http';
|
||||
import {TaskService} from './task.service';
|
||||
import {MockBackend} from '@angular/http/testing/mock_backend';
|
||||
import {TaskStore} from '../stores/task.store';
|
||||
import {SOCKET_IO} from '../../app.tokens';
|
||||
import {mockIO} from '../../mocks/mock-socket';
|
||||
|
||||
describe('Task-Service', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
TaskService,
|
||||
TaskStore,
|
||||
{provide: SOCKET_IO, useValue: mockIO},
|
||||
BaseRequestOptions,
|
||||
MockBackend,
|
||||
{provide: Http, useFactory: (mockBackend: ConnectionBackend,
|
||||
defaultOptions: BaseRequestOptions) => {
|
||||
return new Http(mockBackend, defaultOptions);
|
||||
}, deps: [MockBackend, BaseRequestOptions]},
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
let taskService: TaskService;
|
||||
let taskStore: TaskStore;
|
||||
let mockBackend: MockBackend;
|
||||
|
||||
beforeEach(inject([TaskService, TaskStore, MockBackend],
|
||||
(_taskService, _taskStore, _mockBackend) => {
|
||||
taskService = _taskService;
|
||||
taskStore = _taskStore;
|
||||
mockBackend = _mockBackend;
|
||||
})
|
||||
);
|
||||
|
||||
const saveTask = (task, expectedUrl = null, expectedMethod = null) => {
|
||||
mockBackend.connections.subscribe(connection => {
|
||||
if (expectedUrl) {
|
||||
expect(connection.request.url).toBe(expectedUrl);
|
||||
}
|
||||
if (expectedMethod) {
|
||||
expect(connection.request.method).toBe(expectedMethod);
|
||||
}
|
||||
const response = new ResponseOptions({body: JSON.stringify(task)});
|
||||
connection.mockRespond(new Response(response));
|
||||
});
|
||||
taskService.saveTask(task).subscribe();
|
||||
};
|
||||
|
||||
it('should trigger a HTTP-POST for new Tasks', (() => {
|
||||
const task = {title: 'Task 1'};
|
||||
mockBackend.connections.subscribe(connection => {
|
||||
const expectedUrl = 'http://localhost:3000/api/tasks/';
|
||||
expect(connection.request.url).toBe(expectedUrl);
|
||||
expect(connection.request.method).toBe(RequestMethod.Post);
|
||||
const response = new ResponseOptions({body: JSON.stringify(task)});
|
||||
connection.mockRespond(new Response(response));
|
||||
});
|
||||
taskService.saveTask(task).subscribe();
|
||||
}));
|
||||
|
||||
it('should trigger a HTTP-POST for new Tasks', (() => {
|
||||
const task = {title: 'Task 1'};
|
||||
saveTask(task, 'http://localhost:3000/api/tasks/', RequestMethod.Post);
|
||||
}));
|
||||
|
||||
it('should do a HTTP-Put for existing Tasks', (() => {
|
||||
const task = {id: 1, title: 'Existing Task'};
|
||||
saveTask(task, 'http://localhost:3000/api/tasks/1', RequestMethod.Put);
|
||||
}));
|
||||
|
||||
it('should add the Task to the store', (() => {
|
||||
const spy = spyOn(taskStore, 'dispatch').and.callThrough();
|
||||
saveTask({title: 'Task 1'});
|
||||
const dispatchedAction = spy.calls.mostRecent().args[0];
|
||||
expect(dispatchedAction.type).toEqual('ADD');
|
||||
expect(dispatchedAction.data.title).toEqual('Task 1');
|
||||
}));
|
||||
|
||||
it('should save the Task in store', (() => {
|
||||
const spy = spyOn(taskStore, 'dispatch').and.callThrough();
|
||||
saveTask({id: 1, title: 'Task 1'});
|
||||
const dispatchedAction = spy.calls.mostRecent().args[0];
|
||||
expect(dispatchedAction.type).toEqual('EDIT');
|
||||
expect(dispatchedAction.data.title).toEqual('Task 1');
|
||||
}));
|
||||
|
||||
});
|
|
@ -1,71 +0,0 @@
|
|||
|
||||
import {NgForm, FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
|
||||
|
||||
import {
|
||||
ComponentFixture
|
||||
} from '@angular/core/testing'
|
||||
|
||||
import {By} from '@angular/platform-browser';
|
||||
import {ShowErrorComponent} from './show-error.component';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
export class FakeForm {
|
||||
constructor(private control: any) {
|
||||
}
|
||||
|
||||
get(str: string) {
|
||||
return this.control;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
describe('ShowError Component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [FormsModule, ReactiveFormsModule],
|
||||
declarations: [ShowErrorComponent],
|
||||
providers: [NgForm]
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
let fixture: ComponentFixture<ShowErrorComponent>;
|
||||
|
||||
it('should display "required" error for touched controls', (done) => {
|
||||
fixture = TestBed.createComponent(ShowErrorComponent);
|
||||
fixture.whenStable().then(() => {
|
||||
const showErrorCmp: ShowErrorComponent = fixture.componentInstance;
|
||||
const element = fixture.nativeElement;
|
||||
(<any>showErrorCmp).form = new FakeForm({
|
||||
touched: true,
|
||||
errors: {
|
||||
required: true
|
||||
}
|
||||
});
|
||||
(<any>showErrorCmp).displayName = 'Vorname';
|
||||
fixture.detectChanges(); //Change-Detection auslösen
|
||||
expect(element.querySelector('.alert-danger').textContent)
|
||||
.toContain('Vorname ist ein Pflichtfeld');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should display no errors for untouched controls', () => {
|
||||
fixture = TestBed.createComponent(ShowErrorComponent);
|
||||
|
||||
const showErrorCmp: ShowErrorComponent = fixture.componentInstance;
|
||||
const fakeControl: any = {touched: false, errors: {required: true}};
|
||||
(<any>showErrorCmp).form = new FakeForm(fakeControl);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('.alert-danger')).toBeNull();
|
||||
expect(fixture.debugElement.query(By.css('.alert-danger'))).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
import {TaskService} from '../../services/task-service/task.service';
|
||||
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
|
||||
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
|
||||
import {TestBed, inject} from '@angular/core/testing';
|
||||
import {EditTaskComponent} from './edit-task.component';
|
||||
import {ShowErrorComponent} from '../../show-error/show-error.component';
|
||||
import {APPLICATION_VALIDATORS} from '../../models/app-validators';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {fakeAsync, tick} from '@angular/core/testing/fake_async';
|
||||
import {Title} from '@angular/platform-browser';
|
||||
import {Component} from '@angular/core';
|
||||
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
|
||||
import {MockTaskService} from '../../mocks/mock-task-service';
|
||||
|
||||
@Component({
|
||||
template: '<router-outlet></router-outlet>'
|
||||
})
|
||||
class TestComponent {
|
||||
}
|
||||
|
||||
describe('EditTask Component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [FormsModule, RouterTestingModule.withRoutes([
|
||||
{path: 'new', component: EditTaskComponent},
|
||||
{path: 'edit/:id', component: EditTaskComponent}
|
||||
],
|
||||
)],
|
||||
declarations: [EditTaskComponent, ShowErrorComponent, APPLICATION_VALIDATORS, TestComponent],
|
||||
providers: [
|
||||
Title,
|
||||
{provide: TaskService, useClass: MockTaskService},
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
let taskService: TaskService;
|
||||
beforeEach(inject([TaskService], (_taskService) => {
|
||||
taskService = _taskService;
|
||||
}));
|
||||
|
||||
it('should load the correct task in Edit-Mode', fakeAsync(() => {
|
||||
const fixture = TestBed.createComponent(EditTaskComponent);
|
||||
const route = TestBed.get(ActivatedRoute);
|
||||
(<any>route.params).next({id: '42'});
|
||||
|
||||
const element = fixture.nativeElement;
|
||||
|
||||
const spy = spyOn(taskService, 'getTask');
|
||||
const fakeTask = {title: 'Task1', assignee: {name: 'John'}};
|
||||
spy.and.returnValue(new BehaviorSubject(fakeTask));
|
||||
|
||||
fixture.autoDetectChanges(true);
|
||||
fixture.whenStable().then(() => {
|
||||
tick();
|
||||
expect(spy).toHaveBeenCalledWith('42');
|
||||
const titleInput = element.querySelector('#title');
|
||||
expect(titleInput.value).toBe(fakeTask.title);
|
||||
|
||||
const assigneeInput = element.querySelector('#assignee_name');
|
||||
expect(assigneeInput.value).toBe(fakeTask.assignee.name);
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should load the correct task (with router)', fakeAsync(() => {
|
||||
const fixture = TestBed.createComponent(TestComponent);
|
||||
const router = TestBed.get(Router);
|
||||
router.navigateByUrl('edit/42');
|
||||
|
||||
const spy = spyOn(taskService, 'getTask');
|
||||
const fakeTask = {title: 'Task1', assignee: {name: 'John'}};
|
||||
spy.and.returnValue(new BehaviorSubject(fakeTask));
|
||||
fixture.whenStable().then(() => {
|
||||
tick();
|
||||
expect(spy).toHaveBeenCalledWith('42');
|
||||
const titleInput = fixture.nativeElement.querySelector('#title');
|
||||
expect(titleInput.value).toBe(fakeTask.title);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should work without passing URL-Parameter', fakeAsync(() => {
|
||||
const fixture = TestBed.createComponent(TestComponent);
|
||||
const router = TestBed.get(Router);
|
||||
router.navigateByUrl('new');
|
||||
const spy = spyOn(taskService, 'getTask');
|
||||
fixture.whenStable().then(() => {
|
||||
tick();
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
const titleInput = fixture.nativeElement.querySelector('#title');
|
||||
expect(titleInput.value).toBe('');
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
});
|
|
@ -1,88 +0,0 @@
|
|||
import {TaskService} from '../../services/task-service/task.service';
|
||||
|
||||
import {RouterTestingModule} from '@angular/router/testing';
|
||||
|
||||
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
|
||||
import {TestBed, inject, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {TaskItemComponent} from './task-item.component';
|
||||
import {TaskListComponent} from './task-list.component';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import {MockTaskService} from '../../mocks/mock-task-service';
|
||||
import {setInputValue} from '../../testing/test-helper';
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 4000;
|
||||
|
||||
describe('TaskList Component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ReactiveFormsModule, RouterTestingModule.withRoutes([])],
|
||||
declarations: [TaskListComponent, TaskItemComponent],
|
||||
providers: [
|
||||
{provide: TaskService, useClass: MockTaskService},
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
let taskService: TaskService;
|
||||
beforeEach(inject([TaskService], (_taskService: TaskService) => {
|
||||
taskService = _taskService;
|
||||
}));
|
||||
|
||||
it('should display TaskItems in the List', () => {
|
||||
const fixture = TestBed.createComponent(TaskListComponent);
|
||||
const element = fixture.nativeElement;
|
||||
|
||||
(<BehaviorSubject<any>>taskService.tasks$).next([
|
||||
{id: 1, title: 'Task1', description: 'Hello Karma'},
|
||||
{id: 2, title: 'Task2', description: 'Hello Jasmine'}
|
||||
]);
|
||||
|
||||
fixture.detectChanges(); //trigger change detection
|
||||
|
||||
expect(element.querySelectorAll('.task-list-entry').length).toBe(2);
|
||||
expect(element.querySelector('.task-list-entry').textContent)
|
||||
.toContain('Hello Karma');
|
||||
});
|
||||
|
||||
it('should display TaskItems in the List (with TestBed.get)', () => {
|
||||
const fixture = TestBed.createComponent(TaskListComponent);
|
||||
const taskService = TestBed.get(TaskService);
|
||||
const element = fixture.nativeElement;
|
||||
|
||||
(<BehaviorSubject<any>>taskService.tasks$).next([
|
||||
{id: 1, title: 'Task1', description: 'Hello Karma'},
|
||||
{id: 2, title: 'Task2', description: 'Hello Jasmine'}
|
||||
]);
|
||||
|
||||
fixture.detectChanges(); //trigger change detection
|
||||
|
||||
expect(element.querySelectorAll('.task-list-entry').length).toBe(2);
|
||||
expect(element.querySelector('.task-list-entry').textContent)
|
||||
.toContain('Hello Karma');
|
||||
});
|
||||
|
||||
it('should call deleteTask when clicking the trash-bin', fakeAsync(() => {
|
||||
const fixture = TestBed.createComponent(TaskListComponent);
|
||||
|
||||
// Task-Liste füllen
|
||||
const task = {id: 42, title: 'Task 1'};
|
||||
(<BehaviorSubject<any>>taskService.tasks$).next([task]);
|
||||
fixture.detectChanges(); //trigger change detection
|
||||
|
||||
// Spy programmieren
|
||||
const spy = spyOn(taskService, 'deleteTask');
|
||||
spy.and.returnValue(new BehaviorSubject<any>({}));
|
||||
|
||||
// Task löschen
|
||||
const trash = fixture.nativeElement.querySelector('.glyphicon-trash');
|
||||
trash.click();
|
||||
|
||||
// Spy auswerten
|
||||
const deleteArguments = spy.calls.mostRecent().args;
|
||||
expect(deleteArguments[0]).toBe(task);
|
||||
expect(taskService.deleteTask).toHaveBeenCalledWith(task);
|
||||
}));
|
||||
|
||||
});
|
|
@ -1,11 +0,0 @@
|
|||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
|
||||
export function dispatchEvent(element: any, eventType: any) {
|
||||
getDOM().dispatchEvent(element, getDOM().createEvent(eventType));
|
||||
}
|
||||
|
||||
export function setInputValue(input: any, value: any) {
|
||||
input.value = value;
|
||||
dispatchEvent(input, 'input');
|
||||
dispatchEvent(input, 'blur');
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
import './polyfills.ts';
|
||||
|
||||
import 'zone.js/dist/long-stack-trace-zone';
|
||||
import 'zone.js/dist/proxy.js';
|
||||
import 'zone.js/dist/sync-test';
|
||||
import 'zone.js/dist/jasmine-patch';
|
||||
import 'zone.js/dist/async-test';
|
||||
import 'zone.js/dist/fake-async-test';
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
import 'rxjs/Rx';
|
||||
|
||||
|
||||
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
|
||||
declare var __karma__: any;
|
||||
declare var require: any;
|
||||
|
||||
// Prevent Karma from running prematurely.
|
||||
__karma__.loaded = function () {};
|
||||
|
||||
// First, initialize the Angular testing environment.
|
||||
getTestBed().initTestEnvironment(
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting()
|
||||
);
|
||||
// Then we find all the tests.
|
||||
const context = require.context('./', true, /\.spec\.ts$/);
|
||||
// And load the modules.
|
||||
context.keys().map(context);
|
||||
// Finally, start Karma to run the tests.
|
||||
__karma__.start();
|
Loading…
Reference in New Issue