<|start_filename|>javascript/debug.js<|end_filename|>
let debugging = false

export default {
  get enabled () {
    return debugging
  },
  get disabled () {
    return !debugging
  },
  get value () {
    return debugging
  },
  set (value) {
    debugging = !!value
  },
  set debug (value) {
    debugging = !!value
  }
}


<|start_filename|>javascript/test/debug.test.js<|end_filename|>
import assert from 'assert'
import refute from './refute'
import Debug from '../debug'
import DebugInOtherFile from '../debug'

describe('Debug', () => {
  beforeEach(() => {
    Debug.set(false)
  })

  it('Debug should be turned off by default', () => {
    assert(Debug.value === false)
  })

  it('Debug can be enabled via set()', () => {
    refute(Debug.value)
    Debug.set(true)
    assert(Debug.value)
  })

  it('Debug can be disabled via set()', () => {
    refute(Debug.value)
    Debug.set(true)
    assert(Debug.value)
    Debug.set(false)
    refute(Debug.value)
  })

  it('Debug can be enabled via debug=', () => {
    refute(Debug.value)
    Debug.debug = true
    assert(Debug.value)
  })

  it('Debug can be disabled via debug=', () => {
    refute(Debug.value)
    Debug.debug = true
    assert(Debug.value)
    Debug.debug = false
    refute(Debug.value)
  })

  it('Debug value can be read by all getters', () => {
    refute(Debug.value)
    refute(Debug.enabled)
    assert(Debug.disabled)

    Debug.set(true)

    assert(Debug.value)
    assert(Debug.enabled)
    refute(Debug.disabled)
  })

  it('Debug value is synced between different instances', () => {
    refute(Debug.value)
    refute(DebugInOtherFile.value)

    Debug.set(true)

    assert(Debug.value)
    assert(DebugInOtherFile.value)

    DebugInOtherFile.set(false)

    refute(Debug.value)
    refute(DebugInOtherFile.value)
  })
})


<|start_filename|>javascript/test/utils.extractReflexName.test.js<|end_filename|>
import assert from 'assert'
import { extractReflexName } from '../utils'

describe('extractReflexName', () => {
  describe("when it includes 'Reflex'", () => {
    describe('when it includes an event name', () => {
      it('returns a reflex name', () => {
        assert(extractReflexName('click->TestReflex#create') === 'Test')
      })
    })

    describe('when it does not include an event name', () => {
      it('returns a reflex name', () => {
        assert(extractReflexName('TestReflex#create') === 'Test')
      })
    })
  })

  describe("when it does not include 'Reflex'", () => {
    describe('when it includes an event name', () => {
      it('returns a reflex name', () => {
        assert(extractReflexName('click->Test#create') === 'Test')
      })
    })

    describe('when it does not include an event name', () => {
      it('returns a reflex name', () => {
        assert(extractReflexName('Test#create') === 'Test')
      })
    })
  })

  describe("when it can't extract the reflex name", () => {
    it('returns an empty string', () => {
      assert(extractReflexName('nope') === '')
    })
  })
})


<|start_filename|>javascript/test/attributes.extractDataAttributes.test.js<|end_filename|>
import assert from 'assert'
import { JSDOM } from 'jsdom'
import { extractDataAttributes } from '../attributes'

describe('extractDataAttributes', () => {
  it('returns empty object for null', () => {
    const actual = extractDataAttributes(null)
    const expected = {}
    assert.deepStrictEqual(actual, expected)
  })

  it('returns empty object for undefined', () => {
    const actual = extractDataAttributes(undefined)
    const expected = {}
    assert.deepStrictEqual(actual, expected)
  })

  it('returns empty object for empty object', () => {
    const actual = extractDataAttributes({})
    const expected = {}
    assert.deepStrictEqual(actual, expected)
  })

  it('returns empty object for an element without attributes', () => {
    const dom = new JSDOM('<div>Test</div>')
    global.document = dom.window.document
    const element = dom.window.document.querySelector('div')
    const actual = extractDataAttributes(element)
    const expected = {}
    assert.deepStrictEqual(actual, expected)
  })

  it('returns expected data attributes for an element', () => {
    const dom = new JSDOM(
      '<div id="example" class="should not appear" data-controller="foo" data-reflex="bar" data-info="12345">Test</div>'
    )
    global.document = dom.window.document
    const element = dom.window.document.querySelector('div')
    const actual = extractDataAttributes(element)
    const expected = {
      'data-controller': 'foo',
      'data-reflex': 'bar',
      'data-info': '12345'
    }
    assert.deepStrictEqual(actual, expected)
  })
})
