#!/usr/bin/env python3
#
# Copyright (c) 2024 Stormux
# Copyright (c) 2010-2012 The Orca Team
# Copyright (c) 2012 Igalia, S.L.
# Copyright (c) 2005-2010 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
# Boston MA  02110-1301 USA.
#
# Fork of Orca Screen Reader (GNOME)
# Original source: https://gitlab.gnome.org/GNOME/orca

"""Test of tree table output."""

from macaroon.playback import *
import utils

sequence = MacroSequence()

sequence.append(KeyComboAction("End"))
sequence.append(KeyComboAction("<Shift>Right"))
sequence.append(KeyComboAction("Down"))
sequence.append(KeyComboAction("Down"))
sequence.append(KeyComboAction("Down"))
sequence.append(KeyComboAction("Down"))
sequence.append(KeyComboAction("Return"))
sequence.append(PauseAction(3000))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "1. January cell focus",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January expanded < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January expanded < > Alex < > Ha', cursor=1",
     "SPEECH OUTPUT: 'January expanded 3 items.'",
     "SPEECH OUTPUT: 'Alex'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Havoc'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Tim'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Owen'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Dave'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'tree level 1'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "2. January cell basic Where Am I",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January expanded < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January expanded < > Alex < > Ha', cursor=1",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Holiday.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'January.'",
     "SPEECH OUTPUT: 'column 1 of 6'",
     "SPEECH OUTPUT: 'row 1 of 53.'",
     "SPEECH OUTPUT: 'expanded.'",
     "SPEECH OUTPUT: 'tree level 1.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "3. January cell detailed Where Am I",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January expanded < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January expanded < > Alex < > Ha', cursor=1",
     "BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January expanded < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January expanded < > Alex < > Ha', cursor=1",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Holiday.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'January.'",
     "SPEECH OUTPUT: 'column 1 of 6'",
     "SPEECH OUTPUT: 'row 1 of 53.'",
     "SPEECH OUTPUT: 'expanded.'",
     "SPEECH OUTPUT: 'tree level 1.'",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Holiday.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'January.'",
     "SPEECH OUTPUT: 'column 1 of 6'",
     "SPEECH OUTPUT: 'row 1 of 53.'",
     "SPEECH OUTPUT: 'January expanded 3 items.'",
     "SPEECH OUTPUT: 'Alex'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Havoc'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Tim'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Owen'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Dave'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'expanded.'",
     "SPEECH OUTPUT: 'tree level 1.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>Left"))
sequence.append(utils.AssertPresentationAction(
    "4. January cell collapsed",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January collapsed < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January collapsed < > Alex < > H', cursor=1",
     "SPEECH OUTPUT: 'collapsed.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "5. January cell collapsed basic Where Am I",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January collapsed < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January collapsed < > Alex < > H', cursor=1",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Holiday.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'January.'",
     "SPEECH OUTPUT: 'column 1 of 6'",
     "SPEECH OUTPUT: 'row 1 of 50.'",
     "SPEECH OUTPUT: 'collapsed.'",
     "SPEECH OUTPUT: 'tree level 1.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "6. January cell collapsed detailed Where Am I",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January collapsed < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January collapsed < > Alex < > H', cursor=1",
     "BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January collapsed < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January collapsed < > Alex < > H', cursor=1",
"SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Holiday.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'January.'",
     "SPEECH OUTPUT: 'column 1 of 6'",
     "SPEECH OUTPUT: 'row 1 of 50.'",
     "SPEECH OUTPUT: 'collapsed.'",
     "SPEECH OUTPUT: 'tree level 1.'",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Holiday.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'January.'",
     "SPEECH OUTPUT: 'column 1 of 6'",
     "SPEECH OUTPUT: 'row 1 of 50.'",
     "SPEECH OUTPUT: 'January collapsed.'",
     "SPEECH OUTPUT: 'Alex'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Havoc'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Tim'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Owen'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'Dave'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'collapsed.'",
     "SPEECH OUTPUT: 'tree level 1.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>Right"))
sequence.append(utils.AssertPresentationAction(
    "7. January cell expanded",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header January expanded < > Alex < > Havoc < > Tim < > Owen < > Dave TREE LEVEL 1'",
     "     VISIBLE:  'January expanded < > Alex < > Ha', cursor=1",
     "SPEECH OUTPUT: 'expanded.'",
     "SPEECH OUTPUT: '3 items.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "8. New Year's Day cell",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Holiday column header New Years Day <x> Alex <x> Havoc <x> Tim <x> Owen < > Dave TREE LEVEL 2'",
     "     VISIBLE:  'New Years Day <x> Alex <x> Havoc', cursor=1",
     "SPEECH OUTPUT: 'New Years Day.'",
     "SPEECH OUTPUT: 'Alex'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Havoc'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Tim'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Owen'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Dave'",
     "SPEECH OUTPUT: 'check box not checked.'",
     "SPEECH OUTPUT: 'tree level 2'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Right"))
sequence.append(utils.AssertPresentationAction(
    "9. Alex checkbox cell",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Alex column header New Years Day <x> Alex <x> Havoc <x> Tim <x> Owen < > Dave'",
     "     VISIBLE:  '<x> Alex <x> Havoc <x> Tim <x> O', cursor=1",
     "SPEECH OUTPUT: 'Alex column header check box checked.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "10. Alex checkbox cell basic Where Am I",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Alex column header New Years Day <x> Alex <x> Havoc <x> Tim <x> Owen < > Dave'",
     "     VISIBLE:  '<x> Alex <x> Havoc <x> Tim <x> O', cursor=1",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Alex.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'column 2 of 6'",
     "SPEECH OUTPUT: 'row 2 of 53.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "11. Alex checkbox cell detailed Where Am I",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Alex column header New Years Day <x> Alex <x> Havoc <x> Tim <x> Owen < > Dave'",
     "     VISIBLE:  '<x> Alex <x> Havoc <x> Tim <x> O', cursor=1",
     "BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Alex column header New Years Day <x> Alex <x> Havoc <x> Tim <x> Owen < > Dave'",
     "     VISIBLE:  '<x> Alex <x> Havoc <x> Tim <x> O', cursor=1",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Alex.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'column 2 of 6'",
     "SPEECH OUTPUT: 'row 2 of 53.'",
     "SPEECH OUTPUT: 'tree table.'",
     "SPEECH OUTPUT: 'Alex.'",
     "SPEECH OUTPUT: 'table cell.'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'column 2 of 6'",
     "SPEECH OUTPUT: 'row 2 of 53.'",
     "SPEECH OUTPUT: 'New Years Day.'",
     "SPEECH OUTPUT: 'Alex'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Havoc'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Tim'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Owen'",
     "SPEECH OUTPUT: 'check box checked.'",
     "SPEECH OUTPUT: 'Dave'",
     "SPEECH OUTPUT: 'check box not checked.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(TypeAction(" "))
sequence.append(utils.AssertPresentationAction(
    "12. Alex checkbox cell unchecked",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Alex column header New Years Day < > Alex <x> Havoc <x> Tim <x> Owen < > Dave'",
     "     VISIBLE:  '< > Alex <x> Havoc <x> Tim <x> O', cursor=1",
     "SPEECH OUTPUT: 'not checked.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(TypeAction(" "))
sequence.append(utils.AssertPresentationAction(
    "13. Alex checkbox cell checked",
    ["BRAILLE LINE:  'gtk3-demo application Tree Store frame tree table Alex column header New Years Day <x> Alex <x> Havoc <x> Tim <x> Owen < > Dave'",
     "     VISIBLE:  '<x> Alex <x> Havoc <x> Tim <x> O', cursor=1",
     "SPEECH OUTPUT: 'checked.'"]))

sequence.append(KeyComboAction("<Alt>F4"))

sequence.append(utils.AssertionSummaryAction())
sequence.start()