From 5d7f7cfd5e611de80f986aacd40c8449acf05d45 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Wed, 22 Mar 2017 06:37:47 +0100 Subject: [PATCH] Reverse previous commit --- .../e2e/dashboard/dashboard.e2e-spec.ts | 24 +++++++++ .../e2e/helpers/take_screenshot.ts | 12 +++++ .../e2e/tasks/edit-task.e2e-spec.ts | 26 +++++++++ project-manager/e2e/tasks/edit-task.po.ts | 34 ++++++++++++ .../task-list-no-page-object.e2e-spec.ts | 25 +++++++++ .../e2e/tasks/task-list.e2e-spec.ts | 54 +++++++++++++++++++ project-manager/e2e/tasks/task-list.po.ts | 32 +++++++++++ project-manager/e2e/tsconfig.json | 19 +++++++ project-manager/karma.conf.js | 44 +++++++++++++++ .../protractor-html-reporter.conf.js | 52 ++++++++++++++++++ project-manager/protractor.conf.js | 32 +++++++++++ .../src/app/testing/test-helper.ts | 11 ++++ project-manager/src/test.ts | 34 ++++++++++++ 13 files changed, 399 insertions(+) create mode 100644 project-manager/e2e/dashboard/dashboard.e2e-spec.ts create mode 100644 project-manager/e2e/helpers/take_screenshot.ts create mode 100644 project-manager/e2e/tasks/edit-task.e2e-spec.ts create mode 100644 project-manager/e2e/tasks/edit-task.po.ts create mode 100644 project-manager/e2e/tasks/task-list-no-page-object.e2e-spec.ts create mode 100644 project-manager/e2e/tasks/task-list.e2e-spec.ts create mode 100644 project-manager/e2e/tasks/task-list.po.ts create mode 100644 project-manager/e2e/tsconfig.json create mode 100644 project-manager/karma.conf.js create mode 100644 project-manager/protractor-html-reporter.conf.js create mode 100644 project-manager/protractor.conf.js create mode 100644 project-manager/src/app/testing/test-helper.ts create mode 100644 project-manager/src/test.ts diff --git a/project-manager/e2e/dashboard/dashboard.e2e-spec.ts b/project-manager/e2e/dashboard/dashboard.e2e-spec.ts new file mode 100644 index 0000000..36222fa --- /dev/null +++ b/project-manager/e2e/dashboard/dashboard.e2e-spec.ts @@ -0,0 +1,24 @@ +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'); + }); + +}); diff --git a/project-manager/e2e/helpers/take_screenshot.ts b/project-manager/e2e/helpers/take_screenshot.ts new file mode 100644 index 0000000..c2c00c2 --- /dev/null +++ b/project-manager/e2e/helpers/take_screenshot.ts @@ -0,0 +1,12 @@ +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(); + }) +} \ No newline at end of file diff --git a/project-manager/e2e/tasks/edit-task.e2e-spec.ts b/project-manager/e2e/tasks/edit-task.e2e-spec.ts new file mode 100644 index 0000000..3a25155 --- /dev/null +++ b/project-manager/e2e/tasks/edit-task.e2e-spec.ts @@ -0,0 +1,26 @@ +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); + }); +}); \ No newline at end of file diff --git a/project-manager/e2e/tasks/edit-task.po.ts b/project-manager/e2e/tasks/edit-task.po.ts new file mode 100644 index 0000000..a695a49 --- /dev/null +++ b/project-manager/e2e/tasks/edit-task.po.ts @@ -0,0 +1,34 @@ +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(); + } + +} + diff --git a/project-manager/e2e/tasks/task-list-no-page-object.e2e-spec.ts b/project-manager/e2e/tasks/task-list-no-page-object.e2e-spec.ts new file mode 100644 index 0000000..1d104f4 --- /dev/null +++ b/project-manager/e2e/tasks/task-list-no-page-object.e2e-spec.ts @@ -0,0 +1,25 @@ +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); + }); + + +}); diff --git a/project-manager/e2e/tasks/task-list.e2e-spec.ts b/project-manager/e2e/tasks/task-list.e2e-spec.ts new file mode 100644 index 0000000..c24a8d0 --- /dev/null +++ b/project-manager/e2e/tasks/task-list.e2e-spec.ts @@ -0,0 +1,54 @@ + +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); + }); + }); + +}); diff --git a/project-manager/e2e/tasks/task-list.po.ts b/project-manager/e2e/tasks/task-list.po.ts new file mode 100644 index 0000000..ef8d311 --- /dev/null +++ b/project-manager/e2e/tasks/task-list.po.ts @@ -0,0 +1,32 @@ +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(); + } + +} + diff --git a/project-manager/e2e/tsconfig.json b/project-manager/e2e/tsconfig.json new file mode 100644 index 0000000..a372020 --- /dev/null +++ b/project-manager/e2e/tsconfig.json @@ -0,0 +1,19 @@ +{ + "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" + ] + } +} diff --git a/project-manager/karma.conf.js b/project-manager/karma.conf.js new file mode 100644 index 0000000..a79edd1 --- /dev/null +++ b/project-manager/karma.conf.js @@ -0,0 +1,44 @@ +// 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 + }); +}; diff --git a/project-manager/protractor-html-reporter.conf.js b/project-manager/protractor-html-reporter.conf.js new file mode 100644 index 0000000..b9360f8 --- /dev/null +++ b/project-manager/protractor-html-reporter.conf.js @@ -0,0 +1,52 @@ +// Protractor configuration file, see link for more information +// https://github.com/angular/protractor/blob/master/docs/referenceConf.js + +/*global jasmine */ +var SpecReporter = require('jasmine-spec-reporter'); +//var ScreenshotProcessor = require('./e2e/helpers/screen_shot_reporter.ts'); +var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter'); + +var reporter = new HtmlScreenshotReporter({ + dest: 'tmp/screenshots', + filename: 'test-report.html', + cleanDestination: true, + ignoreSkippedSpecs: true, + captureOnlyFailedSpecs: false +}); + + +exports.config = { + allScriptsTimeout: 11000, + specs: [ + './e2e/**/*.e2e-spec.ts' + ], + capabilities: { + 'browserName': 'firefox' + }, + 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' + }); + return new Promise(function(resolve){ + reporter.beforeLaunch(resolve); + }); + }, + afterLaunch: function(exitCode) { + return new Promise(function(resolve){ + reporter.afterLaunch(resolve.bind(this, exitCode)); + }); + }, + onPrepare: function() { + jasmine.getEnv().addReporter(reporter); + jasmine.getEnv().addReporter(new SpecReporter()); + }, +}; \ No newline at end of file diff --git a/project-manager/protractor.conf.js b/project-manager/protractor.conf.js new file mode 100644 index 0000000..ffded70 --- /dev/null +++ b/project-manager/protractor.conf.js @@ -0,0 +1,32 @@ +// 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()); + } +}; diff --git a/project-manager/src/app/testing/test-helper.ts b/project-manager/src/app/testing/test-helper.ts new file mode 100644 index 0000000..f5ac2fa --- /dev/null +++ b/project-manager/src/app/testing/test-helper.ts @@ -0,0 +1,11 @@ +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'); +} \ No newline at end of file diff --git a/project-manager/src/test.ts b/project-manager/src/test.ts new file mode 100644 index 0000000..abce206 --- /dev/null +++ b/project-manager/src/test.ts @@ -0,0 +1,34 @@ +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();