# SPDX-FileCopyrightText: (c) TagStudio Contributors
# SPDX-License-Identifier: GPL-3.0-only


from pytestqt.qtbot import QtBot

from tagstudio.core.library.alchemy.library import Library
from tagstudio.core.library.alchemy.models import Tag
from tagstudio.qt.mixed.build_tag import BuildTagPanel
from tagstudio.qt.qt_driver import QtDriver


def test_tag_panel(qtbot: QtBot, library: Library):
    panel = BuildTagPanel(library)

    qtbot.addWidget(panel)


def test_add_tag_callback(qt_driver: QtDriver):
    # Given
    assert len(qt_driver.lib.tags) == 6
    qt_driver.add_tag_action_callback()

    # When
    build_tag_panel = qt_driver.modal.layout().content_widget
    assert isinstance(build_tag_panel, BuildTagPanel)
    build_tag_panel.name_field.setText("xxx")
    # qt_driver.modal.widget.color_field.setCurrentIndex(1)
    qt_driver.modal.saved.emit()

    # Then
    tags: list[Tag] = qt_driver.lib.tags
    assert len(tags) == 7
    assert "xxx" in {tag.name for tag in tags}
