Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
Testing load messages
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquead committed Apr 2, 2019
1 parent 7507c02 commit e7c0cdd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
32 changes: 18 additions & 14 deletions lib/commprivate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const Message = require('../src/message.js')


class PrivateCommunication {

constructor(fetch) {
this.dataSync = new DataSync(fetch);
this.fetch = fetch;
Expand All @@ -17,7 +16,7 @@ class PrivateCommunication {
/**
* Loads messages into the inbox
*/
async loadMessages(myUsername, a){
async loadMessages(myUsername, a,testing){

var messages = new Array(); //here will be stored all messages loaded

Expand Down Expand Up @@ -55,7 +54,7 @@ class PrivateCommunication {
messages.push(new Message(sender,dateTime,message));
}
myMsgRead = true;
}, err => $("#addOurMessages").empty() );
}, err => {if(!testing){$("#addOurMessages").empty()}});

fc.readFile(fileWithMessagesSentByTheOtherUSer).then( body => {
var res = body.split("\n\n\n");
Expand All @@ -82,26 +81,27 @@ class PrivateCommunication {
if(!myMsgRead){
var that = this;
setTimeout(function(){
that.orderAndShow(messages, me);
that.orderAndShow(messages, me,testing);
}, 1000);
}else {
this.orderAndShow(messages, me);
this.orderAndShow(messages, me,testing);
}
}, err => $("#addOtherMessages").empty() );
}, err => {if(!testing){$("#addOurMessages").empty()}} );
}

orderAndShow(messages, me){
orderAndShow(messages, me,testing){
//Now order the messages
messages.sort(function(a,b){
// Turn your strings into dates, and then subtract them
// to get a value that is either negative, positive, or zero.
return new Date(b.dateTime) - new Date(a.dateTime);
});

console.log(messages);
$("#addMessages").empty();
$("#addOurMessages").empty();
$("#addOtherMessages").empty();
if(!testing){
console.log(messages);
$("#addMessages").empty();
$("#addOurMessages").empty();
$("#addOtherMessages").empty();
}
for ( var i=messages.length-1; i>=0; i--){
var mesg = messages[i].content;
var mesgToAdd = "";
Expand All @@ -119,7 +119,9 @@ class PrivateCommunication {
'</div>'+
'</div>'+
'</div>';
$("#addMessages").append(toAppend);
if(!testing){
$("#addMessages").append(toAppend);
}
}else{
console.log(messages[i].content + " en " + messages[i].sender);

Expand All @@ -128,7 +130,9 @@ class PrivateCommunication {
mesgToAdd + '<span id="userName" class="badge badge-secondary">'+messages[i].sender+'</span>'+
'</div>'+
'</div>';
$("#addMessages").append(toAppend);
if(!testing){
$("#addMessages").append(toAppend);
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ $('#create-button').click(async () => {
});

$('#start-new-chat-btn').click(async () => {
await core.sendMessage(personal,$("#data-name").val());
("#data-name").val("")
var message = $("#data-name").val();
var receiver = $("#possible-people option:selected").val();
$("#data-name").val("");
core.sendMessage(personal, receiver, message);
});


Expand All @@ -145,7 +147,7 @@ $('#start-new-chat-btn').click(async () => {
async function checkForNotifications() {
var length = $('#mySelectList > option').length;
if(length === 0){
await core.loadMessages(personal, $("#possible-people option:selected").val());
await core.loadMessages(personal, $("#possible-people option:selected").val(),false);
}
}

Expand All @@ -167,7 +169,7 @@ $("#cancel-group-menu").click(() => {
$('#create-new-group').addClass('hidden');
});

$("#possible-people-btn").click( async () => core.loadMessages(personal));
$("#possible-people-btn").click( async () => core.loadMessages(personal,$("#possible-people option:selected").val(),false));

/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ describe('Core testing', function () {


it("Obtain chat groups",async function(){
var username = await personal.loadNames("https://mariodiaz98.solid.community/profile/card#me")
console.log(username);
personal.username="enriquead";
var loaded = await personal.loadInbox();
var chats = await chat.getChatGroups(personal);
assert.isNotNull(chats);

})





Expand Down
6 changes: 6 additions & 0 deletions test/private.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('Private communication testing', function () {
assert.equal(comunicacion,true);
})

it("Loads messages properly",async function(){
var result = await privateComm.loadMessages("enriquead","mariodiaz98",true);


})




Expand Down
9 changes: 6 additions & 3 deletions test/public.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Private communication testing', function () {
assert.equal(rdom.length,5);

})
it("Create core file",async function(){
it("Create core file and send message",async function(){
personal.username = "mariodiaz98";
var rand = publicComm.randomString(6);
var groupName = "Testing group"+publicComm.randomString(3);
Expand All @@ -36,8 +36,11 @@ describe('Private communication testing', function () {
webId: "https://enriquead.solid.community/profile/card#me"});

publicComm.createCoreFile(personal,rand,groupName,friendList);
publicComm.sendFirstMessage(personal,friendList[0],rand,groupName);
var comunicacion = await publicComm.communicationEstablished(personal.username,friendList[0]);
assert.equal(comunicacion,true);

assert.equal(comunicacion,true);
})


})

0 comments on commit e7c0cdd

Please sign in to comment.