Skip to content

Commit b049242

Browse files
authored
Merge pull request #9489 from jrafanie/add-cypress-throttling-and-notification-stubs
Add cypress commands for throttling and notification stubs
2 parents 5f9ac4f + 2c2c109 commit b049242

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "notifications",
3+
"count": 0,
4+
"subcount": 0,
5+
"pages": 0,
6+
"resources": [],
7+
"actions": [
8+
{
9+
"name": "mark_as_seen",
10+
"method": "post",
11+
"href": "http://localhost:3000/api/notifications"
12+
},
13+
{
14+
"name": "delete",
15+
"method": "post",
16+
"href": "http://localhost:3000/api/notifications"
17+
}
18+
],
19+
"links": {
20+
"self": "http://localhost:3000/api/notifications?offset=0",
21+
"first": "http://localhost:3000/api/notifications?offset=0",
22+
"last": "http://localhost:3000/api/notifications?offset=0"
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "notifications",
3+
"count": 0,
4+
"subcount": 0,
5+
"pages": 0,
6+
"resources": [],
7+
"actions": [
8+
{
9+
"name": "mark_as_seen",
10+
"method": "post",
11+
"href": "http://localhost:3000/api/notifications"
12+
},
13+
{
14+
"name": "delete",
15+
"method": "post",
16+
"href": "http://localhost:3000/api/notifications"
17+
}
18+
],
19+
"links": {
20+
"self": "http://localhost:3000/api/notifications?expand=resources&attributes=details&sort_by=id&sort_order=desc&limit=100&offset=0",
21+
"first": "http://localhost:3000/api/notifications?expand=resources&attributes=details&sort_by=id&sort_order=desc&limit=100&offset=0",
22+
"last": "http://localhost:3000/api/notifications?expand=resources&attributes=details&sort_by=id&sort_order=desc&limit=100&offset=0"
23+
}
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Cypress.Commands.add('stub_notifications', () => {
2+
cy.intercept('GET', '/api/notifications', (req) => {
3+
req.reply({fixture: 'empty_notifications.json'});
4+
});
5+
6+
cy.intercept('GET', '/api/notifications?expand=resources&attributes=details*', (req) => {
7+
req.reply({fixture: 'empty_notifications_expanded.json'});
8+
});
9+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Usage: cy.throttle_response(1000, 56);
2+
Cypress.Commands.add('throttle_response', (response_delay, throttle_kbps) => {
3+
cy.intercept(
4+
{
5+
url: 'http://localhost:3000/**',
6+
middleware: true,
7+
},
8+
(req) => {
9+
req.on('response', (res) => {
10+
// Add response delay and throttle network to simulate slower networks
11+
res.setDelay(response_delay).setThrottle(throttle_kbps)
12+
})
13+
}
14+
)
15+
});
16+

cypress/support/e2e.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ import './commands/explorer.js'
4444
import './commands/gtl.js'
4545
import './commands/login.js'
4646
import './commands/menu.js'
47+
import './commands/stub_notifications.js'
4748
import './commands/toolbar.js'
49+
import './commands/throttle_response.js'
4850

4951
// Assertions
5052
import './assertions/expect_rates_table.js';
@@ -65,3 +67,9 @@ Cypress.on('uncaught:exception', (err, runnable) => {
6567
return false;
6668
}
6769
});
70+
71+
beforeEach(() => {
72+
// Global hook run once before each test
73+
// cy.throttle_response(500, 56);
74+
// cy.stub_notifications();
75+
})

0 commit comments

Comments
 (0)