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

mozilla / blurts-server / ea160b21-282b-46f8-8bfe-f53fd3b88c61

pending completion
ea160b21-282b-46f8-8bfe-f53fd3b88c61

push

circleci

GitHub
Merge pull request #2848 from mozilla/MNTOR-1188/breaches-email-count

282 of 1374 branches covered (20.52%)

Branch coverage included in aggregate %.

12 of 12 new or added lines in 4 files covered. (100.0%)

959 of 3725 relevant lines covered (25.74%)

4.18 hits per line

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

0.0
/src/client/js/partials/add-email.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
let dialogEl, form
6

7
function init () {
8
  dialogEl = document.querySelector('dialog[data-partial="add-email"]')
×
9
  if (!dialogEl) return
×
10

11
  form = dialogEl.querySelector('form')
×
12
  form.addEventListener('submit', handleSubmit)
×
13
  dialogEl.addEventListener('close', kill)
×
14
}
15

16
async function handleSubmit (e) {
17
  e.preventDefault()
×
18

19
  try {
×
20
    form.elements['email-submit'].toggleAttribute('disabled', true)
×
21
    const res = await fetch('/api/v1/user/email', {
×
22
      headers: {
23
        'Content-Type': 'application/json',
24
        'x-csrf-token': form.elements['csrf-token'].value
25
      },
26
      mode: 'same-origin',
27
      method: 'POST',
28
      body: JSON.stringify({
29
        email: form.elements['email-address'].value
30
      })
31
    })
32

33
    if (!res.ok) throw new Error('Bad fetch response')
×
34

35
    const { newEmailCount } = await res.json()
×
36

37
    renderSuccess({
×
38
      email: form.elements['email-address'].value,
39
      newEmailCount
40
    })
41
  } catch (e) {
42
    console.error('Could not add new email.', e)
×
43
  } finally {
44
    form.elements['email-submit'].toggleAttribute('disabled', false)
×
45
  }
46
}
47

48
function renderSuccess (data) {
49
  const content = dialogEl.querySelector('template[data-success]').content.cloneNode(true)
×
50
  const messageEl = content.querySelector('p.add-email-success')
×
51

52
  messageEl.style.setProperty('--form-height', `${form.clientHeight}px`)
×
53
  messageEl.querySelector('.current-email').textContent = data.email
×
54
  form.replaceWith(content)
×
55
  dialogEl.dispatchEvent(new CustomEvent('email-added', {
×
56
    bubbles: true,
57
    detail: data
58
  }))
59
}
60

61
function kill () {
62
  form.removeEventListener('submit', handleSubmit)
×
63
  dialogEl.removeEventListener('close', kill)
×
64
}
65

66
export default init
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

© 2025 Coveralls, Inc