Skip to content

Commit 5394e28

Browse files
committed
add test for web socket channels
1 parent fff4d70 commit 5394e28

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/test/cypress/integration/monex_spec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,56 @@ describe('Monex', function () {
6363
})
6464
})
6565

66+
describe('remote console channels', function () {
67+
it ('should show the message from the right channel', function () {
68+
// WebSocket connection 1.
69+
const ws1 = new WebSocket('ws://localhost:8080/exist/rconsole')
70+
ws1.onopen = () => {
71+
ws1.send(JSON.stringify({ channel: 'c1' }))
72+
}
73+
ws1.onmessage = (e) => {
74+
if (e.data == "ping") return;
75+
const messageData = JSON.parse(e.data)
76+
// Verify message content
77+
expect(messageData.message).to.eq('111')
78+
// Close connection and end test
79+
ws.close()
80+
done()
81+
}
82+
ws1.onerror = (error) => {
83+
done(error)
84+
}
85+
86+
// WebSocket connection 2.
87+
const ws2 = new WebSocket('ws://localhost:8080/exist/rconsole')
88+
ws2.onopen = () => {
89+
ws2.send(JSON.stringify({ channel: 'c2' }))
90+
}
91+
ws2.onmessage = (e) => {
92+
if (e.data == "ping") return;
93+
const messageData = JSON.parse(e.data)
94+
// Verify message content
95+
expect(messageData.message).to.eq('222')
96+
// Close connection and end test
97+
ws.close()
98+
done()
99+
}
100+
ws2.onerror = (error) => {
101+
done(error)
102+
}
103+
104+
// Send messages to both web sockets.
105+
cy.request({
106+
method: 'GET',
107+
url: '/rest/db?_query=import%20module%20namespace%20console="http://exist-db.org/xquery/console";%20console:log("c1", "111")'
108+
})
109+
cy.request({
110+
method: 'GET',
111+
url: '/rest/db?_query=import%20module%20namespace%20console="http://exist-db.org/xquery/console";%20console:log("c2", "222")'
112+
})
113+
})
114+
})
115+
66116
describe('remote monitoring', function () {
67117
it ('should load remote monitoring', function () {
68118
cy.visit('/apps/monex/remotes.html')

0 commit comments

Comments
 (0)