# All files / docs utils.js

15.79% Statements 3/19
100% Branches 0/0
14.29% Functions 1/7
15.79% Lines 3/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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

    1x

    1x
    8x

     import React from 'react'
    import ReactDOM from 'react-dom'
    import IntentExample from '../react/IntentOpener/IntentExample'
    import translations from './fixtures/en.json'
    import get from 'lodash/get'

    /** Fake cozy.client.intents.create to demonstrate features in Styleguide */
    export const fakeIntentCreate = (action, doctype, options) => {
      let res
      const p = new Promise(resolve => {
        res = resolve
      })
      p.start = (node, onFrameLoaded) => {
        const iframe = document.createElement('iframe')
        iframe.onload = () => {
          onFrameLoaded()

          const onComplete = () => {
            node.removeChild(iframe)
            res({ result: 'OK' })
          }

          // Copy all styles to the iframe
          Array.from(document.querySelectorAll('style')).forEach(node => {
            const copy = node.cloneNode(true)
            iframe.contentDocument.head.appendChild(copy)
          })

          ReactDOM.render(
            React.createElement(IntentExample, { onComplete, action, doctype, options }),
            iframe.contentDocument.body
          )
        }
        node.appendChild(iframe)
        return p
      }
      return p
    }

    export const t = (path) => {
      return get(translations, path)
    }