Sha256: a8f9d11d621ccd4c48c91b8f35168b0da90424badeaa2b689cba3d43896176a2

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

{addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers

testGroup "localized", ->
  for id in ["one", "two", "past", "future"]
    test id, ->
      assertLocalized id

  test "date", ->
    assertLocalized "date", "date"

  test "unparseable time", ->
    el = addTimeEl format: "%Y", datetime: ":("
    setText el, "2013"
    assert.equal getText(el), "2013"


assertLocalized = (id, type = "time") ->
  switch type
    when "time"
      momentFormat = "MMMM D, YYYY h:mma"
      compare = "toString"
    when "date"
      momentFormat = "MMMM D, YYYY"
      compare = "dayOfYear"

  el = document.getElementById id

  assert.ok datetime = el.getAttribute "datetime"
  assert.ok local = getText el
  assert.equal el.getAttribute("aria-label"), local

  datetimeParsed = moment datetime
  localParsed = moment local, momentFormat

  assert.ok datetimeParsed.isValid()
  assert.ok localParsed.isValid()
  assert.equal datetimeParsed[compare](), localParsed[compare]()

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/local_time-2.1.0/test/javascripts/src/local_time_test.coffee
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/local_time-2.1.0/test/javascripts/src/local_time_test.coffee
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/local_time-2.1.0/test/javascripts/src/local_time_test.coffee
local_time-2.1.0 test/javascripts/src/local_time_test.coffee
local_time-2.0.1 test/javascripts/src/local_time_test.coffee