summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/tests/browser/test_landing_page.py
blob: 771e627a8dc56494051f87819ca30203ec39e84f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#! /usr/bin/env python3
#
# BitBake Toaster Implementation
#
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2013-2016 Intel Corporation
#

from django.urls import reverse
from django.utils import timezone
from tests.browser.selenium_helpers import SeleniumTestCase

from orm.models import Project, Build

class TestLandingPage(SeleniumTestCase):
    """ Tests for redirects on the landing page """

    PROJECT_NAME = 'test project'
    LANDING_PAGE_TITLE = 'This is Toaster'
    CLI_BUILDS_PROJECT_NAME = 'command line builds'

    def setUp(self):
        """ Add default project manually """
        self.project = Project.objects.create_project(
            self.CLI_BUILDS_PROJECT_NAME,
            None
        )
        self.project.is_default = True
        self.project.save()

    def test_icon_info_visible_and_clickable(self):
        """ Test that the information icon is visible and clickable """
        self.get(reverse('landing'))
        info_sign = self.find('#toaster-version-info-sign')

        # check that the info sign is visible
        self.assertTrue(info_sign.is_displayed())

        # check that the info sign is clickable
        # and info modal is appearing when clicking on the info sign
        info_sign.click() # click on the info sign make attribute 'aria-describedby' visible
        info_model_id = info_sign.get_attribute('aria-describedby')
        info_modal = self.find(f'#{info_model_id}')
        self.assertTrue(info_modal.is_displayed())
        self.assertTrue("Toaster version information" in info_modal.text)

    def test_documentation_link_displayed(self):
        """ Test that the documentation link is displayed """
        self.get(reverse('landing'))
        documentation_link = self.find('#navbar-docs > a')

        # check that the documentation link is visible
        self.assertTrue(documentation_link.is_displayed())
        
        # check browser open new tab toaster manual when clicking on the documentation link
        self.assertEqual(documentation_link.get_attribute('target') , '_blank')
        self.assertEqual(
            documentation_link.get_attribute('href'), 
            'http://docs.yoctoproject.org/toaster-manual/index.html#toaster-user-manual')
        self.assertTrue("Documentation" in documentation_link.text)

    def test_only_default_project(self):
        """
        No projects except default
        => should see the landing page
        """
        self.get(reverse('landing'))
        self.assertTrue(self.LANDING_PAGE_TITLE in self.get_page_source())

    def test_default_project_has_build(self):
        """
        Default project has a build, no other projects
        => should see the builds page
        """
        now = timezone.now()
        build = Build.objects.create(project=self.project,
                                     started_on=now,
                                     completed_on=now)
        build.save()

        self.get(reverse('landing'))

        elements = self.find_all('#allbuildstable')
        self.assertEqual(len(elements), 1, 'should redirect to builds')
        content = self.get_page_source()
        self.assertFalse(self.PROJECT_NAME in content,
                         'should not show builds for project %s' % self.PROJECT_NAME)
        self.assertTrue(self.CLI_BUILDS_PROJECT_NAME in content,
                        'should show builds for cli project')

    def test_user_project_exists(self):
        """
        User has added a project (without builds)
        => should see the projects page
        """
        user_project = Project.objects.create_project('foo', None)
        user_project.save()

        self.get(reverse('landing'))

        elements = self.find_all('#projectstable')
        self.assertEqual(len(elements), 1, 'should redirect to projects')

    def test_user_project_has_build(self):
        """
        User has added a project (with builds), command line builds doesn't
        => should see the builds page
        """
        user_project = Project.objects.create_project(self.PROJECT_NAME, None)
        user_project.save()

        now = timezone.now()
        build = Build.objects.create(project=user_project,
                                     started_on=now,
                                     completed_on=now)
        build.save()

        self.get(reverse('landing'))

        elements = self.find_all('#allbuildstable')
        self.assertEqual(len(elements), 1, 'should redirect to builds')
        content = self.get_page_source()
        self.assertTrue(self.PROJECT_NAME in content,
                        'should show builds for project %s' % self.PROJECT_NAME)
        self.assertFalse(self.CLI_BUILDS_PROJECT_NAME in content,
                         'should not show builds for cli project')