# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2016 Continuum Analytics, Inc.
#
# May be copied and distributed freely only as part of an Anaconda or
# Miniconda installation.
# -----------------------------------------------------------------------------
"""
Tests for quit-like dialogs.
"""

# Third party imports
from qtpy.QtCore import Qt
from pytestqt import qtbot  # analysis:ignore
import pytest

# Local imports
from anaconda_navigator.widgets.main_window import MainWindow
from anaconda_navigator.utils.fixtures import tmpconfig

# --- Fixtures
# -----------------------------------------------------------------------------
@pytest.fixture
def botwin(qtbot, tmpconfig):
    tmpconfig.set('main', 'hide_quit_dialog', True)
    widget = MainWindow(config=tmpconfig)
    widget.show()
    qtbot.addWidget(widget)
    return qtbot, widget, tmpconfig


class TestMainWindow:

    def test_versions(self, botwin):
        qtbot, widget, config = botwin
        packages = {'anaconda-navigator': {'versions': ['1.0.0', '1.1.1']}}
        widget.check_for_updates(packages, '1.1.1')
        assert not widget.button_update_available.isVisible()
        widget.check_for_updates(packages, '1.1.1dev')
        assert widget.button_update_available.isVisible()
        widget.check_for_updates(packages, '1.2')
        assert not widget.button_update_available.isVisible()
        widget.check_for_updates(packages, '1.1')
        assert widget.button_update_available.isVisible()
