<commit_before>define([
  'client/preprocessors/module_actions'
], function (applyModuleActions) {
  describe('Module actions', function() {

    var originalModernizr = applyModuleActions.Modernizr;
    var moreInfoLink;
    var ul;

    beforeEach(function() {
      $('body').append($('<section><aside class="more-info" id="module1"><span class="more-info-link"></span><ul><li>'));
      moreInfoLink = $('.more-info-link');
      ul = $('.more-info ul');
    });

    describe('touch behaviour', function() {

      beforeEach(function() {
        applyModuleActions.Modernizr = {
          touch: true
        };
      });

      afterEach(function() {
        applyModuleActions.Modernizr = originalModernizr;
        $('.more-info').remove();
      });

      it('should show a callout on touch', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
      });

      it('should toggle the callout on repeated touches', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        moreInfoLink.trigger('touchend');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close the callout when the user touches somewhere else on the page", function () {
        applyModuleActions();
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        $('body').trigger('touchend');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close other open callouts on touch", function () {
        $('body').append($('<section><aside class="more-info" id="module2"><span class="more-info-link"></span><ul><li>'));
        applyModuleActions();

        $('#module1 .more-info-link').trigger('touchend');
        expect($('#module1 ul')).toHaveClass('js-clicked');
        expect($('#module2 ul')).not.toHaveClass('js-clicked');

        $('#module2 .more-info-link').trigger('touchend');
        expect($('#module1 ul')).not.toHaveClass('js-clicked');
        expect($('#module2 ul')).toHaveClass('js-clicked');
      });

      it("should not close the callout when the user touches the info box", function () {
        applyModuleActions();
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        ul.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        ul.find('li').trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        $('body').trigger('touchend');
        expect(ul).not.toHaveClass('js-clicked');
      });

    });

    describe("non-touch behaviour", function () {

      beforeEach(function() {
        applyModuleActions.Modernizr = {
          touch: false
        };
      });

      afterEach(function() {
        applyModuleActions.Modernizr = originalModernizr;
        $('.more-info').remove();
      });

      it('should show a callout on click', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
      });

      it('should toggle the callout on repeated clicks', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
        moreInfoLink.trigger('click');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close the callout when the user clicks somewhere else on the page", function () {
        applyModuleActions();
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
        $('body').trigger('click');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close other open callouts on click", function () {
        $('body').append($('<section><aside class="more-info" id="module2"><span class="more-info-link"></span><ul><li>'));
        applyModuleActions();

        $('#module1 .more-info-link').trigger('click');
        expect($('#module1 ul')).toHaveClass('js-clicked');
        expect($('#module2 ul')).not.toHaveClass('js-clicked');

        $('#module2 .more-info-link').trigger('click');
        expect($('#module1 ul')).not.toHaveClass('js-clicked');
        expect($('#module2 ul')).toHaveClass('js-clicked');
      });

      it("should not close the callout when the user clicks the info box", function () {
        applyModuleActions();
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
        ul.trigger('click');
        expect(ul).toHaveClass('js-clicked');
        ul.find('li').trigger('click');
        expect(ul).toHaveClass('js-clicked');
        $('body').trigger('click');
        expect(ul).not.toHaveClass('js-clicked');
      });<commit_msg>tests for anchor clicking<commit_after>define([
  'client/preprocessors/module_actions'
], function (applyModuleActions) {
  describe('Module actions', function() {

    var originalModernizr = applyModuleActions.Modernizr;
    var moreInfoLink;
    var ul;

    beforeEach(function() {
      $('body').append($('<section><aside class="more-info" id="module1"><span class="more-info-link"></span><ul><li><a>'));
      moreInfoLink = $('.more-info-link');
      ul = $('.more-info ul');
    });

    describe('touch behaviour', function() {

      beforeEach(function() {
        applyModuleActions.Modernizr = {
          touch: true
        };
      });

      afterEach(function() {
        applyModuleActions.Modernizr = originalModernizr;
        $('.more-info').remove();
      });

      it('should show a callout on touch', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
      });

      it('should toggle the callout on repeated touches', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        moreInfoLink.trigger('touchend');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close the callout when the user touches somewhere else on the page", function () {
        applyModuleActions();
        moreInfoLink.trigger('touchend');
        expect(ul).toHaveClass('js-clicked');
        $('body').trigger('touchend');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close other open callouts on touch", function () {
        $('body').append($('<section><aside class="more-info" id="module2"><span class="more-info-link"></span><ul><li>'));
        applyModuleActions();

        $('#module1 .more-info-link').trigger('touchend');
        expect($('#module1 ul')).toHaveClass('js-clicked');
        expect($('#module2 ul')).not.toHaveClass('js-clicked');

        $('#module2 .more-info-link').trigger('touchend');
        expect($('#module1 ul')).not.toHaveClass('js-clicked');
        expect($('#module2 ul')).toHaveClass('js-clicked');
      });

      describe("when the target is not an anchor", function () {
        it("should not close the callout when the user touches the info box", function () {
          applyModuleActions();
          moreInfoLink.trigger('touchend');
          expect(ul).toHaveClass('js-clicked');
          ul.trigger('touchend');
          expect(ul).toHaveClass('js-clicked');
          ul.find('li').trigger('touchend');
          expect(ul).toHaveClass('js-clicked');
          $('body').trigger('touchend');
          expect(ul).not.toHaveClass('js-clicked');
        });
      });
      describe("when the target is an anchor", function () {
        it("should not close the callout when the user touches the info box", function () {
          applyModuleActions();
          moreInfoLink.trigger('touchend');
          expect(ul).toHaveClass('js-clicked');
          ul.find('a').trigger('touchend');
          expect(ul).not.toHaveClass('js-clicked');
        });
      });

    });

    describe("non-touch behaviour", function () {

      beforeEach(function() {
        applyModuleActions.Modernizr = {
          touch: false
        };
      });

      afterEach(function() {
        applyModuleActions.Modernizr = originalModernizr;
        $('.more-info').remove();
      });

      it('should show a callout on click', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
      });

      it('should toggle the callout on repeated clicks', function() {
        applyModuleActions();
        expect(ul).not.toHaveClass('js-clicked');
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
        moreInfoLink.trigger('click');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close the callout when the user clicks somewhere else on the page", function () {
        applyModuleActions();
        moreInfoLink.trigger('click');
        expect(ul).toHaveClass('js-clicked');
        $('body').trigger('click');
        expect(ul).not.toHaveClass('js-clicked');
      });

      it("should close other open callouts on click", function () {
        $('body').append($('<section><aside class="more-info" id="module2"><span class="more-info-link"></span><ul><li>'));
        applyModuleActions();

        $('#module1 .more-info-link').trigger('click');
        expect($('#module1 ul')).toHaveClass('js-clicked');
        expect($('#module2 ul')).not.toHaveClass('js-clicked');

        $('#module2 .more-info-link').trigger('click');
        expect($('#module1 ul')).not.toHaveClass('js-clicked');
        expect($('#module2 ul')).toHaveClass('js-clicked');
      });

      describe("when the target is not an anchor", function () {
        it("should not close the callout when the user clicks the info box", function () {
          applyModuleActions();
          moreInfoLink.trigger('click');
          expect(ul).toHaveClass('js-clicked');
          ul.trigger('click');
          expect(ul).toHaveClass('js-clicked');
          ul.find('li').trigger('click');
          expect(ul).toHaveClass('js-clicked');
          $('body').trigger('click');
          expect(ul).not.toHaveClass('js-clicked');
        });
      });

      describe("when the target is an anchor", function () {
        it("should not close the callout when the user clicks the info box", function () {
          applyModuleActions();
          moreInfoLink.trigger('click');
          expect(ul).toHaveClass('js-clicked');
          ul.find('a').trigger('click');
          expect(ul).not.toHaveClass('js-clicked');
        });
      });
{'fraction_non_alphanumeric': 0.17969533886709843, 'fraction_numerical': 0.0027364772416309403, 'mean_word_length': 2.8322264942327857, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, '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': '6032736', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3127, 'n_words': 525}