summaryrefslogtreecommitdiff
path: root/javascript/videojs/test/unit/error-display.test.js
blob: 802483c7994d5196cad226a5b82d73528ab078aa (plain)
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
/* eslint-env qunit */
import TestHelpers from './test-helpers.js';

QUnit.module('ErrorDisplay');

QUnit.test('should update errorDisplay when several errors occur in succession', function(assert) {
  const player = TestHelpers.makePlayer({ techOrder: ['html5'] });
  const events = {
    beforemodalopen: 0,
    beforemodalclose: 0,
    modalopen: 0,
    modalclose: 0
  };

  player.errorDisplay.on(
    ['beforemodalopen', 'beforemodalclose', 'modalopen', 'modalclose'],
    ({ type }) => {
      events[type] += 1;
    }
  );

  // Dummy case for initial state
  assert.strictEqual(player.error(), null, 'error is null');
  assert.strictEqual(
    player.errorDisplay.contentEl().textContent,
    '',
    'error display contentEl textContent is empty'
  );
  assert.strictEqual(events.beforemodalopen, 0, 'beforemodalopen was not called');
  assert.strictEqual(events.modalopen, 0, 'modalopen was not called');
  assert.strictEqual(events.beforemodalclose, 0, 'beforemodalclose was not called');
  assert.strictEqual(events.modalclose, 0, 'modalclose was not called');

  // Case for first error
  player.error('Error 1');

  assert.strictEqual(player.error().message, 'Error 1', 'error has message');
  assert.strictEqual(
    player.errorDisplay.contentEl().textContent,
    'Error 1',
    'error display contentEl textContent has content'
  );
  assert.strictEqual(events.beforemodalopen, 1, 'beforemodalopen was called once');
  assert.strictEqual(events.modalopen, 1, 'modalopen was called once');
  assert.strictEqual(events.beforemodalclose, 0, 'beforemodalclose was not called');
  assert.strictEqual(events.modalclose, 0, 'modalclose was not called');

  // Case for second error
  player.error('Error 2');

  assert.strictEqual(player.error().message, 'Error 2', 'error has new message');
  assert.strictEqual(
    player.errorDisplay.contentEl().textContent,
    'Error 2',
    'error display contentEl textContent has been updated with the new error message'
  );
  assert.strictEqual(events.beforemodalopen, 1, 'beforemodalopen was called once');
  assert.strictEqual(events.modalopen, 1, 'modalopen has been called once');
  assert.strictEqual(events.beforemodalclose, 0, 'beforemodalclose was not called');
  assert.strictEqual(events.modalclose, 0, 'modalclose was not called');

  player.dispose();
});