from plone import api
from ploneintranet.workspace.testing import PLONEINTRANET_WORKSPACE_INTEGRATION_TESTING
from unittest import TestCase


class TestWorkspaceWorkgroups(TestCase):

    layer = PLONEINTRANET_WORKSPACE_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer["portal"]
        self.request = self.layer["request"]
        self.workspace = api.content.create(
            container=self.portal.workspaces,
            id="testws",
            type="ploneintranet.workspace.workspacefolder",
        )

    def test_workspace_activity_stream_shown(self):
        """Test if activity stream is shown depending on the workspace settings."""
        view = api.content.get_view("view", self.workspace, self.request)

        # Should be shown by default.
        self.assertTrue(self.workspace.show_activity_stream)
        self.assertTrue(view.show_activity_stream)
        out = self.workspace()
        self.assertIn('id="post-box-workspaces"', out)
        self.assertIn('id="activity-stream-workspaces"', out)

        # The activity stream should not be shown when set to off.
        self.workspace.show_activity_stream = False
        self.assertFalse(self.workspace.show_activity_stream)
        self.assertFalse(view.show_activity_stream)
        out = self.workspace()
        self.assertNotIn('id="post-box-workspaces"', out)
        self.assertNotIn('id="activity-stream-workspaces"', out)
