Blame view

test/unit/specs/message.spec.js 1.99 KB
23e20abf   Sergio Crisostomo   DRY message/index...
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
  import {createVue, destroyVM, waitForIt} from '../util';
  
  describe('Message.vue', () => {
    let vm;
    afterEach(() => {
      destroyVM(vm);
    });
  
    it('should open a info message by default', done => {
      vm = createVue({render: () => {}});
      const testMessage = 'Hello world!';
      let messageContainer = null;
      vm.$Message.info({
        content: testMessage,
        duration: 200 // too long so we can test
      });
  
      const selector = '.ivu-message-notice-content-text .ivu-message-info';
      const checkMessageOpens = () => (messageContainer = document.querySelector(selector));
  
      waitForIt(checkMessageOpens, function() {
        expect(messageContainer.textContent.trim()).to.equal(testMessage);
        messageContainer.parentElement.removeChild(messageContainer);
        done();
      });
    });
  
    it('should open specific messages of different types', function(done) {
      vm = createVue({render: () => {}});
      const testMessage = type => `Hello world! this is a ${type} message`;
      const tests = ['info', 'success', 'warning', 'error', 'loading'].reduce((tests, type) => {
        return tests.concat({
          type: type,
          message: testMessage(type),
          class: 'ivu-message-' + type
        });
      }, []);
      let domElements = [];
  
      for (const {type, message} of tests) {
        vm.$Message[type]({
          content: message,
          duration: 10 // long so we can test
        });
      }
  
      const checkAllMessageOpens = () => {
        domElements = document.querySelectorAll('.ivu-message-custom-content');
        return domElements.length == tests.length && domElements;
      };
  
      waitForIt(checkAllMessageOpens, function() {
        const verify = {};
        domElements.forEach(el => {
          const message = el.textContent.trim();
          const test = tests.find(test => test.message == message);
          verify[test.type] = true;
          expect(el.classList.contains(test.class)).to.equal(true);
        });
        expect(Object.keys(verify).length).to.equal(tests.length);
        done();
      });
    });
  });