const qtek = require('../../../dist/qtek');
const { util, helper } = require('../../common');
const path = require('path');

describe('Integration.lights.Spec', function () {
    it('directional light', function (done) {
        const { renderer, scene, camera, canvas } = helper.createQtekScene(); 

        const light = new qtek.light.Directional({
            intensity: 1
        });
        light.position.set(30, 30, 30);
        light.lookAt(scene.position);
         
        scene.add(light);

        var root = new qtek.Node();
        root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);
        scene.add(root);

        const mesh = new qtek.Mesh({
            material: new qtek.Material({
                shader : qtek.shader.library.get('qtek.standard')
            }),
            geometry : new qtek.geometry.Cube()
        });
        root.add(mesh);

        const drawInfo = renderer.render(scene, camera);
        
        util.assertWith(canvas, path.join(__dirname, 'directional-light.png'), done);
    });

    it('ambient light', function (done) {
        const { renderer, scene, camera, canvas } = helper.createQtekScene(); 
    
        scene.add(new qtek.light.Ambient({
            intensity: 0.3
        }));

        var root = new qtek.Node();
        root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);
        scene.add(root);

        const mesh = new qtek.Mesh({
            material: new qtek.Material({
                shader : qtek.shader.library.get('qtek.standard')
            }),
            geometry : new qtek.geometry.Cube()
        });
        root.add(mesh);

        const drawInfo = renderer.render(scene, camera);
        
        util.assertWith(canvas, path.join(__dirname, 'ambient-light.png'), done);
    });

    it('point light', function (done) {
        const { renderer, scene, camera, canvas } = helper.createQtekScene(); 
        
        const light = new qtek.light.Point({
            castShadow: false,
            range: 200
        })
        light.position.set(30, -30, 30);
        light.lookAt(scene.position);

        scene.add(light);

        var root = new qtek.Node();
        root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);
        scene.add(root);

        const mesh = new qtek.Mesh({
            material: new qtek.Material({
                shader : qtek.shader.library.get('qtek.standard')
            }),
            geometry : new qtek.geometry.Cube()
        });
        root.add(mesh);

        const drawInfo = renderer.render(scene, camera);
        
        util.assertWith(canvas, path.join(__dirname, 'point-light.png'), done);
    });
});



@@ -118,16 +118,399 @@
 ath');%0A%0A
+function createCube() %7B%0A    const root = new qtek.Node();%0A    root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);%0A%0A    const mesh = new qtek.Mesh(%7B%0A        material: new qtek.Material(%7B%0A            shader : qtek.shader.library.get('qtek.standard')%0A        %7D),%0A        geometry : new qtek.geometry.Cube()%0A    %7D);%0A    root.add(mesh);%0A%0A    return root;%0A%7D%0A%0A
 describe
@@ -892,1163 +892,489 @@
     
-var root = new qtek.Node();%0A        root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);%0A        scene.add(root);%0A%0A        const mesh = new qtek.Mesh(%7B%0A            material: new qtek.Material(%7B%0A                shader : qtek.shader.library.get('qtek.standard')%0A            %7D),%0A            geometry : new qtek.geometry.Cube()%0A        %7D);%0A        root.add(mesh);%0A%0A        const drawInfo = renderer.render(scene, camera);%0A        %0A        util.assertWith(canvas, path.join(__dirname, 'directional-light.png'), done);%0A    %7D);%0A%0A    it('ambient light', function (done) %7B%0A        const %7B renderer, scene, camera, canvas %7D = helper.createQtekScene(); %0A    %0A        scene.add(new qtek.light.Ambient(%7B%0A            intensity: 0.3%0A        %7D));%0A%0A        var root = new qtek.Node();%0A        root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);%0A        scene.add(root);%0A%0A        const mesh = new qtek.Mesh(%7B%0A            material: new qtek.Material(%7B%0A                shader : qtek.shader.library.get('qtek.standard')%0A            %7D),%0A            geometry : new qtek.geometry.Cube()%0A        %7D);%0A        root.add(mesh
+const cube = createCube();%0A        scene.add(cube);%0A%0A        const drawInfo = renderer.render(scene, camera);%0A        %0A        util.assertWith(canvas, path.join(__dirname, 'directional-light.png'), done);%0A    %7D);%0A%0A    it('ambient light', function (done) %7B%0A        const %7B renderer, scene, camera, canvas %7D = helper.createQtekScene(); %0A    %0A        scene.add(new qtek.light.Ambient(%7B%0A            intensity: 0.3%0A        %7D));%0A%0A        const cube = createCube();%0A        scene.add(cube
 );%0A%0A
@@ -1887,394 +1887,57 @@
     
-var root = new qtek.Node();%0A        root.rotation.identity().rotateY(30 * Math.PI / 180).rotateX(30 * Math.PI / 180);%0A        scene.add(root);%0A%0A        const mesh = new qtek.Mesh(%7B%0A            material: new qtek.Material(%7B%0A                shader : qtek.shader.library.get('qtek.standard')%0A            %7D),%0A            geometry : new qtek.geometry.Cube()%0A        %7D);%0A        root.add(mesh
+const cube = createCube();%0A        scene.add(cube
 );%0A%0A

refactor of lights.spec.js