-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.cy.js
178 lines (149 loc) · 4 KB
/
app.cy.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Test the critical functionality of the application
*/
describe('Application tests', () => {
beforeEach(() => {
cy.visit('http://localhost:5173/edinburgh-councillors');
cy
.get('button:contains("Ok, got it!")')
.click();
});
it('Checks welcome modal', () => {
cy
.get('button:contains("Ok, got it!")')
.should('not.exist');
});
it('Checks the map is loaded', () => {
cy
.get('path.leaflet-interactive')
.should('have.length', 17);
});
it('Checks councillor data is loaded', () => {
cy
.get('h3')
.contains('Almond')
.then(() => {
cy.get('h4')
.contains('Kevin Lang');
cy.get('a[href="tel:01315294389"]');
cy.get('a[href="mailto:[email protected]"]');
cy.get('a[href="https://democracy.edinburgh.gov.uk/mgUserInfo.aspx?UID=115"]');
});
cy
.get('h3')
.contains('Portobello')
.then(() => {
cy.get('h4')
.contains('Tim Jones');
cy.get('a[href="tel:01315294166"]');
cy.get('a[href="mailto:[email protected]"]');
cy.get('a[href="https://democracy.edinburgh.gov.uk/mgUserInfo.aspx?UID=2669"]');
});
});
it('Checks phone button is disabled when telephone number missing', () => {
cy
.get('h3')
.contains('Almond')
.then(() => {
cy.get('h4')
.contains('Lewis Younie');
cy.get('button[aria-label="Call Lewis Younie"][disabled]');
});
});
it('Checks all councillors have working image URLs', () => {
cy
.get('.ec-councillor-image')
.each($img => {
expect($img.attr('src')).to.not.have.string('councillor-no-portrait.png');
cy.request({
url: $img.attr('src')
})
.then(response => {
expect(response.status).to.eq(200);
});
});
});
it('Checks click on map highlights ward and scrolls to councillors', () => {
cy
.get('.leaflet-interactive')
.last()
.click();
cy.wait(1000);
cy
.get('.leaflet-interactive')
.last()
.then($path => {
$path.click();
expect($path.attr('fill-opacity')).to.eq('0.4');
cy
.get('.controls')
.then($panel => {
cy
.get('.ec-councillors')
.last()
.then($ward => {
expect($panel.attr('scrollTop')).to.eq($ward.attr('offsetTop'));
});
});
});
});
it('Checks correct postcode search highlights ward and scrolls to councillors, and deleting the postcode resets the map', () => {
cy
.get('input[type="search"]')
.type('EH1 1HZ');
cy.wait(1000);
cy
.get('.leaflet-interactive[fill-opacity="0.4"]')
.should('have.length', 1);
cy
.get('.ec-councillors')
.contains('City Centre')
.then($ward => {
cy
.get('.controls')
.then($panel => {
expect($panel.attr('scrollTop')).to.eq($ward.attr('offsetTop'));
});
});
cy
.get('input[type="search"]')
.clear();
cy.wait(1000);
cy
.get('.leaflet-interactive[fill-opacity="0.4"]')
.should('have.length', 0);
});
it('Checks incorrect postcode search displays error messages', () => {
cy
.get('input[type="search"]')
.type('EH$');
cy.wait(500);
cy
.get('.ec-warning')
.contains('Letters and numbers only');
cy
.get('input[type="search"]')
.clear()
.type('FH1');
cy.wait(500);
cy
.get('.ec-warning')
.contains('Enter an EH postcode');
cy
.get('input[type="search"]')
.clear()
.type('EH12 3456');
cy.wait(500);
cy
.get('.ec-warning')
.contains('Woops, that\'s too long');
cy
.get('input[type="search"]')
.clear()
.type('EH12 345');
cy.wait(500);
cy
.get('.ec-warning')
.contains('Couldn\'t find that postcode');
});
});