<commit_before>import { describe, it, context, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from '../../helpers/start-app';
import destroyApp from '../../helpers/destroy-app';
import { mockSetup, mockTeardown, mock, mockFindAll, mockQuery, mockCreate,
  mockUpdate, buildList } from 'ember-data-factory-guy';
import { authenticateSession } from 'frontend/tests/helpers/ember-simple-auth';

describe('Acceptance | find broadcasts/close login window', function() {
  let application, broadcasts, broadcastsMock, impressionUpdateMock;

  beforeEach(function() {
    application = startApp();
    mockSetup();
    broadcastsMock = mockQuery('broadcast');
    impressionUpdateMock = mockCreate('impression');
    mockFindAll('station');
    mockFindAll('medium');
  });


  afterEach(function() {
    mockTeardown();
    destroyApp(application);
  });


  context('given 12 broadcasts', function() {
    beforeEach(function() {
      broadcasts = buildList('broadcast', 12).add({
        meta: {
          'total-pages': 2,
          'total-count': 12}
      });
      broadcastsMock.returns({json: broadcasts});
    });

    context('unauthenticated user', function() {
      beforeEach(function() {
      });

      describe('visit /find-broadcasts', function(){
        it('does not show the login dialog', function() {
          visit('/find-broadcasts/');
          return andThen(() => {
            expect(find('.auth0-lock')).to.have.length(0);
          });
        })

        describe('click on the next button', function(){
          it('sends no requests to the backend', function() {
            visit('/find-broadcasts/');
            click('.find-broadcasts-navigation-next');
            return andThen(() => {
              expect(impressionUpdateMock.timesCalled).to.equal(0);
            });
          })
        })
      })
    })

    context('authenticated user', function() {
      beforeEach(function() {
        const sessionData = {idToken : 1};
        authenticateSession(application, sessionData);
      });

      describe('visit /find-broadcast', function(){
        it('sends a parameter ?mark_as_seen=true', function() {
          broadcastsMock = mockQuery('broadcast');
          visit('/find-broadcasts/');
          return andThen(() => {
            expect(broadcastsMock.timesCalled).to.equal(1);
          });
        });
      });

      describe('click on support button', function(){
        it('creates a positive impression', function() {
          visit('/find-broadcasts/');
          impressionUpdateMock = mockCreate('impression').match({
            response: 'positive'
          });
          click('.decision-card-support-button');
          return andThen(() => {
            expect(impressionUpdateMock.timesCalled).to.equal(1);
          });
        })
      })
    });
  })
});<commit_msg>Fix test setup in frontend<commit_after>import { describe, it, context, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from '../../helpers/start-app';
import destroyApp from '../../helpers/destroy-app';
import { mockSetup, mockTeardown, mockFindAll, mockQuery, mockCreate,
  buildList } from 'ember-data-factory-guy';
import { authenticateSession } from 'frontend/tests/helpers/ember-simple-auth';

describe('Acceptance | find broadcasts/close login window', function() {
  let application, broadcasts, broadcastsMock, impressionUpdateMock;

  beforeEach(function() {
    application = startApp();
    mockSetup();
    mockFindAll('station');
    mockFindAll('medium');
  });


  afterEach(function() {
    mockTeardown();
    destroyApp(application);
  });


  context('given 12 broadcasts', function() {
    beforeEach(function() {
      broadcasts = buildList('broadcast', 12).add({
        meta: {
          'total-pages': 2,
          'total-count': 12}
      });
    });

    context('unauthenticated user', function() {
      beforeEach(function() {
        broadcastsMock = mockQuery('broadcast');
        broadcastsMock.returns({json: broadcasts});
        impressionUpdateMock = mockCreate('impression');
      });

      describe('visit /find-broadcasts', function(){
        it('does not show the login dialog', function() {
          visit('/find-broadcasts/');
          return andThen(() => {
            expect(find('.auth0-lock')).to.have.length(0);
          });
        })

        describe('click on the next button', function(){
          it('sends no requests to the backend', function() {
            visit('/find-broadcasts/');
            click('.find-broadcasts-navigation-next');
            return andThen(() => {
              expect(impressionUpdateMock.timesCalled).to.equal(0);
            });
          })
        })
      })
    })

    context('authenticated user', function() {
      beforeEach(function() {
        const sessionData = {idToken : 1};
        authenticateSession(application, sessionData);
      });

      describe('visit /find-broadcast', function(){
        it('sends a parameter ?mark_as_seen=true', function() {
          broadcastsMock = mockQuery('broadcast');
          broadcastsMock.withSomeParams({
            mark_as_seen: true,
          });
          visit('/find-broadcasts/');
          return andThen(() => {
            expect(broadcastsMock.timesCalled).to.equal(1);
          });
        });
      });

      describe('click on support button', function(){
        it('creates a positive impression', function() {
          broadcastsMock = mockQuery('broadcast');
          broadcastsMock.returns({json: broadcasts});
          visit('/find-broadcasts/');
          impressionUpdateMock = mockCreate('impression').match({
            response: 'positive'
          });
          click('.decision-card-support-button');
          return andThen(() => {
            expect(impressionUpdateMock.timesCalled).to.equal(1);
          });
        })
      })
    });
  })
});
{'fraction_non_alphanumeric': 0.15145924186514592, 'fraction_numerical': 0.004360952700436095, 'mean_word_length': 2.5076470588235296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '258825', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1567, 'n_words': 315}