Code coverage report for js/dialogSystem.jsx

# All files / js dialogSystem.jsx

41.67% Statements 5/12
0% Branches 0/9
100% Functions 1/1
41.67% Lines 5/12

    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

    1x
    1x

    1x
    1x

    1x

     'use strict'

    import hub from './hub'
    import { DialogChangedEvent } from './events'

    class DialogSystem {
      constructor () {
        this._dialogInstance = null
      }

      // invoked by the application once the dialog has been created.
      notifyDialogInstance (dialog) {
        this._dialogInstance = dialog
      }

      // given a dialog class this will instruct the application to bring up
      // the dialog and display it.
      showDialog (dialog, options) {
        // if the current dialog prevents navigation, then we just silently
        // will not show the dialog.
        if (!this.preventNavigation()) {
          hub.emit(new DialogChangedEvent({
            dialog: dialog,
            dialogOptions: options || {}
          }))
        }
      }

      // tells the application to dismiss the current dialog.
      dismissDialog () {
        if (!this.preventNavigation()) {
          hub.emit(new DialogChangedEvent({
            currentDialog: null
          }))
        }
      }

      // indicates if a dialog is shown
      dialogIsOpen () {
        return !!this._dialogInstance
      }

      // returns true if the current dialog prevents navigation.
      preventNavigation () {
        return (
          this._dialogInstance &&
          this._dialogInstance.preventNavigation !== undefined &&
          this._dialogInstance.preventNavigation()
        )
      }
    }

    const dialogSystem = new DialogSystem()

    export default dialogSystem