Skip to content

Commit

Permalink
(TBR) fixed the tests and added the On message hook
Browse files Browse the repository at this point in the history
  • Loading branch information
PawBud committed Jul 26, 2022
1 parent 1140ad8 commit bbb985e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/headless/plugins/chat/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ const ChatBox = ModelWithContact.extend({
!this.handleChatMarker(attrs) &&
!(await this.handleRetraction(attrs))
) {
const message_retraction = await api.hook('onMessage', this, { retract: false });
this.setEditable(attrs, attrs.time);

if (attrs['chat_state'] && attrs.sender === 'them') {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/jingle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./chat-header-notification.js";
import './toolbar-button.js';
import { JINGLE_CALL_STATUS } from './constants.js';
import { html } from "lit";
import { parseJingleMessage } from './utils.js';
import { parseJingleMessage, handleRetraction } from './utils.js';

const { Strophe } = converse.env;

Expand Down Expand Up @@ -47,5 +47,6 @@ converse.plugins.add('converse-jingle', {
return buttons;
});
api.listen.on('parseMessage', parseJingleMessage);
api.listen.on('onMessage', handleRetraction);
},
});
18 changes: 8 additions & 10 deletions src/plugins/jingle/tests/message-initiation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("A Jingle Message Initiation Request", function () {

describe("from the initiator's perspective", function () {

fit("is sent out when one clicks the call button", mock.initConverse(
it("is sent out when one clicks the call button", mock.initConverse(
['chatBoxesFetched'], {}, async function (_converse) {

await mock.waitForRoster(_converse, 'current', 1);
Expand Down Expand Up @@ -66,10 +66,8 @@ describe("A Jingle Message Initiation Request", function () {
// This needs to be fixed
expect(view.model.messages.length).toEqual(1);
}));
});

//todo Add a test of the chat header
it("is ended when the initiator clicks the end call header button", mock.initConverse(
fit("is ended when the initiator clicks the end call header button", mock.initConverse(
['chatBoxesFetched'], {}, async function (_converse) {

await mock.waitForRoster(_converse, 'current', 1);
Expand All @@ -79,7 +77,8 @@ describe("A Jingle Message Initiation Request", function () {
// the first click starts the call, and the other one ends it
const call_button = view.querySelector('converse-jingle-toolbar-button button');
call_button.click();
call_button.click();
const header_end_call_button = await u.waitUntil(() => view.querySelector('.jingle-call-initiated-button'));
header_end_call_button.click();
const sent_stanzas = _converse.connection.sent_stanzas;
const stanza = await u.waitUntil(() => sent_stanzas.filter(s => sizzle(`retract[xmlns='${Strophe.NS.JINGLEMESSAGE}']`, s).length).pop());
const retract_id = stanza.querySelector('retract');
Expand All @@ -104,7 +103,7 @@ describe("A Jingle Message Initiation Request", function () {

describe("from the receiver's perspective", function () {

it("is received when the initiator clicks the call button", mock.initConverse(
fit("is received when the initiator clicks the call button", mock.initConverse(
['chatBoxesFetched'], { allow_non_roster_messaging: true }, async function (_converse) {

await mock.waitForRoster(_converse, 'current', 1);
Expand All @@ -120,11 +119,10 @@ describe("A Jingle Message Initiation Request", function () {
</propose>
<store xmlns='${Strophe.NS.HINTS}'/>
</message>`);
_converse.connection._dataRecv(mock.createRequest(initiator_stanza));
_converse.connection._dataRecv(mock.createRequest(initiator_stanza));

const view = await u.waitUntil(() => _converse.chatboxviews.get(contact_jid));
expect(view.model.messages.length).toEqual(1);
const message = view.model.messages.at(0);
const view = await u.waitUntil(() => _converse.chatboxviews.get(contact_jid));
expect(view.model.messages.length).toEqual(1);
}));

it("is received when the initiator clicks the end call button", mock.initConverse(
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/jingle/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ function getJingleProposeType(stanza){
export function jingleCallInitialized() {
JingleCallModal;
}

export function handleRetraction(context, retracted) {

}

0 comments on commit bbb985e

Please sign in to comment.