import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { AccordionModule } from 'ngx-bootstrap/accordion';

import { SampComponent } from './samp.component';

describe('[Instance][Search][Component][Result] SampComponent', () => {
    let component: SampComponent;
    let fixture: ComponentFixture<SampComponent>;

    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [SampComponent],
            imports: [
                AccordionModule.forRoot(),
                BrowserAnimationsModule
            ]
        });
        fixture = TestBed.createComponent(SampComponent);
        component = fixture.componentInstance;
    });

    it('should create the component', () => {
        expect(component).toBeTruthy();
    });

    it('#isSampActivated() should return if SAMP has to be enabled or not', () => {
        component.datasetList = [
            {
                name: 'myDataset',
                table_ref: 'table',
                label: 'my dataset',
                description: 'This is my dataset',
                display: 1,
                data_path: '/path',
                survey_name: 'mySurvey',
                id_dataset_family: 1,
                public: true,
                full_data_path: '/data/path',
                config: {
                    images: ['image1'],
                    survey: {
                        survey_enabled: true,
                        survey_label: 'More about this survey'
                    },
                    cone_search: {
                        cone_search_enabled: true,
                        cone_search_opened: true,
                        cone_search_column_ra: 1,
                        cone_search_column_dec: 2,
                        cone_search_plot_enabled: true,
                        cone_search_sdss_enabled: true,
                        cone_search_sdss_display: 1,
                        cone_search_background: [{ id: 1, enabled: true, display: 1 }]
                    },
                    download: {
                        download_enabled: true,
                        download_opened: true,
                        download_csv: true,
                        download_ascii: true,
                        download_vo: true,
                        download_archive: true
                    },
                    summary: {
                        summary_enabled: true,
                        summary_opened: true
                    },
                    server_link: {
                        server_link_enabled: false,
                        server_link_opened: true
                    },
                    samp: {
                        samp_enabled: false,
                        samp_opened: false
                    },
                    datatable: {
                        datatable_enabled: true,
                        datatable_opened: true,
                        datatable_selectable_rows: true
                    }
                }
            },
            {
                name: 'anotherDataset',
                table_ref: 'table',
                label: 'another dataset',
                description: 'This is another dataset',
                display: 1,
                data_path: '/path',
                survey_name: 'mySurvey',
                id_dataset_family: 1,
                public: true,
                full_data_path: '/data/path',
                config: {
                    images: ['image1'],
                    survey: {
                        survey_enabled: true,
                        survey_label: 'More about this survey'
                    },
                    cone_search: {
                        cone_search_enabled: true,
                        cone_search_opened: true,
                        cone_search_column_ra: 1,
                        cone_search_column_dec: 2,
                        cone_search_plot_enabled: true,
                        cone_search_sdss_enabled: true,
                        cone_search_sdss_display: 1,
                        cone_search_background: [{ id: 1, enabled: true, display: 1 }]
                    },
                    download: {
                        download_enabled: true,
                        download_opened: true,
                        download_csv: true,
                        download_ascii: true,
                        download_vo: true,
                        download_archive: true
                    },
                    summary: {
                        summary_enabled: true,
                        summary_opened: true
                    },
                    server_link: {
                        server_link_enabled: true,
                        server_link_opened: true
                    },
                    samp: {
                        samp_enabled: true,
                        samp_opened: true
                    },
                    datatable: {
                        datatable_enabled: true,
                        datatable_opened: true,
                        datatable_selectable_rows: true
                    }
                }
            }
        ];
        component.datasetSelected = 'myDataset';
        expect(component.isSampActivated()).toBeFalsy();
        component.datasetSelected = 'anotherDataset';
        expect(component.isSampActivated()).toBeTruthy();
    });

    it('#isSampOpened() should return if URL tab has to be opened or not', () => {
        component.datasetList = [
            {
                name: 'myDataset',
                table_ref: 'table',
                label: 'my dataset',
                description: 'This is my dataset',
                display: 1,
                data_path: '/path',
                survey_name: 'mySurvey',
                id_dataset_family: 1,
                public: true,
                full_data_path: '/data/path',
                config: {
                    images: ['image1'],
                    survey: {
                        survey_enabled: true,
                        survey_label: 'More about this survey'
                    },
                    cone_search: {
                        cone_search_enabled: true,
                        cone_search_opened: true,
                        cone_search_column_ra: 1,
                        cone_search_column_dec: 2,
                        cone_search_plot_enabled: true,
                        cone_search_sdss_enabled: true,
                        cone_search_sdss_display: 1,
                        cone_search_background: [{ id: 1, enabled: true, display: 1 }]
                    },
                    download: {
                        download_enabled: true,
                        download_opened: true,
                        download_csv: true,
                        download_ascii: true,
                        download_vo: true,
                        download_archive: true
                    },
                    summary: {
                        summary_enabled: true,
                        summary_opened: true
                    },
                    server_link: {
                        server_link_enabled: false,
                        server_link_opened: false
                    },
                    samp: {
                        samp_enabled: false,
                        samp_opened: false
                    },
                    datatable: {
                        datatable_enabled: true,
                        datatable_opened: true,
                        datatable_selectable_rows: true
                    }
                }
            },
            {
                name: 'anotherDataset',
                table_ref: 'table',
                label: 'another dataset',
                description: 'This is another dataset',
                display: 1,
                data_path: '/path',
                survey_name: 'mySurvey',
                id_dataset_family: 1,
                public: true,
                full_data_path: '/data/path',
                config: {
                    images: ['image1'],
                    survey: {
                        survey_enabled: true,
                        survey_label: 'More about this survey'
                    },
                    cone_search: {
                        cone_search_enabled: true,
                        cone_search_opened: true,
                        cone_search_column_ra: 1,
                        cone_search_column_dec: 2,
                        cone_search_plot_enabled: true,
                        cone_search_sdss_enabled: true,
                        cone_search_sdss_display: 1,
                        cone_search_background: [{ id: 1, enabled: true, display: 1 }]
                    },
                    download: {
                        download_enabled: true,
                        download_opened: true,
                        download_csv: true,
                        download_ascii: true,
                        download_vo: true,
                        download_archive: true
                    },
                    summary: {
                        summary_enabled: true,
                        summary_opened: true
                    },
                    server_link: {
                        server_link_enabled: true,
                        server_link_opened: true
                    },
                    samp: {
                        samp_enabled: true,
                        samp_opened: true
                    },
                    datatable: {
                        datatable_enabled: true,
                        datatable_opened: true,
                        datatable_selectable_rows: true
                    }
                }
            }
        ];
        component.datasetSelected = 'myDataset';
        expect(component.isSampOpened()).toBeFalsy();
        component.datasetSelected = 'anotherDataset';
        expect(component.isSampOpened()).toBeTruthy();
    });

    it('#getColor() should return color button depending on SAMP registered or not', () => {
        expect(component.getColor()).toEqual('red');
        component.sampRegistered = true;
        expect(component.getColor()).toEqual('green');
    });
});