# -*- 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 preferences dialog.
"""

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

# Local imports
from anaconda_navigator.utils.fixtures import tmpconfig
from anaconda_navigator.widgets.dialogs.preferences import PreferencesDialog


# --- Fixtures
# -----------------------------------------------------------------------------
@pytest.fixture
def botpreferences(qtbot, tmpconfig):
    widget = PreferencesDialog(config=tmpconfig)
    widget.show()
    qtbot.addWidget(widget)
    return qtbot, widget


# --- Tests
# -----------------------------------------------------------------------------
class TestPreferencesDialog:
    def test_simple(self, botpreferences):
        qtbot, widget = botpreferences
        assert widget.widgets
        assert widget.button_ok.isEnabled() == False  # no change yet

    def test_options(self, botpreferences):
        qtbot, widget = botpreferences
        widget.set_option('hide_quit_dialog', True)
        assert widget.get_option('hide_quit_dialog') is True
        qtbot.mouseClick(widget.button_reset, Qt.LeftButton)
        assert widget.get_option('hide_quit_dialog') is False

    def test_bad_api(self, botpreferences):
        qtbot, widget = botpreferences
        qtbot.keyClicks(widget.widgets[0], '*&**&')
        qtbot.mouseClick(widget.button_ok, Qt.LeftButton)
        assert widget.widgets[0].label_information.toolTip()
        assert widget.button_ok.isEnabled() is False
