<commit_before>Tinytest.add "Luma Component - Attribute Accessor", ( test ) ->

  class Car extends Component

  data =
    doors: 2
    color: 'red'
    options:
      performance:
        tires:
          manufacturer: "Dunlop"
          name: "<NAME>"
      convertible:
        hardTop: true

  if Meteor.isClient
    context =
      data: data
  if Meteor.isServer
    context = data

  sportsCar = new Car context

  test.equal sportsCar.data, data, "Properties should be identical after instantiation."
  test.equal sportsCar.doors(), data.doors, "Attribute accessor should return property value."
  test.equal sportsCar.color(), data.color, "Attribute accessor should return property value."
  test.equal sportsCar.options(), data.options, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance, data.options.performance, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance.tires, data.options.performance.tires, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance.tires.manufacturer, data.options.performance.tires.manufacturer, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance.tires.name, data.options.performance.tires.name, "Attribute accessor should return property value."
  test.equal sportsCar.options().convertible, data.options.convertible, "Attribute accessor should return property value."
  test.equal sportsCar.options().convertible.hardTop, data.options.convertible.hardTop, "Attribute accessor should return property value."

  try
    sportsCar.doesntExist()
  catch error
    if Meteor.isServer
      message = "Object #<Car> has no method 'doesntExist'"
    if Meteor.isClient
      message = "undefined is not a function"
    test.equal error.message, message, "Calling an undefined accessor should result in an error."

  if sportsCar.color
    test.equal true, true, "Accessor methods should serve dual purpose as conditionals."
  else test.equal true, false, "Accessor methods should serve dual purpose as conditionals."

  unless sportsCar.doesntExist
    test.equal true, true, "Accessor methods should serve dual purpose as conditionals."
  else test.equal true, false, "Accessor methods should serve dual purpose as conditionals."

  sportsCar.color "black"
  sportsCar.doors 4

  test.equal sportsCar.color(), "black", "Setting an accessor should set the property."
  test.equal sportsCar.doors(), 4, "Setting an accessor should set the property."

  sportsCar.options {}
  test.equal sportsCar.options(), {}, "Setting an accessor should set the property."

Tinytest.add "Luma Component - Mixins", ( test ) ->
  classProperties =
    find: ( id ) -> return id
    create: ( attrs ) -> return attrs

  instanceProperties =
    save: ( id ) -> return id
    destroy: ( id ) -> return true

  class User extends Component
    @extend classProperties
    @include instanceProperties

  attrs =
    name: "<NAME>"
    email: "<EMAIL>"

  user = new User()
  test.equal User.find( 1 ), 1, "Class methods mixed into a class should be present on the class."
  test.equal User.create( attrs ), attrs, "Class methods mixed into a class should be present on the class."
  test.equal user.save( 1 ), 1, "Instance methods mixed into a class should be present on instances of that class."
  test.equal user.destroy( 2 ), true, "Instance methods mixed into a class should be present on instances of that class."

  ORM =
    find: ( id ) -> return id
    create: ( attrs ) -> return attrs
    extended: ->
      @include
        save: ( id ) -> return id
        destroy: ( id ) -> return true

  class Model extends Component
    @extend ORM

  model = new Model()
  test.equal Model.find( 1 ), 1, "Class methods mixed into a class should be present on the class."
  test.equal Model.create( attrs ), attrs, "Class methods mixed into a class should be present on the class."
  test.equal model.save( 1 ), 1, "Instance methods mixed into a class should be present on instances of that class."
  test.equal model.destroy( 2 ), true, "Instance methods mixed into a class should be present on instances of that class."

  data =
    name: "<NAME>"
    email: "<EMAIL>"
    tags: [
      key: "value"
    ]

  if Meteor.isClient
    context =
      data: data
  if Meteor.isServer
    context = data
  user = new Model context

  test.equal user.name(), "<NAME>", "Attribute accessors should still function when mixins are present."
  test.equal user.email(), "<EMAIL>", "Attribute accessors should still function when mixins are present."
  test.equal user.tags()[ 0 ].key, "value", "Attribute accessors should still function when mixins are present."
  test.equal user.save( 3 ), 3, "Instance methods should still function when attribute accessors are created."
  test.equal user.destroy( 2 ), true, "Instance methods should still function when attribute accessors are created."
  test.equal Model.find( 1 ), 1, "Class methods should still function when attribute accessors are created."
  test.equal Model.create( attrs ), attrs, "Class methods should still function when attribute accessors are created."

if Meteor.isClient
  Tinytest.add "Luma Component - Extend Template", ( test ) ->
    data =
      id: 1234
      class: "example"
      name: "<NAME>"
      email: "<EMAIL>"

    ORM =
      find: ( name ) -> return Session.get name or false
      extended: ->
        @include
          save: -> Session.set @name, @email
          destroy: -> Session.set @name, undefined

    class Model extends Component
      @extend ORM

    Template.componentFixture.created = -> new Model @
    Template.componentFixture.rendered = -> @save()
    Template.componentFixture.destroyed = -> @destroyed()

    component = UI.renderWithData Template.componentFixture, data
    tI = component.templateInstance

    test.equal tI.name(), "<NAME>", "Attribute accessors should still function when mixins are present."
    test.equal tI.email(), "<EMAIL>", "Attribute accessors should still function when mixins are present."

    UI.insert component, $( '<div></div>' )

    test.equal Session.get( "<NAME>" ), tI.find( "<NAME>" ), "Component methods are first class methods of the template instance."<commit_msg>extend template tests<commit_after>Tinytest.add "Luma Component - Attribute Accessor", ( test ) ->

  class Car extends Component

  data =
    doors: 2
    color: 'red'
    options:
      performance:
        tires:
          manufacturer: "Dunlop"
          name: "<NAME>"
      convertible:
        hardTop: true

  if Meteor.isClient
    context =
      data: data
  if Meteor.isServer
    context = data

  sportsCar = new Car context

  test.equal sportsCar.data, data, "Properties should be identical after instantiation."
  test.equal sportsCar.doors(), data.doors, "Attribute accessor should return property value."
  test.equal sportsCar.color(), data.color, "Attribute accessor should return property value."
  test.equal sportsCar.options(), data.options, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance, data.options.performance, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance.tires, data.options.performance.tires, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance.tires.manufacturer, data.options.performance.tires.manufacturer, "Attribute accessor should return property value."
  test.equal sportsCar.options().performance.tires.name, data.options.performance.tires.name, "Attribute accessor should return property value."
  test.equal sportsCar.options().convertible, data.options.convertible, "Attribute accessor should return property value."
  test.equal sportsCar.options().convertible.hardTop, data.options.convertible.hardTop, "Attribute accessor should return property value."

  try
    sportsCar.doesntExist()
  catch error
    if Meteor.isServer
      message = "Object #<Car> has no method 'doesntExist'"
    if Meteor.isClient
      message = "undefined is not a function"
    test.equal error.message, message, "Calling an undefined accessor should result in an error."

  if sportsCar.color
    test.equal true, true, "Accessor methods should serve dual purpose as conditionals."
  else test.equal true, false, "Accessor methods should serve dual purpose as conditionals."

  unless sportsCar.doesntExist
    test.equal true, true, "Accessor methods should serve dual purpose as conditionals."
  else test.equal true, false, "Accessor methods should serve dual purpose as conditionals."

  sportsCar.color "black"
  sportsCar.doors 4

  test.equal sportsCar.color(), "black", "Setting an accessor should set the property."
  test.equal sportsCar.doors(), 4, "Setting an accessor should set the property."

  sportsCar.options {}
  test.equal sportsCar.options(), {}, "Setting an accessor should set the property."

Tinytest.add "Luma Component - Mixins", ( test ) ->
  classProperties =
    find: ( id ) -> return id
    create: ( attrs ) -> return attrs

  instanceProperties =
    save: ( id ) -> return id
    destroy: ( id ) -> return true

  class User extends Component
    @extend classProperties
    @include instanceProperties

  attrs =
    name: "<NAME>"
    email: "<EMAIL>"

  user = new User()
  test.equal User.find( 1 ), 1, "Class methods mixed into a class should be present on the class."
  test.equal User.create( attrs ), attrs, "Class methods mixed into a class should be present on the class."
  test.equal user.save( 1 ), 1, "Instance methods mixed into a class should be present on instances of that class."
  test.equal user.destroy( 2 ), true, "Instance methods mixed into a class should be present on instances of that class."

  ORM =
    find: ( id ) -> return id
    create: ( attrs ) -> return attrs
    extended: ->
      @include
        save: ( id ) -> return id
        destroy: ( id ) -> return true

  class Model extends Component
    @extend ORM

  model = new Model()
  test.equal Model.find( 1 ), 1, "Class methods mixed into a class should be present on the class."
  test.equal Model.create( attrs ), attrs, "Class methods mixed into a class should be present on the class."
  test.equal model.save( 1 ), 1, "Instance methods mixed into a class should be present on instances of that class."
  test.equal model.destroy( 2 ), true, "Instance methods mixed into a class should be present on instances of that class."

  data =
    name: "<NAME>"
    email: "<EMAIL>"
    tags: [
      key: "value"
    ]

  if Meteor.isClient
    context =
      data: data
  if Meteor.isServer
    context = data
  user = new Model context

  test.equal user.name(), "<NAME>", "Attribute accessors should still function when mixins are present."
  test.equal user.email(), "<EMAIL>", "Attribute accessors should still function when mixins are present."
  test.equal user.tags()[ 0 ].key, "value", "Attribute accessors should still function when mixins are present."
  test.equal user.save( 3 ), 3, "Instance methods should still function when attribute accessors are created."
  test.equal user.destroy( 2 ), true, "Instance methods should still function when attribute accessors are created."
  test.equal Model.find( 1 ), 1, "Class methods should still function when attribute accessors are created."
  test.equal Model.create( attrs ), attrs, "Class methods should still function when attribute accessors are created."

if Meteor.isClient
  Tinytest.add "Luma Component - Extend Template", ( test ) ->
    data =
      id: "unique-selector"
      class: "example"
      name: "<NAME>"
      email: "<EMAIL>"

    ORM =
      currentUser: ( key ) -> Session.get key or false
      extended: ->
        @include
          save: -> Session.set @name(), @email()
          destroy: -> Session.set @name(), undefined

    class Model extends Component
      @extend ORM

    Template.componentFixture.created = -> new Model @
    Template.componentFixture.rendered = -> @save()
    Template.componentFixture.destroyed = -> @destroy()

    component = UI.renderWithData Template.componentFixture, data
    tI = component.templateInstance

    test.equal tI.name(), "<NAME>", "Attribute accessors should still function when mixins are present."
    test.equal tI.email(), "<EMAIL>", "Attribute accessors should still function when mixins are present."

    $DOM = $( '<div id="parentNode"></div>' )
    UI.insert component, $DOM

    test.equal Model.currentUser( "<NAME>" ), "<EMAIL>" , "Calling instance method in rendered callback preserves context."

    $( "#unique-selector", $DOM ).remove()

    test.equal Model.currentUser( "<NAME>"), undefined, "Calling instance method in destroyed callback should preserve context."
{'fraction_non_alphanumeric': 0.10067061759201497, 'fraction_numerical': 0.0032751091703056767, 'mean_word_length': 3.4764397905759163, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2947902', 'n_tokens_mistral': 3495, 'n_tokens_neox': 3391, 'n_words': 1334}