<commit_before>import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find, findAll, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { setupIntl } from 'ember-intl/test-support';

module('Integration | Component | new programyear', function(hooks) {
  setupRenderingTest(hooks);
  setupIntl(hooks);

  test('it renders', async function(assert) {
    assert.expect(8);
    this.set('years', [{ label: '2018-2019', value: 2018}, {label: '2019-2020', value: 2019}]);
    await render(hbs`<NewProgramyear
      @cancel={{noop}}
      @save={{noop}}
      @availableAcademicYears={{this.years}}
    />`);
    const label = find('[data-test-newprogramyear-startyear] label');
    const options = findAll('[data-test-newprogramyear-startyear] option');
    const saveBtn = find('.buttons .done');
    const cancelBtn = find('.buttons .cancel');

    assert.dom(label).hasText('Academic Year:');
    assert.equal(options.length, 2);
    assert.dom(options[0]).hasText('2018-2019');
    assert.dom(options[0]).hasValue('2018');
    assert.dom(options[1]).hasText('2019-2020');
    assert.dom(options[1]).hasValue('2019');
    assert.ok(saveBtn);
    assert.ok(cancelBtn);
  });

  test('cancel', async function(assert) {
    assert.expect(1);
    this.set('cancel', () => {
      assert.ok(true, 'cancel action fired.');
    });
    this.set('years', [{ label: '2018-2019', value: 2018}, {label: '2019-2020', value: 2019}]);
    await render(hbs`<NewProgramyear
      @save={{noop}}
      @cancel={{this.cancel}}
      @availableAcademicYears={{this.years}}
    />`);
    const cancelBtn = find('.buttons .cancel');
    await click(cancelBtn);
  });

  test('save', async function(assert) {
    assert.expect(1);
    this.set('save', async (startYear) => {
      assert.equal(startYear, '2018');
    });
    this.set('years', [{ label: '2018-2019', value: 2018}, {label: '2019-2020', value: 2019}]);
    await render(hbs`<NewProgramyear
      @save={{this.save}}
      @cancel={{noop}}
      @availableAcademicYears={{this.years}}
    />`);
    const saveBtn = find('.buttons .done');
    await click(saveBtn);
  });
});<commit_msg>fix up new programyear component and add test for year ranges in academic-year picker.<commit_after>import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find, findAll, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { setupIntl } from 'ember-intl/test-support';

module('Integration | Component | new programyear', function(hooks) {
  setupRenderingTest(hooks);
  setupIntl(hooks);

  hooks.beforeEach(function() {
    this.currentYear = (new Date()).getFullYear();
  });

  test('it renders', async function(assert) {
    await render(hbs`<NewProgramyear
      @cancel={{noop}}
      @save={{noop}}
      @academicYearCrossesCalendarYearBoundaries={{false}}
    />`);
    const label = find('[data-test-newprogramyear-startyear] label');
    const options = findAll('[data-test-newprogramyear-startyear] option');
    const saveBtn = find('.buttons .done');
    const cancelBtn = find('.buttons .cancel');
    assert.dom(label).hasText('Academic Year:');
    assert.equal(options.length, 10);
    assert.dom(options[0]).hasText((this.currentYear - 5).toString());
    assert.dom(options[0]).hasValue((this.currentYear - 5).toString());
    assert.dom(options[9]).hasText((this.currentYear + 4).toString());
    assert.dom(options[9]).hasValue((this.currentYear + 4).toString());
    assert.ok(saveBtn);
    assert.ok(cancelBtn);
  });

  test('academic-years dropdown shows year ranges if application config enables it', async function(assert) {
    await render(hbs`<NewProgramyear
      @cancel={{noop}}
      @save={{noop}}
      @academicYearCrossesCalendarYearBoundaries={{true}}
    />`);
    const options = findAll('[data-test-newprogramyear-startyear] option');
    assert.dom(options[0]).hasText(`${this.currentYear - 5} - ${this.currentYear - 4}`);
    assert.dom(options[0]).hasValue((this.currentYear - 5).toString());
    assert.dom(options[9]).hasText(`${this.currentYear + 4} - ${this.currentYear + 5}`);
    assert.dom(options[9]).hasValue((this.currentYear + 4).toString());
  });

  test('cancel', async function(assert) {
    assert.expect(1);
    this.set('cancel', () => {
      assert.ok(true, 'cancel action fired.');
    });
    await render(hbs`<NewProgramyear
      @save={{noop}}
      @cancel={{this.cancel}}
      @academicYearCrossesCalendarYearBoundaries={{false}}
    />`);
    const cancelBtn = find('.buttons .cancel');
    await click(cancelBtn);
  });

  test('save', async function(assert) {
    assert.expect(1);
    this.set('save', async (startYear) => {
      assert.equal(startYear, (this.currentYear - 5).toString());
    });
    await render(hbs`<NewProgramyear
      @save={{this.save}}
      @cancel={{noop}}
      @academicYearCrossesCalendarYearBoundaries={{false}}
    />`);
    const saveBtn = find('.buttons .done');
    await click(saveBtn);
  });
});
{'fraction_non_alphanumeric': 0.18466353677621283, 'fraction_numerical': 0.025625978090766822, 'mean_word_length': 4.047384007897334, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, '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': '6124229', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1630, 'n_words': 295}