# Copyright (c) 2010 gocept gmbh & co. kg
# See also LICENSE.txt

import zeit.cms.testing


class TestPanels(zeit.cms.testing.SeleniumTestCase):

    def assertSidebarState(self, state):
        s = self.selenium
        s.waitForElementPresent(
            '//div[@id="sidebar-dragger"][@class="sidebar-%s"]' % state)

    def assertPanelState(self, id, state):
        s = self.selenium
        s.verifyElementPresent('//div[@id ="%s"][@class = "panel %s"]' %(
            id, state))

    def test_panels_should_be_foldable(self):
        s = self.selenium

        # Open a folder with articles.
        self.open('/repository/online/2007/01')

        self.assertPanelState('ClipboardPanel', 'unfolded')
        s.click('//div[@id = "ClipboardPanel"]/h1')
        self.assertPanelState('ClipboardPanel', 'folded')
        # Stays that way when reloading
        self.open('/repository/online/2007/01')
        self.assertPanelState('ClipboardPanel', 'folded')

        # unfold again:
        s.click('//div[@id = "ClipboardPanel"]/h1')
        self.assertPanelState('ClipboardPanel', 'unfolded')
        # Stays that way when reloading
        self.open('/repository/online/2007/01')
        self.assertPanelState('ClipboardPanel', 'unfolded')

    def test_sidebar_should_be_expandable_and_foldable(self):
        s = self.selenium
        self.open('/repository/online/2007/01')
        self.assertSidebarState('expanded')
        s.click('sidebar-dragger')
        self.assertSidebarState('folded')
        self.open('/repository/online/2007/01')
        self.assertSidebarState('folded')

@@ -396,14 +396,15 @@
   s.
-verify
+waitFor
 Elem

use waitFor to cope for timing issues