"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/ui/test/utest_crumbs.py $
$Id: utest_crumbs.py 30177 2007-10-19 11:30:16Z dbinger $
"""
from dulcinea.common import CommonTest
from dulcinea.ui.crumbs import format_crumbs
from qp.fill.directory import Directory, get_crumb_tree
import dulcinea.ui.crumbs


class CrumbTest (CommonTest):

    def test_get_exports1(self):
        exports = [('', '_q_index', 'crumb', 'title')]
        class Dir(Directory):
            def get_exports(self):
                return exports
        assert Dir().get_exports() == exports

    def test_get_crumb_tree(self):
        class Dir3(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb3', 'title3'),
                        ('c3', 'n3', 'acrumb', 'atitle')]

            def _q_traverse(self, components):
                return get_crumb_tree()
            n3 = 'ok'
        class Dir2(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb2', 'title2'),
                        ('c2', 'n2', 'acrumb', 'atitle')]
            n2 = Dir3()
        class Dir1(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb', 'title'),
                        ('c1', 'n1', 'acrumb', 'atitle')]
            n1 = Dir2()

        directory = Dir1()
        assert directory._q_traverse(['c1', 'c2', ''])  == [
            [('./../../', 'crumb', 'title', 'menu_'),
             ('./../../c1', 'acrumb', 'atitle', 'menu_c1')],
            [('./../', 'crumb2', 'title2', 'menu_'),
             ('./../c2', 'acrumb', 'atitle', 'menu_c2')]]

    def test_get_crumb_tree_no_index_crumb_still_has_menu(self):
        class Dir2(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb3', 'title3'),
                        ('c2', 'n2', 'acrumb', 'atitle')]

            def _q_traverse(self, components):
                return get_crumb_tree()
            n2 = 'ok'
        class Dir(Directory):
            def get_exports(self):
                return [('', 'c', '', 'title'),
                        ('c1', 'n1', 'still see crumb', 'still see title')]
            n1 = Dir2()

        directory = Dir()
        assert directory._q_traverse(['c1', 'c2'])  == [
            [('./../c1', 'still see crumb', 'still see title', 'menu_c1')],
            [('./', 'crumb3', 'title3', 'menu_'),
             ('./c2', 'acrumb', 'atitle', 'menu_c2')]]

    def test_format_crumbs(self):
        class Dir3(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb', 'title'),
                        ('c3', 'n3', 'acrumb', 'atitle')]

            def _q_traverse(self, components):
                return format_crumbs()
            n3 = 'ok'
        class Dir2(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb', 'title'),
                        ('c2', 'n2', 'acrumb', 'atitle')]
            n2 = Dir3()
        class Dir1(Directory):
            def get_exports(self):
                return [('', '_q_index', 'crumb', 'title'),
                        ('c1', 'n1', 'acrumb', 'atitle')]
            n1 = Dir2()

        directory = Dir1()
        crumb_menus = False
        def get_config_value(name):
            return crumb_menus
        dulcinea.ui.crumbs.get_config_value = get_config_value
        crumb_menus = True

if __name__ == "__main__":
    CrumbTest()
