<commit_before>import { module, test } from 'qunit';
import { currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupAuthentication } from 'ilios-common';
import page from 'ilios/tests/pages/search';
import dashboardPage from 'ilios/tests/pages/dashboard';

module('Acceptance | search', function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  hooks.beforeEach(async function () {
    await setupAuthentication({}, true);
    this.server.get('application/config', function () {
      return {
        config: {
          searchEnabled: true,
        },
      };
    });
  });

  test('visiting /search', async function (assert) {
    assert.expect(8);
    const input = 'hello';

    this.server.get('api/search/v1/curriculum', (schema, { queryParams }) => {
      assert.ok(queryParams.q);
      assert.strictEqual(queryParams.q, input);

      return {
        results: {
          autocomplete: [],
          courses: [],
        },
      };
    });

    await page.visit();
    assert.strictEqual(currentURL(), '/search');
    await page.globalSearch.searchBox.input(input);
    assert.strictEqual(currentURL(), '/search', 'entering input value does not update query param');
    await page.globalSearch.searchBox.clickIcon();
    assert.strictEqual(page.globalSearch.searchBox.inputValue, input);
    assert.strictEqual(currentURL(), `/search?q=${input}`, 'triggering search updates query param');
  });

  test('search with special chars #4752', async function (assert) {
    assert.expect(4);

    const input = 'H&L+foo=bar';

    this.server.get('api/search/v1/curriculum', () => {
      return {
        results: {
          autocomplete: [],
          courses: [],
        },
      };
    });

    await page.visit();
    assert.strictEqual(currentURL(), '/search');
    await page.globalSearch.searchBox.input(input);
    assert.strictEqual(currentURL(), '/search', 'entering input value does not update query param');
    await page.globalSearch.searchBox.clickIcon();
    assert.strictEqual(currentURL(), `/search?q=${encodeURIComponent(input)}`);
    assert.strictEqual(page.globalSearch.searchBox.inputValue, input);
  });

  test('search with special chars from dashboard #4752', async function (assert) {
    assert.expect(3);

    const input = 'H&L+foo=bar';

    this.server.get('api/search/v1/curriculum', () => {
      return {
        results: {
          autocomplete: [],
          courses: [],
        },
      };
    });
    await dashboardPage.visit();
    assert.strictEqual(currentURL(), '/dashboard/week');
    await dashboardPage.iliosHeader.searchBox.input(input);
    await dashboardPage.iliosHeader.searchBox.clickIcon();
    assert.strictEqual(currentURL(), `/search?page=1&q=${encodeURIComponent(input)}`);<commit_msg>Remove page param from search test<commit_after>import { module, test } from 'qunit';
import { currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { setupAuthentication } from 'ilios-common';
import page from 'ilios/tests/pages/search';
import dashboardPage from 'ilios/tests/pages/dashboard';

module('Acceptance | search', function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  hooks.beforeEach(async function () {
    await setupAuthentication({}, true);
    this.server.get('application/config', function () {
      return {
        config: {
          searchEnabled: true,
        },
      };
    });
  });

  test('visiting /search', async function (assert) {
    assert.expect(8);
    const input = 'hello';

    this.server.get('api/search/v1/curriculum', (schema, { queryParams }) => {
      assert.ok(queryParams.q);
      assert.strictEqual(queryParams.q, input);

      return {
        results: {
          autocomplete: [],
          courses: [],
        },
      };
    });

    await page.visit();
    assert.strictEqual(currentURL(), '/search');
    await page.globalSearch.searchBox.input(input);
    assert.strictEqual(currentURL(), '/search', 'entering input value does not update query param');
    await page.globalSearch.searchBox.clickIcon();
    assert.strictEqual(page.globalSearch.searchBox.inputValue, input);
    assert.strictEqual(currentURL(), `/search?q=${input}`, 'triggering search updates query param');
  });

  test('search with special chars #4752', async function (assert) {
    assert.expect(4);

    const input = 'H&L+foo=bar';

    this.server.get('api/search/v1/curriculum', () => {
      return {
        results: {
          autocomplete: [],
          courses: [],
        },
      };
    });

    await page.visit();
    assert.strictEqual(currentURL(), '/search');
    await page.globalSearch.searchBox.input(input);
    assert.strictEqual(currentURL(), '/search', 'entering input value does not update query param');
    await page.globalSearch.searchBox.clickIcon();
    assert.strictEqual(currentURL(), `/search?q=${encodeURIComponent(input)}`);
    assert.strictEqual(page.globalSearch.searchBox.inputValue, input);
  });

  test('search with special chars from dashboard #4752', async function (assert) {
    assert.expect(3);

    const input = 'H&L+foo=bar';

    this.server.get('api/search/v1/curriculum', () => {
      return {
        results: {
          autocomplete: [],
          courses: [],
        },
      };
    });
    await dashboardPage.visit();
    assert.strictEqual(currentURL(), '/dashboard/week');
    await dashboardPage.iliosHeader.searchBox.input(input);
    await dashboardPage.iliosHeader.searchBox.clickIcon();
    assert.strictEqual(currentURL(), `/search?q=${encodeURIComponent(input)}`);
{'fraction_non_alphanumeric': 0.15289256198347106, 'fraction_numerical': 0.004993112947658402, 'mean_word_length': 3.328614008941878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '223058', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1707, 'n_words': 324}