<commit_before>import {expect} from 'chai'
import Ember from 'ember'
const {Component} = Ember
import {$hook, initialize as initializeHook} from 'ember-hook'
import {setupComponentTest} from 'ember-mocha'
import SpreadMixin from 'ember-spread'
import hbs from 'htmlbars-inline-precompile'
import {beforeEach, describe, it} from 'mocha'

import sinon from 'sinon'

const SpreadComponent = Component.extend(SpreadMixin, {
  // == Properties ============================================================

  hook: 'spreadTest',
  layout: hbs`
    <div data-test={{hook 'spreadProperty'}}>
      {{property}}
    </div>
  `,

  // == Actions ===============================================================

  click () {
    // Note: A get is not used in this case; onClick is a function on the
    // local component, not a computed property
    this.onClick()
  }
})

describe('ember-spread', function () {
  setupComponentTest('ember-spread', {
    integration: true
  })

  let handler

  beforeEach(function () {
    initializeHook()
    this.registry.register('component:spread-test', SpreadComponent)
    handler = sinon.spy()
  })

  describe('when using the default (options) spread property', function () {
    beforeEach(function () {
      this.setProperties({
        options: {
          property: 'Neat',
          onClick: handler
        }
      })

      this.render(hbs`
        {{spread-test
          options=options
        }}
      `)
    })

    it('should bind spread properties as local properties', function () {
      expect($hook('spreadProperty').text().trim()).to.equal('Neat')
    })

    it('should bind spread functions as local functions', function () {
      // Note: In the spreadTest component above the onClick function
      // is called directly without retrieving the function using `get`
      $hook('spreadTest').click()
      expect(handler).to.have.callCount(1)
    })

    describe('and a source property changes', function () {
      beforeEach(function () {
        this.set('options.property', 'Woah')
      })

      it('should update the local property', function () {
        expect($hook('spreadProperty').text().trim()).to.equal('Woah')
      })
    })
  })

  describe('when using a custom spread property', function () {
    beforeEach(function () {
      this.setProperties({
        options: {
          property: 'Neat',
          onClick: handler
        }
      })

      this.render(hbs`
        {{spread-test
          foo=options
          spreadOptions=(hash
            property='foo'
          )
        }}
      `)
    })

    it('should bind spread properties as local properties', function () {
      expect($hook('spreadProperty').text().trim()).to.equal('Neat')
    })

    it('should bind spread functions as local functions', function () {
      // Note: In the spreadTest component above the onClick function
      // is called directly without retrieving the function using `get`
      $hook('spreadTest').click()
      expect(handler).to.have.callCount(1)
    })

    describe('and a source property changes', function () {
      beforeEach(function () {
        this.set('options.property', 'Woah')<commit_msg>tests: add tests for staticProperties, concatenatedProperties and mergedProperties<commit_after>import {expect} from 'chai'
import Ember from 'ember'
const {Component} = Ember
import {$hook, initialize as initializeHook} from 'ember-hook'
import {setupComponentTest} from 'ember-mocha'
import SpreadMixin from 'ember-spread'
import hbs from 'htmlbars-inline-precompile'
import {beforeEach, describe, it} from 'mocha'

import sinon from 'sinon'

const SpreadComponent = Component.extend(SpreadMixin, {
  // == Properties ============================================================

  mergedProperties: ['mergedProperty'],
  classNames: 'base-class',
  hook: 'spreadTest',
  layout: hbs`
    <div data-test={{hook 'spreadProperty'}}>
      {{property}}
    </div>
    <div data-test={{hook 'mergedProperty'}}>
      {{#each-in mergedProperty as |key value|}}
        {{key}}: {{value}}<br>
      {{/each-in}}
    </div>
  `,
  mergedProperty: {baseValue: true},

  // == Actions ===============================================================

  click () {
    // Note: A get is not used in this case; onClick is a function on the
    // local component, not a computed property
    this.onClick()
  }
})

describe('ember-spread', function () {
  setupComponentTest('ember-spread', {
    integration: true
  })

  let handler

  beforeEach(function () {
    initializeHook()
    this.registry.register('component:spread-test', SpreadComponent)
    handler = sinon.spy()
  })

  describe('when using the default (options) spread property', function () {
    beforeEach(function () {
      this.setProperties({
        options: {
          tagName: 'span',
          elementId: 'test-id',
          classNames: 'test-class',
          property: 'Neat',
          mergedProperty: {testValue: true},
          onClick: handler
        }
      })

      this.render(hbs`
        {{spread-test
          options=options
        }}
      `)
    })

    it('should bind spread properties as local properties', function () {
      expect($hook('spreadProperty').text().trim()).to.equal('Neat')
    })

    it('should set static properties as plain local properties', function () {
      expect($hook('spreadTest').attr('id')).to.equal('test-id')
      expect($hook('spreadTest').prop('tagName').toLowerCase()).to.equal('span')
    })

    it('should concatenate properties, if they are listed as concatenatedProperties', function () {
      expect($hook('spreadTest').attr('class')).to.include('base-class').and.include('test-class')
    })

    it('should merge properties, if they are listed as mergedProperties', function () {
      expect($hook('mergedProperty').text()).to.include('baseValue').and.include('testValue')
    })

    it('should bind spread functions as local functions', function () {
      // Note: In the spreadTest component above the onClick function
      // is called directly without retrieving the function using `get`
      $hook('spreadTest').click()
      expect(handler).to.have.callCount(1)
    })

    describe('and a source property changes', function () {
      beforeEach(function () {
        this.set('options.property', 'Woah')
      })

      it('should update the local property', function () {
        expect($hook('spreadProperty').text().trim()).to.equal('Woah')
      })
    })
  })

  describe('when using a custom spread property', function () {
    beforeEach(function () {
      this.setProperties({
        options: {
          tagName: 'span',
          elementId: 'test-id',
          classNames: 'test-class',
          property: 'Neat',
          mergedProperty: {testValue: true},
          onClick: handler
        }
      })

      this.render(hbs`
        {{spread-test
          foo=options
          spreadOptions=(hash
            property='foo'
          )
        }}
      `)
    })

    it('should bind spread properties as local properties', function () {
      expect($hook('spreadProperty').text().trim()).to.equal('Neat')
    })

    it('should set static properties as plain local properties', function () {
      expect($hook('spreadTest').attr('id')).to.equal('test-id')
      expect($hook('spreadTest').prop('tagName').toLowerCase()).to.equal('span')
    })

    it('should concatenate properties, if they are listed as concatenatedProperties', function () {
      expect($hook('spreadTest').attr('class')).to.include('base-class').and.include('test-class')
    })

    it('should merge properties, if they are listed as mergedProperties', function () {
      expect($hook('mergedProperty').text()).to.include('baseValue').and.include('testValue')
    })

    it('should bind spread functions as local functions', function () {
      // Note: In the spreadTest component above the onClick function
      // is called directly without retrieving the function using `get`
      $hook('spreadTest').click()
      expect(handler).to.have.callCount(1)
    })

    describe('and a source property changes', function () {
      beforeEach(function () {
        this.set('options.property', 'Woah')
{'fraction_non_alphanumeric': 0.16808355598736943, 'fraction_numerical': 0.00048579062424095217, 'mean_word_length': 3.0072992700729926, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3303193', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2177, 'n_words': 561}