-
Notifications
You must be signed in to change notification settings - Fork 1
/
kuker-spec.js
84 lines (75 loc) · 2.27 KB
/
kuker-spec.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
/// <reference types="Cypress" />
// confirming events sent by the Kuker Redux emitter to Kuker DevTools
// by cleaning each event and comparing it to the expected object
// make sure we are only spying on Kuker Redux events (except for init)
const isKukerRedux = what =>
Cypress._.isPlainObject(what) && what.kuker && what.type !== 'NEW_EMITTER'
// only pick properties we want for testing
const reduxEvent = event => Cypress._.pick(event, 'action', 'state')
describe('Clean Kuker messages', () => {
beforeEach(() => {
cy.visit('/', {
onBeforeLoad (win) {
let kuker = cy.spy().as('kuker')
const postMessage = win.postMessage.bind(win)
win.postMessage = (what, target) => {
if (isKukerRedux(what)) {
const sanitized = reduxEvent(what)
kuker(sanitized)
// log better message ourselves
Cypress.log({
name: 'Redux',
message: `${what.action.type} "${what.action.text}"`,
consoleProps () {
return sanitized
}
}).end()
} // else ignore messages
return postMessage(what, target)
}
}
})
})
it('adds 2 todos', function () {
cy.get('.new-todo').type('learn testing{enter}')
// confirm the first Redux event
cy.get('@kuker')
.its('lastCall.args.0')
.should('deep.equal', {
action: { type: 'ADD_TODO', text: 'learn testing' },
state: {
todos: [
{
completed: false,
id: 0,
text: 'learn testing'
}
],
visibilityFilter: 'show_all'
}
})
cy.get('.new-todo').type('be cool{enter}')
// confirm the second Redux event
cy.get('@kuker')
.its('lastCall.args.0')
.should('deep.equal', {
action: { type: 'ADD_TODO', text: 'be cool' },
state: {
todos: [
{
completed: false,
id: 0,
text: 'learn testing'
},
{
completed: false,
id: 1,
text: 'be cool'
}
],
visibilityFilter: 'show_all'
}
})
cy.get('.todo-list li').should('have.length', 2)
})
})