Completed
Push — feature/browser_tests ( 4795bd )
by Grant
14:44
created

ProfileTest::testFillProfile()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 107
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 107
rs 8.8509
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Tests\Browser;
4
5
use Tests\DuskTestCase;
6
use Laravel\Dusk\Browser;
7
use Illuminate\Foundation\Testing\WithFaker;
8
use Illuminate\Foundation\Testing\DatabaseMigrations;
9
10
class ProfileTest extends DuskTestCase {
11
12
    public function testFillProfile() {
13
14
        // User with name / email / password, not saved to database
15
        $user = factory(\App\Models\User::class)->make();
16
17
        // Register with factory credentials
18
        $this->browse(function ($browser) use ($user) {
19
            $browser->visit('/register')
20
                    ->type('name', $user->name)
21
                    ->type('email', $user->email)
22
                    ->type('password', $user->password)
23
                    ->type('password_confirmation', $user->password)
24
                    ->press('Register')
25
                    // Should be able to see My Profile after authentication
26
                    ->assertSee('My Profile');
27
28
            // Go to profile
29
            $browser->clickLink('My Profile')
30
                    ->assertSee('About Me');
31
32
            // Go to My Experience, open accordion
33
            $browser->clickLink('My Experience')
34
                    ->assertSee('My Experience')
35
                    ->press('Add Diploma/Degree')
36
                    ->assertSee('New Diploma/Degree');
37
38
            // Add a diploma
39
            $browser->select('#degrees\5b new\5d \5b 1\5d degreeType', '4')
40
                    ->type('#degrees\5b new\5d \5b 1\5d degreeArea', 'Test area of study')
41
                    ->type('#degrees\5b new\5d \5b 1\5d degreeInstitution', 'Test institution');
42
                    // TODO: Selectors for date picker
43
                    //->click('#degrees\5b new\5d \5b 1\5d degreeStartDate')
44
                    //->type('#degrees\5b new\5d \5b 1\5d degreeStartDate', ['2017'], ['{tab}'], ['0717']);
45
                    //->type('#degrees\5b new\5d \5b 1\5d degreeEndDate', '2018', ['{tab}'], '08', ['{tab}'], '18');
46
47
            // Saved work sample name should be visible
48
            $browser->assertSee('Save Diploma/Degree')
49
                    ->pause(777) // Fails without a short pause
50
                    ->press('Save Diploma/Degree')
51
                    ->assertSee('Phd, Test area of study');
52
53
            // TODO: Repeat for certification / equivalent experience
54
            //$browser->press('Add Course/Certification')
55
            //        ->assertSee('New Course/Certification');
56
57
            // Go to My Skills page
58
            $browser->clickLink('My Skills')
59
                    ->assertSee('My Skills')
60
                    ->press('Add Skill')
61
                    ->assertSee('New Skill');
62
63
            // Add a soft skill
64
            $browser->select('#skill_declarations\5b new\5d \5b soft\5d \5b 1\5d skillSelection', '24') // Select dropdown by value
65
                    ->keys('#skill_declarations\5b new\5d \5b soft\5d \5b 1\5d skillSelection',
66
                        ['{tab}'], ['{tab}'], ['{arrow_right}']) // Keyboard controls were necessary to select skill level properly
67
                    ->type('#skill_declarations\5b new\5d \5b soft\5d \5b 1\5d skillDescription', 'Test skill description');
68
69
            $browser->script('window.scrollTo(0, 1000);');
70
71
            // Text corresponding to skill selection value should be visible
72
            $browser->assertSee('Save Skill')
73
                    ->pause(777)
74
                    ->press('Save Skill')
75
                    ->assertSee('Passion');
76
77
            // TODO: Repeat for hard skill
78
79
            // Go to My References, open accordion
80
            $browser->clickLink('My References')
81
                    ->assertSee('My References')
82
                    ->press('Add Reference')
83
                    ->assertSee('New Reference');
84
85
            // Add a reference
86
            $browser->type('#references\5b new\5d \5b 1\5d referenceName', 'Test Reference')
87
                    ->select('#references\5b new\5d \5b 1\5d referenceRelationship') // Selects random if not specified
88
                    ->type('#references\5b new\5d \5b 1\5d referenceEmail', '[email protected]')
89
                    ->type('#references\5b new\5d \5b 1\5d referenceDescription', 'Test reference description');
90
91
            // Scroll down (button click will fail if not visible on test browser screen)
92
            $browser->script('window.scrollTo(0, 1000);');
93
94
            // Saved work sample name should be visible
95
            $browser->assertSee('Save Reference')
96
                    ->pause(777) // Fails without a short pause
97
                    ->press('Save Reference')
98
                    ->assertSee('Test Reference');
99
100
            // Go to My Work Samples, open accordion
101
            $browser->clickLink('My Work Samples')
102
                    ->assertSee('My Work Samples')
103
                    ->press('Add Sample')
104
                    ->assertSee('New Work Sample');
105
106
            // Add work sample data, wouln't work without copying the full selector
107
            $browser->type('#work_samples\5b new\5d \5b 1\5d sampleName', 'Test Sample')
108
                    ->select('#work_samples\5b new\5d \5b 1\5d sampleType') // Selects random if not specified
109
                    ->type('#work_samples\5b new\5d \5b 1\5d sampleLink', 'http://talent.canada.ca')
110
                    ->type('#work_samples\5b new\5d \5b 1\5d sampleDescription', 'Test sample description');
111
112
            $browser->script('window.scrollTo(0, 1000);');
113
114
            // Saved work sample name should be visible
115
            $browser->assertSee('Save Sample')
116
                    ->pause(777) // Fails without a short pause
117
                    ->press('Save Sample')
118
                    ->assertSee('Test Sample');
119
120
        });
121
    }
122
}
123