<commit_before>/*
This file is part of the Juju GUI, which lets users view and manage Juju
environments within a graphical interface (https://launchpad.net/juju-gui).
Copyright (C) 2017 Canonical Ltd.

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
General Public License for more details.

You should have received a copy of the GNU Affero General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

'use strict';

var juju = {components: {}}; // eslint-disable-line no-unused-vars

chai.config.includeStack = true;
chai.config.truncateThreshold = 0;

describe('HeaderHelp', function() {
  let appState;

  beforeAll(function(done) {
    // By loading this file it adds the component to the juju components.
    YUI().use('header-help', function() { done(); });
  });

  beforeEach(function() {
    appState = {
      current: {},
      changeState: sinon.stub()
    };
  });

  it('renders', function () {
    const renderer = jsTestUtils.shallowRender(
      <juju.components.HeaderHelp.prototype.wrappedComponent
        appState={appState}
        gisf={false}
        user={null} />, true);
    const output = renderer.getRenderOutput();
    const instance = renderer.getMountedInstance();

    const expected = <div className="header-menu">
        <span className={'header-menu__button'}
          onClick={instance.toggleHelpMenu}
          role="button"
          tabIndex="0"
          aria-haspopup="true"
          aria-owns="headerHelpMenu"
          aria-controls="headerHelpMenu"
          aria-expanded="false">
          <juju.components.SvgIcon name="help_16"
            className="header-menu__icon"
            size="16" />
          <span className="tooltip__tooltip--below">
            <span className="tooltip__inner tooltip__inner--up">
              Help
            </span>
          </span>
        </span>
        {''}
      </div>;

    assert.deepEqual(output, expected);
  });

  describe('menu', function () {
    const issueUrl = 'https://github.com/juju/juju-gui/issues';
    const loggedInIssueUrl = 'https://jujucharms.com/support';
    const docsUrl = 'https://jujucharms.com/docs/stable/getting-started';

    it('opens a menu when clicked', function () {
      const renderer = jsTestUtils.shallowRender(
        <juju.components.HeaderHelp.prototype.wrappedComponent
          appState={appState}
          gisf={false}
          user={null} />, true);
      const instance = renderer.getMountedInstance();
      instance.toggleHelpMenu();
      const output = renderer.getRenderOutput();

      assert.equal(output.props.children.length, 2);
      assert.deepEqual(output.props.children[0].props.className,
        'header-menu__button header-menu__show-menu');

      const expected = (<juju.components.Panel
        instanceName="header-menu__menu"
        visible={true}>
          <ul className="header-menu__menu-list" role="menubar">
            <li className="header-menu__menu-list-item
              header-menu__menu-list-item-with-link"
              role="menuitem" tabIndex="0">
              <a className="header-menu__menu-list-item-link"
                href={docsUrl}
                target="_blank">
                View Documentation</a>
            </li>
            <li className="header-menu__menu-list-item
              header-menu__menu-list-item-with-link"
              role="menuitem" tabIndex="0">
              <a className="header-menu__menu-list-item-link"
                href={issueUrl} target="_blank">File Issue</a>
            </li>
            <li className="header-menu__menu-list-item
              header-menu__menu-list-item-with-link"
              role="menuItem" tabIndex="0"
              onClick={instance._handleShortcutsLink}>
              <span className="header-menu__menu-list-item-link">
                Keyboard shortcuts
                <span className="header-menu__menu-extra-info">
                  Shift + ?
                </span>
              </span>
            </li>
          </ul>
        </juju.components.Panel>);
      expect(output.props.children[1]).toEqualJSX(expected);
    });

    it('shows the jujuchams issues page if in gisf and logged in',
      function () {
        const renderer = jsTestUtils.shallowRender(
          <juju.components.HeaderHelp.prototype.wrappedComponent
            appState={appState}
            gisf={true}
            user={{}} />, true);
        const instance = renderer.getMountedInstance();
        instance.toggleHelpMenu();
        const output = renderer.getRenderOutput();

        assert.equal(output.props.children.length, 2);
        assert.deepEqual(output.props.children[0].props.className,
          'header-menu__button header-menu__show-menu');

        const expected = (<juju.components.Panel
          instanceName="header-menu__menu"
          visible={true}>
            <ul className="header-menu__menu-list" role="menubar">
              <li className="header-menu__menu-list-item
                header-menu__menu-list-item-with-link"
                role="menuitem" tabIndex="0">
                <a className="header-menu__menu-list-item-link"
                  href={docsUrl}
                  target="_blank">
                  View Documentation</a>
              </li>
              <li className="header-menu__menu-list-item
                header-menu__menu-list-item-with-link"
                role="menuitem" tabIndex="0">
                <a className="header-menu__menu-list-item-link"
                  href={loggedInIssueUrl} target="_blank">Get Support</a>
              </li>
              <li className="header-menu__menu-list-item
                header-menu__menu-list-item-with-link"
                role="menuItem" tabIndex="0"
                onClick={instance._handleShortcutsLink}>
                <span className="header-menu__menu-list-item-link">
                  Keyboard shortcuts
                  <span className="header-menu__menu-extra-info">
                    Shift + ?
                  </span>
                </span>
              </li>
            </ul>
          </juju.components.Panel>);
        expect(output.props.children[1]).toEqualJSX(expected);
    });

    it('keyboard shortcuts link calls correct keyboard shortcut cb', () => {
      const keybindingsCallback = sinon.stub();
      const keybindings = {
        'S-/': {
          target: '#shortcut-help',
          toggle: true,
          callback: keybindingsCallback
        }
      };
      const evt = {
        stopPropagation: sinon.stub()
      }
      const div = document.createElement('div');
      div.setAttribute('id', 'shortcut-help');<commit_msg>Linting issues fixed<commit_after>/*
This file is part of the Juju GUI, which lets users view and manage Juju
environments within a graphical interface (https://launchpad.net/juju-gui).
Copyright (C) 2017 Canonical Ltd.

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
General Public License for more details.

You should have received a copy of the GNU Affero General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

'use strict';

var juju = {components: {}}; // eslint-disable-line no-unused-vars

chai.config.includeStack = true;
chai.config.truncateThreshold = 0;

describe('HeaderHelp', function() {
  let appState;

  beforeAll(function(done) {
    // By loading this file it adds the component to the juju components.
    YUI().use('header-help', function() { done(); });
  });

  beforeEach(function() {
    appState = {
      current: {},
      changeState: sinon.stub()
    };
  });

  it('renders', function () {
    const renderer = jsTestUtils.shallowRender(
      <juju.components.HeaderHelp.prototype.wrappedComponent
        appState={appState}
        gisf={false}
        user={null} />, true);
    const output = renderer.getRenderOutput();
    const instance = renderer.getMountedInstance();

    const expected = <div className="header-menu">
        <span className={'header-menu__button'}
          onClick={instance.toggleHelpMenu}
          role="button"
          tabIndex="0"
          aria-haspopup="true"
          aria-owns="headerHelpMenu"
          aria-controls="headerHelpMenu"
          aria-expanded="false">
          <juju.components.SvgIcon name="help_16"
            className="header-menu__icon"
            size="16" />
          <span className="tooltip__tooltip--below">
            <span className="tooltip__inner tooltip__inner--up">
              Help
            </span>
          </span>
        </span>
        {''}
      </div>;

    assert.deepEqual(output, expected);
  });

  describe('menu', function () {
    const issueUrl = 'https://github.com/juju/juju-gui/issues';
    const loggedInIssueUrl = 'https://jujucharms.com/support';
    const docsUrl = 'https://jujucharms.com/docs/stable/getting-started';

    it('opens a menu when clicked', function () {
      const renderer = jsTestUtils.shallowRender(
        <juju.components.HeaderHelp.prototype.wrappedComponent
          appState={appState}
          gisf={false}
          user={null} />, true);
      const instance = renderer.getMountedInstance();
      instance.toggleHelpMenu();
      const output = renderer.getRenderOutput();

      assert.equal(output.props.children.length, 2);
      assert.deepEqual(output.props.children[0].props.className,
        'header-menu__button header-menu__show-menu');

      const expected = (<juju.components.Panel
        instanceName="header-menu__menu"
        visible={true}>
          <ul className="header-menu__menu-list" role="menubar">
            <li className="header-menu__menu-list-item
              header-menu__menu-list-item-with-link"
              role="menuitem" tabIndex="0">
              <a className="header-menu__menu-list-item-link"
                href={docsUrl}
                target="_blank">
                View Documentation</a>
            </li>
            <li className="header-menu__menu-list-item
              header-menu__menu-list-item-with-link"
              role="menuitem" tabIndex="0">
              <a className="header-menu__menu-list-item-link"
                href={issueUrl} target="_blank">File Issue</a>
            </li>
            <li className="header-menu__menu-list-item
              header-menu__menu-list-item-with-link"
              role="menuItem" tabIndex="0"
              onClick={instance._handleShortcutsLink}>
              <span className="header-menu__menu-list-item-link">
                Keyboard shortcuts
                <span className="header-menu__menu-extra-info">
                  Shift + ?
                </span>
              </span>
            </li>
          </ul>
        </juju.components.Panel>);
      expect(output.props.children[1]).toEqualJSX(expected);
    });

    it('shows the jujuchams issues page if in gisf and logged in',
      function () {
        const renderer = jsTestUtils.shallowRender(
          <juju.components.HeaderHelp.prototype.wrappedComponent
            appState={appState}
            gisf={true}
            user={{}} />, true);
        const instance = renderer.getMountedInstance();
        instance.toggleHelpMenu();
        const output = renderer.getRenderOutput();

        assert.equal(output.props.children.length, 2);
        assert.deepEqual(output.props.children[0].props.className,
          'header-menu__button header-menu__show-menu');

        const expected = (<juju.components.Panel
          instanceName="header-menu__menu"
          visible={true}>
            <ul className="header-menu__menu-list" role="menubar">
              <li className="header-menu__menu-list-item
                header-menu__menu-list-item-with-link"
                role="menuitem" tabIndex="0">
                <a className="header-menu__menu-list-item-link"
                  href={docsUrl}
                  target="_blank">
                  View Documentation</a>
              </li>
              <li className="header-menu__menu-list-item
                header-menu__menu-list-item-with-link"
                role="menuitem" tabIndex="0">
                <a className="header-menu__menu-list-item-link"
                  href={loggedInIssueUrl} target="_blank">Get Support</a>
              </li>
              <li className="header-menu__menu-list-item
                header-menu__menu-list-item-with-link"
                role="menuItem" tabIndex="0"
                onClick={instance._handleShortcutsLink}>
                <span className="header-menu__menu-list-item-link">
                  Keyboard shortcuts
                  <span className="header-menu__menu-extra-info">
                    Shift + ?
                  </span>
                </span>
              </li>
            </ul>
          </juju.components.Panel>);
        expect(output.props.children[1]).toEqualJSX(expected);
      }
    );

    it('keyboard shortcuts link calls correct keyboard shortcut cb', () => {
      const keybindingsCallback = sinon.stub();
      const keybindings = {
        'S-/': {
          target: '#shortcut-help',
          toggle: true,
          callback: keybindingsCallback
        }
      };
      const evt = {
        stopPropagation: sinon.stub()
      };
      const div = document.createElement('div');
      div.setAttribute('id', 'shortcut-help');
{'fraction_non_alphanumeric': 0.11951202212922903, 'fraction_numerical': 0.0032626427406199023, 'mean_word_length': 2.1529516994633275, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 103, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, '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': '1373929', 'n_tokens_mistral': 3956, 'n_tokens_neox': 3823, 'n_words': 799}