xref: /openbmc/openbmc/poky/bitbake/lib/toaster/tests/browser/test_landing_page.py (revision 8460358c3d24c71d9d38fd126c745854a6301564)
1#! /usr/bin/env python3
2#
3# BitBake Toaster Implementation
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7# Copyright (C) 2013-2016 Intel Corporation
8#
9
10from django.urls import reverse
11from django.utils import timezone
12from tests.browser.selenium_helpers import SeleniumTestCase
13from selenium.webdriver.common.by import By
14
15from orm.models import Layer, Layer_Version, Project, Build
16
17
18class TestLandingPage(SeleniumTestCase):
19    """ Tests for redirects on the landing page """
20
21    PROJECT_NAME = 'test project'
22    LANDING_PAGE_TITLE = 'This is Toaster'
23    CLI_BUILDS_PROJECT_NAME = 'command line builds'
24
25    def setUp(self):
26        """ Add default project manually """
27        self.project = Project.objects.create_project(
28            self.CLI_BUILDS_PROJECT_NAME,
29            None
30        )
31        self.project.is_default = True
32        self.project.save()
33
34    def test_icon_info_visible_and_clickable(self):
35        """ Test that the information icon is visible and clickable """
36        self.get(reverse('landing'))
37        self.wait_until_visible('#toaster-version-info-sign')
38        info_sign = self.find('#toaster-version-info-sign')
39
40        # check that the info sign is visible
41        self.assertTrue(info_sign.is_displayed())
42
43        # check that the info sign is clickable
44        # and info modal is appearing when clicking on the info sign
45        info_sign.click()  # click on the info sign make attribute 'aria-describedby' visible
46        info_model_id = info_sign.get_attribute('aria-describedby')
47        self.wait_until_visible(f'#{info_model_id}')
48        info_modal = self.find(f'#{info_model_id}')
49        self.assertTrue(info_modal.is_displayed())
50        self.assertTrue("Toaster version information" in info_modal.text)
51
52    def test_documentation_link_displayed(self):
53        """ Test that the documentation link is displayed """
54        self.get(reverse('landing'))
55        self.wait_until_visible('#navbar-docs')
56        documentation_link = self.find('#navbar-docs > a')
57
58        # check that the documentation link is visible
59        self.assertTrue(documentation_link.is_displayed())
60
61        # check browser open new tab toaster manual when clicking on the documentation link
62        self.assertEqual(documentation_link.get_attribute('target'), '_blank')
63        self.assertEqual(
64            documentation_link.get_attribute('href'),
65            'http://docs.yoctoproject.org/toaster-manual/index.html#toaster-user-manual')
66        self.assertTrue("Documentation" in documentation_link.text)
67
68    def test_openembedded_jumbotron_link_visible_and_clickable(self):
69        """ Test OpenEmbedded link jumbotron is visible and clickable: """
70        self.get(reverse('landing'))
71        self.wait_until_visible('.jumbotron')
72        jumbotron = self.find('.jumbotron')
73
74        # check OpenEmbedded
75        openembedded = jumbotron.find_element(By.LINK_TEXT, 'OpenEmbedded')
76        self.assertTrue(openembedded.is_displayed())
77        openembedded.click()
78        self.assertTrue("openembedded.org" in self.driver.current_url)
79
80    def test_bitbake_jumbotron_link_visible_and_clickable(self):
81        """ Test BitBake link jumbotron is visible and clickable: """
82        self.get(reverse('landing'))
83        self.wait_until_visible('.jumbotron')
84        jumbotron = self.find('.jumbotron')
85
86        # check BitBake
87        bitbake = jumbotron.find_element(By.LINK_TEXT, 'BitBake')
88        self.assertTrue(bitbake.is_displayed())
89        bitbake.click()
90        self.assertTrue(
91            "docs.yoctoproject.org/bitbake.html" in self.driver.current_url)
92
93    def test_yoctoproject_jumbotron_link_visible_and_clickable(self):
94        """ Test Yocto Project link jumbotron is visible and clickable: """
95        self.get(reverse('landing'))
96        self.wait_until_visible('.jumbotron')
97        jumbotron = self.find('.jumbotron')
98
99        # check Yocto Project
100        yoctoproject = jumbotron.find_element(By.LINK_TEXT, 'Yocto Project')
101        self.assertTrue(yoctoproject.is_displayed())
102        yoctoproject.click()
103        self.assertTrue("yoctoproject.org" in self.driver.current_url)
104
105    def test_link_setup_using_toaster_visible_and_clickable(self):
106        """ Test big magenta button setting up and using toaster link in jumbotron
107            if visible and clickable
108        """
109        self.get(reverse('landing'))
110        self.wait_until_visible('.jumbotron')
111        jumbotron = self.find('.jumbotron')
112
113        # check Big magenta button
114        big_magenta_button = jumbotron.find_element(By.LINK_TEXT,
115                                                    'Toaster is ready to capture your command line builds'
116                                                    )
117        self.assertTrue(big_magenta_button.is_displayed())
118        big_magenta_button.click()
119        self.assertTrue(
120            "docs.yoctoproject.org/toaster-manual/setup-and-use.html#setting-up-and-using-toaster" in self.driver.current_url)
121
122    def test_link_create_new_project_in_jumbotron_visible_and_clickable(self):
123        """ Test big blue button create new project jumbotron if visible and clickable """
124        # Create a layer and a layer version to make visible the big blue button
125        layer = Layer.objects.create(name='bar')
126        Layer_Version.objects.create(layer=layer)
127
128        self.get(reverse('landing'))
129        self.wait_until_visible('.jumbotron')
130        jumbotron = self.find('.jumbotron')
131
132        # check Big Blue button
133        big_blue_button = jumbotron.find_element(By.LINK_TEXT,
134                                                 'Create your first Toaster project to run manage builds'
135                                                 )
136        self.assertTrue(big_blue_button.is_displayed())
137        big_blue_button.click()
138        self.assertTrue("toastergui/newproject/" in self.driver.current_url)
139
140    def test_toaster_manual_link_visible_and_clickable(self):
141        """ Test Read the Toaster manual link jumbotron is visible and clickable: """
142        self.get(reverse('landing'))
143        self.wait_until_visible('.jumbotron')
144        jumbotron = self.find('.jumbotron')
145
146        # check Read the Toaster manual
147        toaster_manual = jumbotron.find_element(
148            By.LINK_TEXT, 'Read the Toaster manual')
149        self.assertTrue(toaster_manual.is_displayed())
150        toaster_manual.click()
151        self.assertTrue(
152            "https://docs.yoctoproject.org/toaster-manual/index.html#toaster-user-manual" in self.driver.current_url)
153
154    def test_contrib_to_toaster_link_visible_and_clickable(self):
155        """ Test Contribute to Toaster link jumbotron is visible and clickable: """
156        self.get(reverse('landing'))
157        self.wait_until_visible('.jumbotron')
158        jumbotron = self.find('.jumbotron')
159
160        # check Contribute to Toaster
161        contribute_to_toaster = jumbotron.find_element(
162            By.LINK_TEXT, 'Contribute to Toaster')
163        self.assertTrue(contribute_to_toaster.is_displayed())
164        contribute_to_toaster.click()
165        self.assertTrue(
166            "wiki.yoctoproject.org/wiki/contribute_to_toaster" in str(self.driver.current_url).lower())
167
168    def test_only_default_project(self):
169        """
170        No projects except default
171        => should see the landing page
172        """
173        self.get(reverse('landing'))
174        self.wait_until_visible('.jumbotron')
175        self.assertTrue(self.LANDING_PAGE_TITLE in self.get_page_source())
176
177    def test_default_project_has_build(self):
178        """
179        Default project has a build, no other projects
180        => should see the builds page
181        """
182        now = timezone.now()
183        build = Build.objects.create(project=self.project,
184                                     started_on=now,
185                                     completed_on=now)
186        build.save()
187
188        self.get(reverse('landing'))
189
190        elements = self.find_all('#allbuildstable')
191        self.assertEqual(len(elements), 1, 'should redirect to builds')
192        content = self.get_page_source()
193        self.assertFalse(self.PROJECT_NAME in content,
194                         'should not show builds for project %s' % self.PROJECT_NAME)
195        self.assertTrue(self.CLI_BUILDS_PROJECT_NAME in content,
196                        'should show builds for cli project')
197
198    def test_user_project_exists(self):
199        """
200        User has added a project (without builds)
201        => should see the projects page
202        """
203        user_project = Project.objects.create_project('foo', None)
204        user_project.save()
205
206        self.get(reverse('landing'))
207        self.wait_until_visible('#projectstable')
208
209        elements = self.find_all('#projectstable')
210        self.assertEqual(len(elements), 1, 'should redirect to projects')
211
212    def test_user_project_has_build(self):
213        """
214        User has added a project (with builds), command line builds doesn't
215        => should see the builds page
216        """
217        user_project = Project.objects.create_project(self.PROJECT_NAME, None)
218        user_project.save()
219
220        now = timezone.now()
221        build = Build.objects.create(project=user_project,
222                                     started_on=now,
223                                     completed_on=now)
224        build.save()
225
226        self.get(reverse('landing'))
227
228        self.wait_until_visible("#latest-builds")
229        elements = self.find_all('#allbuildstable')
230        self.assertEqual(len(elements), 1, 'should redirect to builds')
231        content = self.get_page_source()
232        self.assertTrue(self.PROJECT_NAME in content,
233                        'should show builds for project %s' % self.PROJECT_NAME)
234