import { ResourceType, SidebarData } from './sidebar-data';

let sidebar: SidebarData;
declare const __karma__: any;

describe('SidebarData', () => {

    console.log(__karma__.config.args);

    beforeEach(() => {
        sidebar = new SidebarData();
    });
    
    it('should create', () => {
        expect(sidebar.getData().length == 0 && sidebar.getUngroupedData().length == 0).toBeTrue();
    });

    it('should push one group', () => {
        sidebar.pushGroup({
            id: 'id1',
            name: 'g',
            closed: false,
            ordering: 1,
            resources: [],
            error: false
        });

        expect(sidebar.getData().length == 1).toBeTrue();
    });

    it('should push multiple group', (done)=>{

        for(let i = 0; i < 30; i++){
            sidebar.pushGroup({
                id: 'id'+i,
                name: 'g'+i,
                closed: false,
                ordering: i,
                resources: [],
                
            error: false
            });
        }

    
        for(let i = 0; i < sidebar.getData().length; i++){
            expect(sidebar.getData()[i].id == 'id'+i).toBeTrue();
        }
        done();
    });

    it('should work pushGroupBefore', ()=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });


        sidebar.pushGroupBefore({
                id: 'id3',
                name: 'g3',
                closed: false,
                ordering: -1,
                resources: [],
                error: false
        });

        expect(
            sidebar.getData().length == 3 &&
            sidebar.getData()[0].id == "id3" &&
            sidebar.getData()[1].id == "id1" &&
            sidebar.getData()[2].id == "id2"
        ).toBeTrue();
    });

    it('should push in the middle', (done)=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });
        
        expect(sidebar.getData()[1].id == 'id3').toBeTrue();

        sidebar.pushGroup({
            id: 'id4',
            name: 'g4',
            closed: false,
            ordering: 125,
            resources: [],
            error: false
        });
        
        expect(sidebar.getData()[1].id == 'id4').toBeTrue();

        sidebar.pushGroup({
            id: 'id5',
            name: 'g4',
            closed: false,
            ordering: 175,
            resources: [],
            error: false
        });
        
        expect(sidebar.getData()[3].id == 'id5').toBeTrue();

        done();
    });

    it('should push group front', (done)=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 50,
            resources: [],
            error: false
        });

        expect(sidebar.getData()[0].id == 'id3').toBeTrue();

        sidebar.pushGroup({
            id: 'id4',
            name: 'g4',
            closed: false,
            ordering: 25,
            resources: [],
            error: false
        });

        expect(sidebar.getData()[0].id == 'id4').toBeTrue();

        done();
    });

    it('should push group back', (done)=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 250,
            resources: [],
            error: false
        });

        expect(sidebar.getData()[2].id == 'id3').toBeTrue();

        sidebar.pushGroup({
            id: 'id4',
            name: 'g4',
            closed: false,
            ordering: 300,
            resources: [],
            error: false
        });

        expect(sidebar.getData()[3].id == 'id4').toBeTrue();

        done();
    });

    it('should remove group', ()=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.removeGroup('id3');

        expect(
            sidebar.getData().length == 2 && 
            sidebar.getData()[0].id == 'id1' &&
            sidebar.getData()[1].id == 'id2'
            ).toBeTrue();
    });

    it('should edit group name', ()=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.editGroupName('id3', 'f3');

        expect(
            sidebar.getData()[0].name == 'g1' &&
            sidebar.getData()[1].name == 'f3' &&
            sidebar.getData()[2].name == 'g2'
            ).toBeTrue();
    });

    it('should edit group close', (done)=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.editGroupClosed('id3', true);

        expect(
            sidebar.getData()[0].closed == false &&
            sidebar.getData()[1].closed == true &&
            sidebar.getData()[2].closed == false
            ).toBeTrue();

        sidebar.editGroupClosed('id3', false);

        expect(
            sidebar.getData()[0].closed == false &&
            sidebar.getData()[1].closed == false &&
            sidebar.getData()[2].closed == false
            ).toBeTrue();

        done();
    });

    it('should edit group ordering', (done)=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 175,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id4',
            name: 'g4',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });

        sidebar.editGroupOrdering('id2', 180);

        expect(
            sidebar.getData()[0].id == 'id1' &&
            sidebar.getData()[1].id == 'id3' &&
            sidebar.getData()[2].id == 'id2' &&
            sidebar.getData()[3].id == 'id4'
        ).toBeTrue();

        sidebar.editGroupOrdering('id2', 10);

        expect(
            sidebar.getData()[0].id == 'id2' &&
            sidebar.getData()[1].id == 'id1' &&
            sidebar.getData()[2].id == 'id3' &&
            sidebar.getData()[3].id == 'id4'
        ).toBeTrue();

        done();
    });


    it('should work the calcOrdering with an outsider id (private)', ()=>{
        let arr = [
            {id: 1, ordering: 10},
            {id: 2, ordering: 20},
            {id: 3, ordering: 30},
            {id: 4, ordering: 40},
            {id: 5, ordering: 50},
            {id: 6, ordering: 60},
        ];

        // private function
        expect(
            sidebar['calcOrderingByPosition'](arr, 0, null) == 5 &&
            sidebar['calcOrderingByPosition'](arr, 1, null) == 15 &&
            sidebar['calcOrderingByPosition'](arr, 2, null) == 25 &&
            sidebar['calcOrderingByPosition'](arr, 3, null) == 35 &&
            sidebar['calcOrderingByPosition'](arr, 4, null) == 45 &&
            sidebar['calcOrderingByPosition'](arr, 5, null) == 55 &&
            sidebar['calcOrderingByPosition'](arr, 6, null) == 61 &&
            sidebar['calcOrderingByPosition']([], 0, null) == 1
        ).toBeTrue();
    });

    it('should work the calcOrdering with an insider id (private)', ()=>{
        let arr = [
            {id: 1, ordering: 10},
            {id: 2, ordering: 20},
            {id: 3, ordering: 30},
            {id: 4, ordering: 40},
            {id: 5, ordering: 50},
            {id: 6, ordering: 60},
        ];

        // private function
        expect(
            sidebar['calcOrderingByPosition'](arr, 0, 1) == 10 &&
            sidebar['calcOrderingByPosition'](arr, 1, 1) == 25 &&
            sidebar['calcOrderingByPosition'](arr, 2, 1) == 35 &&
            sidebar['calcOrderingByPosition'](arr, 3, 1) == 45 &&
            sidebar['calcOrderingByPosition'](arr, 4, 1) == 55 &&
            sidebar['calcOrderingByPosition'](arr, 5, 1) == 61 &&
            sidebar['calcOrderingByPosition'](arr, 6, 1) == 61 &&
            sidebar['calcOrderingByPosition']([], 0, 1) == 1
        ).toBeTrue();
    });

    it('should work the getGroupIndexById', ()=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 175,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id4',
            name: 'g4',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });

        // private function
        expect(
            sidebar['getGroupIndexById']('id1') == 0 &&
            sidebar['getGroupIndexById']('id2') == 1 &&
            sidebar['getGroupIndexById']('id3') == 2 &&
            sidebar['getGroupIndexById']('id4') == 3
        ).toBeTrue();
    });

    it('should work the getResourceIndexById', ()=>{
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });
        sidebar.pushResource('g2', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            error: false,
            nanoSessions: null
        });
        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        let index = sidebar['getResourceIndexById']('r2');
        // private function
        expect(
            index.groupIndex == 1 &&
            index.resourceIndex == 1
        ).toBeTrue();
    });

    it('should work news with edit seen/top message id', (done)=>{
    
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false,
        });
        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.editResourceLastSeenMessage('r1', "id");
        expect(sidebar.getResourceById('r1').news).toBeFalse();

        sidebar.editResourceTopMessageId('r1', "2");
        
        expect(sidebar.getResourceById('r1').news).toBeTrue();

        sidebar.editResourceLastSeenMessage('r1', "2");
        
        expect(sidebar.getResourceById('r1').news).toBeFalse();

        done();
    });


    it('should work the moveGroup', (done)=>{
        sidebar.pushGroup({
            id: 'id1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id3',
            name: 'g3',
            closed: false,
            ordering: 200,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'id4',
            name: 'g4',
            closed: false,
            ordering: 250,
            resources: [],
            error: false
        });
        
        sidebar.moveGroup('id1', 1);

        expect(
            sidebar.getData()[0].id == 'id2' &&
            sidebar.getData()[1].id == 'id1' &&
            sidebar.getData()[2].id == 'id3' &&
            sidebar.getData()[3].id == 'id4'
        ).toBeTrue();

        sidebar.moveGroup('id1', 0);

        expect(
            sidebar.getData()[0].id == 'id1' &&
            sidebar.getData()[1].id == 'id2' &&
            sidebar.getData()[2].id == 'id3' &&
            sidebar.getData()[3].id == 'id4'
        ).toBeTrue();

        sidebar.moveGroup('id1', 3);

        expect(
            sidebar.getData()[0].id == 'id2' &&
            sidebar.getData()[1].id == 'id3' &&
            sidebar.getData()[2].id == 'id4' &&
            sidebar.getData()[3].id == 'id1'
        ).toBeTrue();

        sidebar.moveGroup('id2', 2);

        expect(
            sidebar.getData()[0].id == 'id3' &&
            sidebar.getData()[1].id == 'id4' &&
            sidebar.getData()[2].id == 'id2' &&
            sidebar.getData()[3].id == 'id1'
        ).toBeTrue();

        done();
    });

    it('should push Resource', ()=>{

        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "Id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        expect(
            sidebar.getData()[0].resources.length == 1 &&
            sidebar.getData()[1].resources.length == 1 &&
            sidebar.getData()[0].resources[0].id == 'r1' &&
            sidebar.getData()[1].resources[0].id == 'r2' &&
            sidebar.getUngroupedData().length == 0
            ).toBeTrue();
    });

    it('should work pushResourceBefore', ()=>{

        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResourceBefore('g1', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: -1,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        expect(
            sidebar.getData()[0].resources.length == 3 &&
            sidebar.getData()[0].resources[0].id == 'r3' &&
            sidebar.getData()[0].resources[1].id == 'r1' &&
            sidebar.getData()[0].resources[2].id == 'r2'
            ).toBeTrue();
    });

    it('should push Resource into ungrouped', ()=>{

        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        expect(
            sidebar.getData()[0].resources.length == 1 &&
            sidebar.getData()[1].resources.length == 0  &&
            sidebar.getData()[0].resources[0].id == 'r1' &&
            sidebar.getUngroupedData().length == 1 && 
            sidebar.getUngroupedData()[0].id == 'r2'
            ).toBeTrue();
    });

    it('should edit resource name', ()=>{
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.editResourceName('r2', 'changed');

        expect(
            sidebar.getData()[0].resources[0].name == "r1" &&
            sidebar.getData()[1].resources[0].name == "changed" &&
            sidebar.getData()[1].resources[1].name == "r3" &&
            sidebar.getData()[0].name == "g1" &&
            sidebar.getData()[1].name == "g2"
        ).toBeTrue();
    });

    it('should remove resource', ()=>{
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 175,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.removeResource('r4');

        expect(
            sidebar.getData()[0].resources.length == 1 &&
            sidebar.getData()[1].resources.length == 2 &&
            sidebar.getData()[1].resources[0].id == 'r2' &&
            sidebar.getData()[1].resources[1].id == 'r3'
        ).toBeTrue();
    });

    it('should put resources into ungrouped after group remove', ()=>{
        
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 175,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.removeGroup('g2');

        expect(
            sidebar.getData().length == 1 && 
            sidebar.getData()[0].id == 'g1' &&
            sidebar.getUngroupedData().length == 3 &&
            sidebar.getUngroupedData()[0].id == 'r2' &&
            sidebar.getUngroupedData()[1].id == 'r4' &&
            sidebar.getUngroupedData()[2].id == 'r3'
            ).toBeTrue();

    });

    it('should work private push', ()=>{
        
        let arr = [
            {id: 1, ordering: 10},
            {id: 2, ordering: 20},
            {id: 3, ordering: 30},
            {id: 4, ordering: 40},
            {id: 5, ordering: 50},
        ];

        let first = {id: 6, ordering: 1};
        let middle = {id: 7, ordering: 35};
        let last = {id: 8, ordering: 60};

        sidebar['push'](first, arr);
        sidebar['push'](middle, arr);
        sidebar['push'](last, arr);

        expect(
            arr[0].id == 6 &&
            arr[4].id == 7 &&
            arr[7].id == 8
            ).toBeTrue();
    });

    it('should work private editOrdering', ()=>{
        let arr = [
            {id: 1, ordering: 10},
            {id: 2, ordering: 20},
            {id: 3, ordering: 30},
            {id: 4, ordering: 40},
            {id: 5, ordering: 50},
        ];

        let el = {id: 6, ordering: 1};

        sidebar['editOrdering'](arr[0], arr, 45);
        sidebar['editOrdering'](el, arr, 35);

        expect(
            arr[0].id == 2 && arr[0].ordering == 20 &&
            arr[1].id == 3 && arr[1].ordering == 30 &&
            arr[2].id == 6 && arr[2].ordering == 35 &&
            arr[3].id == 4 && arr[3].ordering == 40 &&
            arr[4].id == 1 && arr[4].ordering == 45 &&
            arr[5].id == 5 && arr[5].ordering == 50 
        ).toBeTrue();
    });

    it('should work resource edit ordering in groups=>groups', ()=>{


        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 175,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.editResourceOrdering('r4', 'g2', 50);
        sidebar.editResourceOrdering('r3', 'g1', 110);

        expect(
            sidebar.getData()[0].resources.length == 2 &&
            sidebar.getData()[0].resources.length == 2 &&
            sidebar.getData()[0].resources[0].id == 'r1' &&
            sidebar.getData()[0].resources[1].id == 'r3' && sidebar.getData()[0].resources[1].ordering == 110 &&
            sidebar.getData()[1].resources[1].id == 'r2' &&
            sidebar.getData()[1].resources[0].id == 'r4' && sidebar.getData()[1].resources[0].ordering == 50
        ).toBeTrue();
    });

    it('should work resource edit ordering groups=>ungroup', ()=>{


        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.editResourceOrdering('r1', null, 120);

        expect(
            sidebar.getData()[0].resources.length == 0 && 
            sidebar.getUngroupedData().length == 2 &&
            sidebar.getUngroupedData()[0].id == 'r1' &&
            sidebar.getUngroupedData()[0].ordering == 120
        ).toBeTrue();

        
    });

    it('should work resource edit ordering ungroup=>ungroup', ()=>{


        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 150,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 300,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.editResourceOrdering('r4', null, 100);

        expect(
            sidebar.getData()[0].resources.length == 1 &&
            sidebar.getData()[1].resources.length == 1 &&
            sidebar.getUngroupedData().length == 2 &&
            sidebar.getUngroupedData()[0].id == 'r4' && sidebar.getUngroupedData()[0].ordering == 100 &&
            sidebar.getUngroupedData()[1].id == 'r3'
        ).toBeTrue();

        
    });

    it('should moveResource groupX=>groupX, ungroup=>ungroup', ()=>{
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });


        sidebar.pushResource(null, {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r5',
            name: 'r5',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 300,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.moveResource('r2', 'g2', 1);
        sidebar.moveResource('r4', null, 1);

        expect(
            sidebar.getData()[0].resources.length == 1 &&
            sidebar.getData()[1].resources.length == 2 &&
            sidebar.getUngroupedData().length == 2 &&
            sidebar.getData()[1].resources[0].id == 'r3' &&
            sidebar.getData()[1].resources[1].id == 'r2' &&
            sidebar.getUngroupedData()[0].id == 'r5' &&
            sidebar.getUngroupedData()[1].id == 'r4'
        ).toBeTrue();
    });

    it('should moveResource groupX=>groupY', ()=>{
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });


        sidebar.pushResource(null, {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r5',
            name: 'r5',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 300,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.moveResource('r1', 'g2', 1);

        console.log(sidebar)
        expect(
            sidebar.getData()[0].resources.length == 0 &&
            sidebar.getData()[1].resources.length == 3 &&
            sidebar.getUngroupedData().length == 2 &&
            sidebar.getData()[1].resources[0].id == 'r2' &&
            sidebar.getData()[1].resources[1].id == 'r1' &&
            sidebar.getData()[1].resources[2].id == 'r3'

        ).toBeTrue();
    });

    it('should moveResource group=>ungroup ungroup=>group', ()=>{
        sidebar.pushGroup({
            id: 'g1',
            name: 'g1',
            closed: false,
            ordering: 100,
            resources: [],
            error: false
        });
        sidebar.pushGroup({
            id: 'g2',
            name: 'g2',
            closed: false,
            ordering: 150,
            resources: [],
            error: false
        });

        sidebar.pushResource('g1', {
            id: 'r1',
            name: 'r1',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r2',
            name: 'r2',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 100,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource('g2', {
            id: 'r3',
            name: 'r3',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });


        sidebar.pushResource(null, {
            id: 'r4',
            name: 'r4',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 200,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.pushResource(null, {
            id: 'r5',
            name: 'r5',
            owner: '',
            news: false,
            topMessageId: "id",
            lastSeenMessageId: "id",
            ordering: 300,
            type: ResourceType.ROOM,
            avatar: null,
            nanoSessions: null,
            error: false
        });

        sidebar.moveResource('r5', 'g1', 1);
        sidebar.moveResource('r3', null, 1);

        
        expect(
            sidebar.getData()[0].resources.length == 2 &&
            sidebar.getData()[1].resources.length == 1 &&
            sidebar.getUngroupedData().length == 2 &&
            sidebar.getData()[0].resources[0].id == 'r1' &&
            sidebar.getData()[0].resources[1].id == 'r5' &&
            sidebar.getUngroupedData()[0].id == 'r4' &&
            sidebar.getUngroupedData()[1].id == 'r3'

        ).toBeTrue();
    })

});