• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uiv-lib / uiv / 7172571949

11 Dec 2023 04:31PM UTC coverage: 86.79%. Remained the same
7172571949

push

github

web-flow
chore(deps): update dependency @babel/preset-env to v7.23.6

859 of 1065 branches covered (0.0%)

Branch coverage included in aggregate %.

1539 of 1698 relevant lines covered (90.64%)

185.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.33
/src/services/notification/Notification.js
1
import { spliceIfExist } from '../../utils/array.utils';
2
import {
3
  isFunction,
4
  isExist,
5
  isString,
6
  hasOwnProperty,
7
} from '../../utils/object.utils';
8
import Notification from '../../components/notification/Notification.vue';
9
import { PLACEMENTS } from '../../constants/notification.constants';
10
import { h, render, reactive } from 'vue';
11

12
const queues = reactive({
27✔
13
  [PLACEMENTS.TOP_LEFT]: [],
14
  [PLACEMENTS.TOP_RIGHT]: [],
15
  [PLACEMENTS.BOTTOM_LEFT]: [],
16
  [PLACEMENTS.BOTTOM_RIGHT]: [],
17
});
18

19
const destroy = (queue, { vNode, container }) => {
27✔
20
  // console.log('destroyNotification')
21
  render(null, container);
20✔
22
  spliceIfExist(queue, vNode.component.ctx);
20✔
23
};
24

25
const init = (options, cb, resolve = null, reject = null) => {
27!
26
  const container = document.createElement('div');
29✔
27
  const placement = options.placement;
29✔
28
  const queue = queues[placement];
29✔
29
  // check if placement is valid
30
  if (!isExist(queue)) {
29✔
31
    return;
1✔
32
  }
33
  /* istanbul ignore else */
34
  // `error` alias of `danger`
35
  if (options.type === 'error') {
28!
36
    options.type = 'danger';
×
37
  }
38
  const vNode = h(Notification, {
28✔
39
    queue,
40
    placement,
41
    ...options,
42
    cb(msg) {
43
      destroy(queue, { vNode, container });
20✔
44
      if (isFunction(cb)) {
20✔
45
        cb(msg);
1✔
46
      } else if (resolve && reject) {
19!
47
        resolve(msg);
19✔
48
      }
49
    },
50
  });
51
  render(vNode, container);
28✔
52
  document.body.appendChild(container.firstElementChild);
28✔
53
  queue.push(vNode.component.ctx);
28✔
54
};
55

56
// eslint-disable-next-line default-param-last
57
const _notify = (options = {}, cb) => {
27✔
58
  // simplify usage: pass string as option.content
59
  if (isString(options)) {
29✔
60
    options = {
9✔
61
      content: options,
62
    };
63
  }
64
  // set default placement as top-right
65
  if (!isExist(options.placement)) {
29✔
66
    options.placement = PLACEMENTS.TOP_RIGHT;
24✔
67
  }
68
  return new Promise((resolve, reject) => {
29✔
69
    init(options, cb, resolve, reject);
29✔
70
  });
71
};
72

73
function _notify2(type, args) {
74
  if (isString(args)) {
2✔
75
    _notify({
1✔
76
      content: args,
77
      type,
78
    });
79
  } else {
80
    _notify({ ...args, type });
1✔
81
  }
82
}
83

84
const notify = Object.defineProperties(_notify, {
27✔
85
  success: {
86
    configurable: false,
87
    writable: false,
88
    value(args) {
89
      _notify2('success', args);
×
90
    },
91
  },
92
  info: {
93
    configurable: false,
94
    writable: false,
95
    value(args) {
96
      _notify2('info', args);
×
97
    },
98
  },
99
  warning: {
100
    configurable: false,
101
    writable: false,
102
    value(args) {
103
      _notify2('warning', args);
1✔
104
    },
105
  },
106
  danger: {
107
    configurable: false,
108
    writable: false,
109
    value(args) {
110
      _notify2('danger', args);
×
111
    },
112
  },
113
  error: {
114
    configurable: false,
115
    writable: false,
116
    value(args) {
117
      _notify2('danger', args);
1✔
118
    },
119
  },
120
  dismissAll: {
121
    configurable: false,
122
    writable: false,
123
    value() {
124
      for (const key in queues) {
×
125
        /* istanbul ignore else */
126
        if (hasOwnProperty(queues, key)) {
×
127
          queues[key].forEach((instance) => {
×
128
            instance.onDismissed();
×
129
          });
130
        }
131
      }
132
    },
133
  },
134
});
135

136
export default { notify };
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc