<commit_before>import { click, fillIn, settled, waitFor, visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { module, test } from 'qunit';

import { defer } from 'rsvp';

import { setupMirage } from 'ember-cli-mirage/test-support';
import { authenticateSession } from 'ember-simple-auth/test-support';

import * as MockFlight from 'skylines/mirage/vcr/flights/87296';

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

  module('unauthenticated', function () {
    test('shows existing comments', async function (assert) {
      this.server.get('/api/flights/87296/json', MockFlight.JSON);
      this.server.get('/api/flights/87296', MockFlight.EXTENDED);

      await visit('/flights/87296');
      await click('[data-test-sidebar-tab="comments"]');
      assert.dom('[data-test-comment]').exists({ count: 1 });
      assert.dom('[data-test-comment]').hasText('<NAME>:\xa0 8-o');
      assert.dom('[data-test-add-comment]').doesNotExist();
    });
  });

  module('authenticated', function (hooks) {
    hooks.beforeEach(async function () {
      await authenticateSession({
        settings: {
          altitudeUnit: 0,
          club: null,
          distanceUnit: 1,
          email: '<EMAIL>',
          firstName: 'John',
          followers: 107,
          following: 128,
          id: 1,
          lastName: 'Doe',
          liftUnit: 0,
          name: '<NAME>',
          speedUnit: 1,
          trackingCallsign: 'JD',
          trackingDelay: 0,
          trackingKey: '<KEY>',
        },
      });
    });

    test('shows existing comments and can add a new comment', async function (assert) {
      this.server.get('/api/flights/87296/json', MockFlight.JSON);
      this.server.get('/api/flights/87296', MockFlight.EXTENDED);

      this.server.post('/api/flights/87296/comments', function (schema, request) {
        let payload = JSON.parse(request.requestBody);
        assert.step(`add-comment(${payload.text})`);
      });

      await visit('/flights/87296');
      await click('[data-test-sidebar-tab="comments"]');
      assert.dom('[data-test-comment]').exists({ count: 1 });
      assert.dom('[data-test-comment]').hasText('<NAME>:\xa0 8-o');
      assert.dom('[data-test-add-comment]').exists();

      await fillIn('[data-test-add-comment] [data-test-input]', 'This is a great flight! 🎉');
      await click('[data-test-add-comment] [data-test-submit]');
      assert.dom('[data-test-comment]').exists({ count: 2 });<commit_msg>tests/comments: Use mirage factory to generate test user<commit_after>import { click, fillIn, settled, waitFor, visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { module, test } from 'qunit';

import { defer } from 'rsvp';

import { setupMirage } from 'ember-cli-mirage/test-support';
import { authenticateSession } from 'ember-simple-auth/test-support';

import * as MockFlight from 'skylines/mirage/vcr/flights/87296';

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

  module('unauthenticated', function () {
    test('shows existing comments', async function (assert) {
      this.server.get('/api/flights/87296/json', MockFlight.JSON);
      this.server.get('/api/flights/87296', MockFlight.EXTENDED);

      await visit('/flights/87296');
      await click('[data-test-sidebar-tab="comments"]');
      assert.dom('[data-test-comment]').exists({ count: 1 });
      assert.dom('[data-test-comment]').hasText('Jane Doe:\xa0 8-o');
      assert.dom('[data-test-add-comment]').doesNotExist();
    });
  });

  module('authenticated', function (hooks) {
    hooks.beforeEach(async function () {
      let user = this.server.create('user', {
        firstName: 'John',
        lastName: 'Doe',
      });

      let userSerializer = this.server.serializerOrRegistry.serializerFor(user);

      await authenticateSession({
        settings: userSerializer.serialize(user).user,
      });
    });

    test('shows existing comments and can add a new comment', async function (assert) {
      this.server.get('/api/flights/87296/json', MockFlight.JSON);
      this.server.get('/api/flights/87296', MockFlight.EXTENDED);

      this.server.post('/api/flights/87296/comments', function (schema, request) {
        let payload = JSON.parse(request.requestBody);
        assert.step(`add-comment(${payload.text})`);
      });

      await visit('/flights/87296');
      await click('[data-test-sidebar-tab="comments"]');
      assert.dom('[data-test-comment]').exists({ count: 1 });
      assert.dom('[data-test-comment]').hasText('Jane Doe:\xa0 8-o');
      assert.dom('[data-test-add-comment]').exists();

      await fillIn('[data-test-add-comment] [data-test-input]', 'This is a great flight! 🎉');
      await click('[data-test-add-comment] [data-test-submit]');
      assert.dom('[data-test-comment]').exists({ count: 2 });
{'fraction_non_alphanumeric': 0.1747689835275211, 'fraction_numerical': 0.02129369224588188, 'mean_word_length': 3.310822510822511, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '5549723', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1566, 'n_words': 288}