diff --git a/karma.conf.js b/karma.conf.js index 5955f21..937e002 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -23,6 +23,8 @@ function listFiles() { var patterns = [].concat(wiredep(wiredepOptions).js) .concat([ + './src/commons.js', + './src/noosfero.js', './src/noosfero-specs.js' ] //[ @@ -124,7 +126,8 @@ module.exports = function (config) { // It was not possible to do it there because karma doesn't let us now if we are // running a single test or not configuration.preprocessors = { - 'src/**/*.js': ['sourcemap'] + 'src/**/*.js': ['sourcemap'], + 'src/**/*.ts': ['sourcemap'] }; // 'src/**/*.js': ['sourcemap'], // 'src/**/*.[sS]pec.ts': ['sourcemap'] diff --git a/src/app/components/noosfero-articles/article/article.directive.spec.ts b/src/app/components/noosfero-articles/article/article.directive.spec.ts index 89c6d0a..6e2fd5c 100644 --- a/src/app/components/noosfero-articles/article/article.directive.spec.ts +++ b/src/app/components/noosfero-articles/article/article.directive.spec.ts @@ -8,21 +8,21 @@ import {ArticleDirective} from './article.directive'; const tcb = new TestComponentBuilder(); +let html = ''; + // Create a component to include your testing component -@Component({ selector: 'my-test' , template: '
'}) +@Component({ selector: 'my-test', template: html, directives: [ArticleDirective] }) class TestArticleDirective { article = { type: 'TinyMceArticle' }; profile = { name: 'profile-name' }; - constructor(){ + constructor() { } } describe("Article Directive", () => { it("receives the article and profile as inputs", done => { - let html = ''; tcb - .overrideTemplate(TestArticleDirective, html) .createAsync(TestArticleDirective).then(fixture => { let myComponent: ArticleDirective = fixture.componentInstance; expect(myComponent.article.type).toEqual("TinyMceArticle"); @@ -32,4 +32,28 @@ describe("Article Directive", () => { }); }); + it("renders a directive corresponding to the article type", done => { + + @Component({ selector: 'noosfero-TinyMceArticle', template: "

custom component

" }) + class CustomArticleComponent { + + } + + @Component({ selector: 'custom-article-type-test', template: html, directives: [ArticleDirective, CustomArticleComponent] }) + class CustomArticleType { + article = { type: 'TinyMceArticle' }; + profile = { name: 'profile-name' }; + constructor() { + } + } + tcb + .createAsync(CustomArticleType).then(fixture => { + let myComponent: CustomArticleType = fixture.componentInstance; + expect(myComponent.article.type).toEqual("TinyMceArticle"); + expect(myComponent.profile.name).toEqual("profile-name"); + console.log(fixture.debugElement); + done(); + }); + }); + }); \ No newline at end of file diff --git a/src/app/index.ts b/src/app/index.ts index e4534ec..ba50481 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -1,4 +1,5 @@ +import "core-js/shim"; import "reflect-metadata"; import {NoosferoApp} from "./index.module"; import {noosferoModuleConfig} from "./index.config"; diff --git a/webpack.config.js b/webpack.config.js index 1d36066..ac01fa6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,7 +3,8 @@ var argv = require("yargs").argv; var path = require("path"); var glob = require("glob"); -var webpack = require("webpack"); + +var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); var extension = ".js"; if (argv.production) { @@ -27,6 +28,7 @@ var webpackConfig = { 'noosfero-specs': './src/spec.ts' }, + plugins: [ new CommonsChunkPlugin("commons.js")], output: { path: path.join(__dirname, "src"), -- libgit2 0.21.2