import importlib
from data_handler import VARS 
from data_handler import MODELS
code = importlib.import_module('tabs.forecast')

def test_layout_view():
    assert  "Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')" in str(code.layout_view())

def test_time_series():
    assert  "Div(children=[Spinner(children=[Modal(children=[], id='ts-modal', centered=True, is_open=False, size='xl')], id='loading-ts-modal', fullscreen=True, fullscreen_style={'opacity': '0.5', 'zIndex': '200000'}, show_initially=False)], id='open-timeseries')" in str(code.time_series())

def test_layout_layers():
    assert  "Div([Span(DropdownMenu(children=[DropdownMenuItem(children='AIRPORTS', id='airports')], id='map-layers-dropdown', direction='up', label='LAYERS'))])" in str(code.layout_layers())

def test_time_slider():
    assert  "Div(children=[Span(children=DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='model-date-picker'), className='timesliderline'), Span(children=[Button(id='btn-play', className='fa fa-play text-center', n_clicks=0, title='Play')], className='timesliderline anim-buttons'), Span(children=Slider(min=0, max=72, step=3, marks={0: '0', 3: '3', 6: '6', 9: '9', 12: '12', 15: '15', 18: '18', 21: '21', 24: '24', 27: '27', 30: '30', 33: '33', 36: '36', 39: '39', 42: '42', 45: '45', 48: '48', 51: '51', 54: '54', 57: '57', 60: '60', 63: '63', 66: '66', 69: '69', 72: '72'}, value=0, id='slider-graph'), className='timesliderline')], className='timeslider')" in str(code.time_slider('20120120', '20220808'))

def test_prob_time_slider():
    assert  "Div(children=[Span(children=DatePickerSingle(date='20220809', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 9, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 9, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='prob-date-picker'), className='timesliderline'), Span(children=Slider(min=0, max=1, step=1, marks={0: 'Today', 1: 'Tomorrow'}, value=0, id='prob-slider-graph'), className='timesliderline')], className='timeslider')" in str(code.prob_time_slider('20120120', '20220809'))

def test_was_time_slider():
    assert  "Div(children=[Span(children=DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='was-date-picker'), className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: 'Today', 2: 'Tomorrow'}, value=1, id='was-slider-graph'), className='timesliderline')], className='timeslider')" in str(code.was_time_slider('20120120', '20220808'))

def test_models_children():
    assert  "[Div(id={'tag': 'tab-name', 'index': 'models'}), Alert(children='To explore the forecast, please select a variable and click on APPLY.', id='alert-forecast', color='primary', duration=6000, fade=True, is_open=True, style={'overflow': 'auto', 'marginBottom': 0}), Div(children=[Container(children=[], id='graph-collection', fluid=True), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer')], id='div-collection'), Div([Store(id='model-clicked-coords'), Store(id='current-popups-stored')]), Div(Interval(id='slider-interval', disabled=True, interval=1000, n_intervals=0))" in str(code.models_children('20120120', '20220808'))

def test_prob_children():
    assert  "[Div(id={'tag': 'tab-name', 'index': 'prob'}), Div(id='prob-graph', className='graph-with-slider'), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='prob-date-picker'), className='timesliderline'), Span(children=Slider(min=0, max=1, step=1, marks={0: 'Today', 1: 'Tomorrow'}, value=0, id='prob-slider-graph'), className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)]" in str(code.prob_children('20120120', '20220808'))

def test_was_children():
    assert "id='was-graph', className='graph-with-slider')), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='was-date-picker'), className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: 'Today', 2: 'Tomorrow'}, value=1, id='was-slider-graph'), className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)]" in str(code.was_children('20120120', '20220808'))

def test_tab_forecast():
    #TEST MODELS
    assert  " '57', 60: '60', 63: '63', 66: '66', 69: '69', 72: '72'}, value=0, id='slider-graph'), className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div'), Div(children=[Spinner(children=[Modal(children=[], id='ts-modal', centered=True, is_open=False, size='xl')], id='loading-ts-modal', fullscreen=True, fullscreen_style={'opacity': '0.5', 'zIndex': '200000'}, show_initially=False)], id='open-timeseries')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('models', '20120120', '20220808'))

    #TEST WAS
    assert  "id='was-graph', className='graph-with-slider')), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='was-date-picker'), className='timesliderline'), Span(children=Slider(min=1, max=2, step=1, marks={1: 'Today', 2: 'Tomorrow'}, value=1, id='was-slider-graph'), className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('was', '20120120', '20220808'))

    #TEST PROB
    assert  "Tab(children=[Div(id={'tag': 'tab-name', 'index': 'prob'}), Div(id='prob-graph', className='graph-with-slider'), Div(children=[Span(children=P('Dust data ©2023 WMO Barcelona Dust Regional Center.'), id='forecast-disclaimer')], className='disclaimer'), NavbarSimple(children=[Div(children=[Div(children=[Span(children=DatePickerSingle(date='20220808', min_date_allowed=datetime.datetime(2012, 1, 20, 0, 0), max_date_allowed=datetime.datetime(2022, 8, 8, 0, 0), placeholder='DD MON YYYY', initial_visible_month=datetime.datetime(2022, 8, 8, 0, 0), clearable=True, reopen_calendar_on_clear=True, display_format='DD MMM YYYY', id='prob-date-picker'), className='timesliderline'), Span(children=Slider(min=0, max=1, step=1, marks={0: 'Today', 1: 'Tomorrow'}, value=0, id='prob-slider-graph'), className='timesliderline')], className='timeslider'), Div(children=[Span(DropdownMenu(children=[DropdownMenuItem(children='Light', id={'tag': 'view-style', 'index': 'carto-positron'}, active=True), DropdownMenuItem(children='Open street map', id={'tag': 'view-style', 'index': 'open-street-map'}, active=False), DropdownMenuItem(children='Terrain', id={'tag': 'view-style', 'index': 'stamen-terrain'}, active=False), DropdownMenuItem(children='ESRI', id={'tag': 'view-style', 'index': 'esri-world'}, active=False)], id='map-view-dropdown', direction='up', in_navbar=True, label='VIEW'))], id='map-view-dropdown-div')], id='layout-dropdown', className='layout-dropdown')], className='fixed-bottom navbar-timebar', dark=True, expand='lg', fixed='bottom', fluid=True)], id='forecast-tab', className='horizontal-menu', label='Forecast', value='forecast-tab')" in str(code.tab_forecast('prob', '20120120', '20220808'))

def test_expand_dropdown():
    assert  "{'models': True, 'prob': False, 'was': False}" in str(code.expand_dropdown('models'))
    assert  "{'models': False, 'prob': True, 'was': False}" in str(code.expand_dropdown('prob'))
    assert  "{'models': False, 'prob': False, 'was': True}" in str(code.expand_dropdown('was'))

def test_sidebar_forecast():
    #TEST MODELS
    assert  "[Div(children=[Label('Variable'), Dropdown(options=[{'label': 'AOD', 'value': 'OD550_DUST'}, {'label': 'Concentration', 'value': 'SCONC_DUST'}, {'label': 'Dry deposition', 'value': 'DUST_DEPD'}, {'label': 'Wet deposition', 'value': 'DUST_DEPW'}, {'label': 'Load', 'value': 'DUST_LOAD'}, {'label': 'Extinction', 'value': 'DUST_EXT_SFC'}], value=['OD550_DUST'], clearable=False, searchable=False, optionHeight=50, maxHeight=400, id='variable-dropdown-forecast')], className='sidebar-first-item'), Div(children=[Card([CardHeader(H2(Button(children=['Models', Span(children=I(className='fa fa-solid fa-angle-up'), id='caret1', className='caret-span')], id='group-1-toggle', className='dropdown', color='link'))), Collapse(children=[CardBody([Checklist(id='model-dropdown', className='sidebar-dropdown', options=[{'label': 'MULTI-MODEL', 'value': 'median'}, {'label': 'MONARCH', 'value': 'monarch'}, {'label': 'CAMS-IFS', 'value': 'cams'}, {'label': 'DREAM8-CAMS', 'value': 'dream8-macc'}, {'label': 'NASA-GEOS', 'value': 'nasa-geos'}, {'label': 'MetOffice-UM', 'value': 'metoffice'}, {'label': 'NCEP-GEFS', 'value': 'ncep-gefs'}, {'label': 'EMA-RegCM4', 'value': 'ema-regcm4'}" in str(code.sidebar_forecast(VARS, ['OD550_DUST'], MODELS, ['median'], window='models', country='burkinafaso'))

    #TEST PROB
    assert  "[Div(children=[Label('Variable'), Dropdown(options=[{'label': 'AOD', 'value': 'OD550_DUST'}, {'label': 'Concentration', 'value': 'SCONC_DUST'}, {'label': 'Dry deposition', 'value': 'DUST_DEPD'}, {'label': 'Wet deposition', 'value': 'DUST_DEPW'}, {'label': 'Load', 'value': 'DUST_LOAD'}, {'label': 'Extinction', 'value': 'DUST_EXT_SFC'}], value=['OD550_DUST'], clearable=False, searchable=False, optionHeight=50, maxHeight=400, id='variable-dropdown-forecast')], className='sidebar-first-item'), Div(children=[Card([CardHeader(H2(Button(children=['Models', Span(children=I(className='fa fa-solid fa-angle-up'), id='caret1', className='caret-span')], id='group-1-toggle', className='dropdown', color='link'))), Collapse(children=[CardBody([Checklist(id='model-dropdown', className='sidebar-dropdown', options=[{'label': 'MULTI-MODEL', 'value': 'median'}, {'label': 'MONARCH', 'value': 'monarch'}, {'label': 'CAMS-IFS', 'value': 'cams'}, {'label': 'DREAM8-CAMS', 'value': 'dream8-macc'}, {'label': 'NASA-GEOS', 'value': 'nasa-geos'}, {'label': 'MetOffice-UM', " in str(code.sidebar_forecast(VARS, ['OD550_DUST'], MODELS, ['median'], window='prob', country='burkinafaso'))

    #TEST WAS
    assert  "[Div(children=[Label('Variable'), Dropdown(options=[{'label': 'AOD', 'value': 'OD550_DUST'}, {'label': 'Concentration', 'value': 'SCONC_DUST'}, {'label': 'Dry deposition', 'value': 'DUST_DEPD'}, {'label': 'Wet deposition', 'value': 'DUST_DEPW'}, {'label': 'Load', 'value': 'DUST_LOAD'}, {'label': 'Extinction', 'value': 'DUST_EXT_SFC'}], value=['OD550_DUST'], clearable=False, searchable=False, optionHeight=50, maxHeight=400, id='variable-dropdown-forecast')], className='sidebar-first-item'), Div(children=[Card([CardHeader(H2(Button(children=['Models', Span(children=I(className='fa fa-solid fa-angle-up'), id='caret1', className='caret-span')], id='group-1-toggle', className='dropdown', color='link'))), Collapse(children=[CardBody([Checklist(id='model-dropdown', className='sidebar-dropdown', options=[{'label': 'MULTI-MODEL', 'value': 'median'}, {'label': 'MONARCH', 'value': 'monarch'}, {'label': 'CAMS-IFS', 'value': 'cams'}, {'label': 'DREAM8-CAMS', 'value': 'dream8-macc'}, {'label': 'NASA-GEOS', 'value': 'nasa-geos'}, {'label': 'MetOffice-UM', 'value': 'metoffice'}, {'label': 'NCEP-GEFS', 'value': 'ncep-gefs'}, {'label': 'EMA-RegCM4', 'value': 'ema-regcm4'}, {'label': 'SILAM'," in str(code.sidebar_forecast(VARS, ['OD550_DUST'], MODELS, ['median'], window='was', country='chad'))
