#!/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 Dojo tree presentation."""

from macaroon.playback import *
import utils

sequence = MacroSequence()

#sequence.append(WaitForDocLoad())
sequence.append(PauseAction(8000))
sequence.append(KeyComboAction("Tab"))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Tab"))
sequence.append(utils.AssertPresentationAction(
    "1. Tab to continents",
    ["BRAILLE LINE:  'before:  $l'",
     "     VISIBLE:  'before:  $l', cursor=9",
     "BRAILLE LINE:  'Continents expanded'",
     "     VISIBLE:  'Continents expanded', cursor=1",
     "SPEECH OUTPUT: 'Continents.'",
     "SPEECH OUTPUT: 'expanded.'",
     "SPEECH OUTPUT: 'tree level 1'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "2. Down arrow to Africa",
    ["BRAILLE LINE:  'Africa collapsed'",
     "     VISIBLE:  'Africa collapsed', cursor=1",
     "SPEECH OUTPUT: 'Africa.'",
     "SPEECH OUTPUT: 'collapsed.'",
     "SPEECH OUTPUT: 'tree level 2'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "3. Basic whereAmI",
    ["BRAILLE LINE:  'Africa collapsed'",
     "     VISIBLE:  'Africa collapsed', cursor=1",
     "SPEECH OUTPUT: 'Africa.'",
     "SPEECH OUTPUT: '1 of 6.'",
     "SPEECH OUTPUT: 'collapsed tree level 2'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Right"))
sequence.append(utils.AssertPresentationAction(
    "4. Expand Africa",
    ["BRAILLE LINE:  'Africa expanded'",
     "     VISIBLE:  'Africa expanded', cursor=1",
     "SPEECH OUTPUT: 'expanded'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "5. Down arrow to Egypt",
    ["BRAILLE LINE:  'Egypt list item'",
     "     VISIBLE:  'Egypt list item', cursor=1",
     "SPEECH OUTPUT: 'Egypt.'",
     "SPEECH OUTPUT: 'tree level 3'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "6. Down arrow to Kenya",
    ["BRAILLE LINE:  'Kenya collapsed'",
     "     VISIBLE:  'Kenya collapsed', cursor=1",
     "SPEECH OUTPUT: 'Kenya.'",
     "SPEECH OUTPUT: 'collapsed.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Right"))
sequence.append(utils.AssertPresentationAction(
    "7. Expand Kenya",
    ["BRAILLE LINE:  'Kenya expanded'",
     "     VISIBLE:  'Kenya expanded', cursor=1",
     "SPEECH OUTPUT: 'expanded'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Left"))
sequence.append(utils.AssertPresentationAction(
    "8. Collapse Kenya",
    ["BRAILLE LINE:  'Kenya collapsed'",
     "     VISIBLE:  'Kenya collapsed', cursor=1",
     "SPEECH OUTPUT: 'collapsed'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "9. Down arrow to Sudan",
    ["BRAILLE LINE:  'Sudan collapsed'",
     "     VISIBLE:  'Sudan collapsed', cursor=1",
     "SPEECH OUTPUT: 'Sudan.'",
     "SPEECH OUTPUT: 'collapsed.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "10. Down arrow to Asia",
    ["BRAILLE LINE:  'Asia collapsed'",
     "     VISIBLE:  'Asia collapsed', cursor=1",
     "SPEECH OUTPUT: 'Asia.'",
     "SPEECH OUTPUT: 'collapsed.'",
     "SPEECH OUTPUT: 'tree level 2'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Right"))
sequence.append(utils.AssertPresentationAction(
    "11. Expand Asia",
    ["BRAILLE LINE:  'Asia expanded'",
     "     VISIBLE:  'Asia expanded', cursor=1",
     "SPEECH OUTPUT: 'expanded'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "12. Down arrow to China",
    ["BRAILLE LINE:  'China list item'",
     "     VISIBLE:  'China list item', cursor=1",
     "SPEECH OUTPUT: 'China.'",
     "SPEECH OUTPUT: 'tree level 3'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "13. Down arrow to India",
    ["BRAILLE LINE:  'India list item'",
     "     VISIBLE:  'India list item', cursor=1",
     "SPEECH OUTPUT: 'India.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "14. Down arrow to Russia",
    ["BRAILLE LINE:  'Russia list item'",
     "     VISIBLE:  'Russia list item', cursor=1",
     "SPEECH OUTPUT: 'Russia.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "15. Down arrow to Mongolia",
    ["BRAILLE LINE:  'Mongolia list item'",
     "     VISIBLE:  'Mongolia list item', cursor=1",
     "SPEECH OUTPUT: 'Mongolia.'"]))

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