test/components/app.js   A
last analyzed

Complexity

Total Complexity 42
Complexity/F 1

Size

Lines of Code 196
Function Count 42

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 42
eloc 87
mnd 0
bc 0
fnc 42
dl 0
loc 196
rs 9.0399
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like test/components/app.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/**
2
 * Test for getting started with Selenium.
3
 */
4
"use strict";
5
6
7
8
const assert = require("assert");
9
const test = require("selenium-webdriver/testing");
10
const webdriver = require("selenium-webdriver");
11
const By = require("selenium-webdriver").By;
12
13
let browser;
14
15
16
// Does not work with WSL!! Use cygwin
17
18
19
20
// Test Suite
21
test.describe("Me-Sida", function() {
22
23
    test.beforeEach(function(done) {
24
        this.timeout(20000);
25
        browser = new webdriver.Builder().
26
            withCapabilities(webdriver.Capabilities.firefox()).build();
27
28
        browser.get("https://pamo18.me");
29
        done();
30
    });
31
32
    test.afterEach(function(done) {
33
        browser.quit();
34
        done();
35
    });
36
37
    // Test case
38
    test.it("Test index", function(done) {
39
        // Check correct title
40
        browser.getTitle().then(function(title) {
41
            assert.equal(title, "Me-Sida");
42
        });
43
44
        // Check correct heading
45
        browser.findElement(By.css("h1")).then(function(element) {
46
            element.getText().then(function(text) {
47
                assert.equal(text, "Om Mig Själv");
48
            });
49
        });
50
51
        // Check correct URL ending
52
        browser.getCurrentUrl().then(function(url) {
53
            assert.ok(url.endsWith(""));
54
        });
55
56
        done();
57
    });
58
59
    test.it("Test go to redovisning", function(done) {
60
        // Use nav link to go to home page
61
        browser.findElement(By.linkText("Redovisning")).then(function(element) {
62
            element.click();
63
        });
64
65
        // Check correct heading
66
        browser.findElement(By.css("h1")).then(function(element) {
67
            element.getText().then(function(text) {
68
                assert.equal(text, "Kmom01");
69
            });
70
        });
71
72
        // Check correct URL ending
73
        browser.getCurrentUrl().then(function(url) {
74
            assert.ok(url.endsWith("/reports/week/1"));
75
        });
76
77
        done();
78
    });
79
80
    test.it("Test go to kmom03", function(done) {
81
        // Use nav link to go to home page
82
        browser.findElement(By.linkText("Redovisning")).then(function(element) {
83
            element.click();
84
        });
85
86
        browser.findElement(By.linkText("Kmom03")).then(function(element) {
87
            element.click();
88
        });
89
90
        // Check correct heading
91
        browser.findElement(By.css("h1")).then(function(element) {
92
            element.getText().then(function(text) {
93
                assert.equal(text, "Kmom03");
94
            });
95
        });
96
97
        // Check correct URL ending
98
        browser.getCurrentUrl().then(function(url) {
99
            assert.ok(url.endsWith("/reports/week/3"));
100
        });
101
102
        done();
103
    });
104
105
    test.it("Test go to register", function(done) {
106
        // Use nav link to go to home page
107
        browser.findElement(By.linkText("Register")).then(function(element) {
108
            element.click();
109
        });
110
111
        // Check correct heading
112
        browser.findElement(By.css("h1")).then(function(element) {
113
            element.getText().then(function(text) {
114
                assert.equal(text, "Registration");
115
            });
116
        });
117
118
        // Check correct URL ending
119
        browser.getCurrentUrl().then(function(url) {
120
            assert.ok(url.endsWith("/register"));
121
        });
122
123
        done();
124
    });
125
126
    test.it("Test login", function(done) {
127
        // Use nav link to go to home page
128
        browser.findElement(By.linkText("Login")).then(function(element) {
129
            element.click();
130
        });
131
132
        browser.findElement(By.name("name")).then(function(element) {
133
            element.sendKeys("doe");
134
        });
135
136
        browser.findElement(By.name("password")).then(function(element) {
137
            element.sendKeys("doe");
138
        });
139
140
        browser.findElement(By.name("login")).then(function(element) {
141
            element.click();
142
        });
143
144
        browser.sleep(2000);
145
146
        // Check correct heading
147
        browser.findElement(By.css("h1")).then(function(element) {
148
            element.getText().then(function(text) {
149
                assert.equal(text, "Profile page");
150
            });
151
        });
152
153
        // Check correct heading
154
        browser.findElement(By.css("h3")).then(function(element) {
155
            element.getText().then(function(text) {
156
                assert.equal(text, "Username: doe");
157
            });
158
        });
159
160
        // Check correct URL ending
161
        browser.getCurrentUrl().then(function(url) {
162
            assert.ok(url.endsWith("/profile"));
163
        });
164
165
        browser.findElement(By.name("logoff")).then(function(element) {
166
            element.click();
167
        });
168
169
        // Check correct heading
170
        browser.findElement(By.css("h1")).then(function(element) {
171
            element.getText().then(function(text) {
172
                assert.equal(text, "Login");
173
            });
174
        });
175
176
        done();
177
    });
178
179
    test.it("Test go to profile", function(done) {
180
        // Use nav link to go to home page
181
        browser.findElement(By.linkText("Profile")).then(function(element) {
182
            element.click();
183
        });
184
185
        // Check correct heading
186
        browser.findElement(By.css("h1")).then(function(element) {
187
            element.getText().then(function(text) {
188
                assert.equal(text, "Profile page");
189
            });
190
        });
191
192
        // Check correct URL ending
193
        browser.getCurrentUrl().then(function(url) {
194
            assert.ok(url.endsWith("/profile"));
195
        });
196
197
        done();
198
    });
199
});
200