import assert from 'assert';
import { transform } from 'babel-core';
import appDecoratorComponent from'../src/index';
import syntaxDecorator from 'babel-plugin-syntax-decorators';

function trim(str) {
    return str.replace(/^\s+|\s+/gm, '');
}

describe('@component', () => {

    it('should add class extends HTMLElement when no options passed', () => {

        let actual =`
            @component()
            class Foo {
            }`;

        let expected = `
            @component()
            class Foo extends HTMLDivElement {}`;

        let generated = transform(actual, {
            plugins: [
                appDecoratorComponent,
                syntaxDecorator,
            ]
        });

        assert.equal(trim(generated.code), trim(expected));

    });

    it('should add "class extends HTML{type}" when options passed', () => {

        let actual =`
            @component({
               extends: 'img'
            })
            class Foo {
            }`;

        let expected =`
            @component({
               extends: 'img'
            })
            class Foo extends HTMLImageElement {
                static get extends() {
                    return 'img';
            }}`;

        let generated = transform(actual, {
            plugins: [
                appDecoratorComponent,
                syntaxDecorator,
            ]
        });

        assert.equal(trim(generated.code), trim(expected));

    });

    it('should add "class extends HTML{type}" by mixed classes', () => {

        let actual =`
            class Foo {}

            @component({
               extends: 'progress'
            })
            class Bar {
            }

            class Baz {}`;

        let expected =`
            class Foo {}

            @component({
               extends: 'progress'
            })
            class Bar extends HTMLProgressElement {
                static get extends() {
                    return 'progress';
            }}

            class Baz {}`;

        let generated = transform(actual, {
            plugins: [
                appDecoratorComponent,
                syntaxDecorator,
            ]
        });

        assert.equal(trim(generated.code), trim(expected));

    });

    it('should resolve and add "class extends HTML{type}" when options passed', () => {

        let actual =`
            class Foo {}
            class Bar extends Foo {}
            
            @component({
               extends: 'form'
            })
            class Baz extends Bar {
            }`;

        let expected = `
            class Foo extends HTMLFormElement {}
            class Bar extends Foo {}
            
            @component({
               extends: 'form'
            })
            class Baz extends Bar {
                static get extends() {
                    return 'form';
                }
            }`;

        let generated = transform(actual, {
            plugins: [
                appDecoratorComponent,
                syntaxDecorator,
            ]
        });

        assert.equal(trim(generated.code), trim(expected));

    });

    it('should resolve passed argument', () => {

        let actual =`
            let options = {
               extends: 'form'
            };
            @component(options)
            class Baz {
            }`;

        let expected = `
            let options = {
               extends: 'form'
            };
            @component(options)
            class Baz extends HTMLFormElement {
                static get extends() {
                    return 'form';
                }
            }`;

        let generated = transform(actual, {
            plugins: [
                appDecoratorComponent,
                syntaxDecorator,
            ]
        });

        assert.equal(trim(generated.code), trim(expected));

    });

});

@@ -2259,1637 +2259,8 @@
 );%0A%0A
-    it('should resolve and add %22class extends HTML%7Btype%7D%22 when options passed', () =%3E %7B%0A%0A        let actual =%60%0A            class Foo %7B%7D%0A            class Bar extends Foo %7B%7D%0A            %0A            @component(%7B%0A               extends: 'form'%0A            %7D)%0A            class Baz extends Bar %7B%0A            %7D%60;%0A%0A        let expected = %60%0A            class Foo extends HTMLFormElement %7B%7D%0A            class Bar extends Foo %7B%7D%0A            %0A            @component(%7B%0A               extends: 'form'%0A            %7D)%0A            class Baz extends Bar %7B%0A                static get extends() %7B%0A                    return 'form';%0A                %7D%0A            %7D%60;%0A%0A        let generated = transform(actual, %7B%0A            plugins: %5B%0A                appDecoratorComponent,%0A                syntaxDecorator,%0A            %5D%0A        %7D);%0A%0A        assert.equal(trim(generated.code), trim(expected));%0A%0A    %7D);%0A%0A    it('should resolve passed argument', () =%3E %7B%0A%0A        let actual =%60%0A            let options = %7B%0A               extends: 'form'%0A            %7D;%0A            @component(options)%0A            class Baz %7B%0A            %7D%60;%0A%0A        let expected = %60%0A            let options = %7B%0A               extends: 'form'%0A            %7D;%0A            @component(options)%0A            class Baz extends HTMLFormElement %7B%0A                static get extends() %7B%0A                    return 'form';%0A                %7D%0A            %7D%60;%0A%0A        let generated = transform(actual, %7B%0A            plugins: %5B%0A                appDecoratorComponent,%0A                syntaxDecorator,%0A            %5D%0A        %7D);%0A%0A        assert.equal(trim(generated.code), trim(expected));%0A%0A    %7D);%0A%0A
 %7D);%0A

remove tests