cozy / cozy-emails

Email Client for Cozy
GNU Affero General Public License v3.0
66 stars 41 forks source link

[test] fix broken client tests #874

Closed m4dz closed 8 years ago

m4dz commented 8 years ago

This PR include some client tests fixes, and (finally) enable client tests runs on CI. It also prepares RequestsStore spec.

misstick commented 8 years ago

here a solution for RECEIVE_RAW_MESSAGES test issue:

[fix] do not care about undefined or null message file: client/stores/message_store.coffee

    _updateMessages = (result={}, timestamp) ->
        {messages, conversationLength} = result

        # This prevent to override local updates
        # with older ones from server
-       messages?.forEach (message) -> _saveMessage message, timestamp
+      messages?.forEach (message) ->
+          _saveMessage message, timestamp if message
misstick commented 8 years ago

[fix] flagsSuccess test issue file: client/test/message_store.spec.js

+      const updated = {messages: [message1, message2] }
      dispatcher.dispatch({
        type: ActionTypes.MESSAGE_FLAGS_SUCCESS,
-        value: { updated: [message1, message2]  },
+        value: { updated },
      });
misstick commented 8 years ago

[feature] remove test on no-implemented feature file: client/test/message_store.spec.js

-    it('SEARCH_SUCCESS', () => {
+   it.skip('SEARCH_SUCCESS', () => {
+      // TODO: update this test when feature will be back
misstick commented 8 years ago

[fix] displayImage test file: client/test/message_store.spec.js

    it('SETTINGS_UPDATE_REQUEST', () => {
      const id1 = fixtures.message1.id;

      // Message must exist into messageStore
      assert.equal(messageStore.getByID(id1).get('id'), id1);
      assert.isUndefined(messageStore.getByID(id1).get('_displayImages'));

      // displayImage value has changed  
      dispatcher.dispatch({
        type: ActionTypes.SETTINGS_UPDATE_RESQUEST,
        value: { messageID: id1, displayImages: true },
      });
      assert.isTrue(messageStore.getByID(id1).get('_displayImages'));

      // displayImage value has changed
      dispatcher.dispatch({
        type: ActionTypes.SETTINGS_UPDATE_RESQUEST,
        value: { messageID: id1, displayImages: false },
      });
      assert.isFalse(messageStore.getByID(id1).get('_displayImages'));
    });
misstick commented 8 years ago

[test] fix getConversation typo file: client/test/message_store.spec.js

1/ fixtures have typo (for all fixtures)

-    mailboxIDs: ['inbox'],
+    mailboxIDs: { inbox: 1 },

2/ test typo

     it('getConversation', () => {
       const id11 = fixtures.message11.id;
+      const mailbox11 = _.keys(fixtures.message11.mailboxIDs)[0];
       const conversationId = fixtures.message11.conversationID;
-      const messages = messageStore.getConversation(conversationId);
+      const messages = messageStore.getConversation(conversationId, mailbox11);
       if (messages[0].get('id') === id11) {
         assert.deepEqual(messages[0].toObject(), fixtures.message11);
         assert.deepEqual(messages[1].toObject(), fixtures.message12);
@@ -337,16 +359,37 @@ describe('Message Store', () => {
         assert.deepEqual(messages[1].toObject(), fixtures.message11);
         assert.deepEqual(messages[0].toObject(), fixtures.message12);
       }
+
+      //  If conversation doesnt exist
+      // then return empty Array
+      const id5 = fixtures.message5.id;
+      const conversation5 = messageStore.getConversation(id5, 'inbox')
+      assert.deepEqual(messageStore.getConversation(id5, 'inbox'), []);
misstick commented 8 years ago

[test] fix getConversationLenth file: client/test/message_store.spec.js

     it('getConversationLength', () => {
+      const id1 = fixtures.message10.id;
       const conversationId1 = fixtures.message10.conversationID;
+
+      // Message10 should exist into messageStore
+      assert.deepEqual(messageStore.getByID(id1).toObject(), fixtures.message10);
+
+      // Its length is 1
+      let length = messageStore.getConversationLength(conversationId1);
+      assert.equal(length, 1);
+
+      const id2 = fixtures.message11.id;
       const conversationId2 = fixtures.message11.conversationID;
-      let length = messageStore.getConversationLength(conversationId2);
+
+      // Message11 should exist into messageStore
+      assert.deepEqual(messageStore.getByID(id2).toObject(), fixtures.message11);
+
+      // Its length is 2
+      length = messageStore.getConversationLength(conversationId2);
       assert.equal(length, 2);
-      length = messageStore.getConversationLength(conversationId1);
-      assert.equal(length, 1);
+
+      // Empty conversation should return length: null
       length = messageStore.getConversationLength('c5');
-      assert.isUndefined(length);
+      assert.isNull(length);
m4dz commented 8 years ago

@misstick in fix flagSuccess, const updated = {messages: [message1, message2] } will never ever work, as, if I understand properly http://github.com/m4dz/cozy-emails/blob/0ec836194b8f6d8f63232d413e38ee6c1e7ea60d/client/app/actions/router_action_creator.coffee#L233, there is no batch flaging: updated always contains only one message. Nope?

EDIT: ok, nvm, misunderstood