{"size": 2185, "ext": "js", "max_stars_repo_path": "src/plugins/CaptionsTogglePlugin.spec.js", "max_stars_repo_name": "BaileyBrightman/SpringRollContainer", "max_stars_repo_stars_event_min_datetime": "2018-06-12T13:02:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T22:08:49.000Z", "max_issues_repo_path": "src/plugins/CaptionsTogglePlugin.spec.js", "max_issues_repo_name": "BaileyBrightman/SpringRollContainer", "max_issues_repo_issues_event_min_datetime": "2015-12-14T20:03:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T15:07:37.000Z", "max_forks_repo_path": "src/plugins/CaptionsTogglePlugin.spec.js", "max_forks_repo_name": "BaileyBrightman/SpringRollContainer", "max_forks_repo_forks_event_min_datetime": "2015-12-15T02:21:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-09T16:48:34.000Z"}
{"max_stars_count": 5, "max_issues_count": 30, "max_forks_count": 7, "avg_line_length": 36.4166666667, "max_line_length": 87, "alphanum_fraction": 0.6892448513}
import { CaptionsTogglePlugin } from './CaptionsTogglePlugin';
import { Bellhop } from 'bellhop-iframe';
import { makeButton } from '../../TestingUtils';

describe('CaptionsTogglePlugin', () => {
  let cp;

  before(() => {
    const buttonOne = makeButton('button_test_one');
    const buttonTwo = makeButton('button_test_two');

    document.body.append(buttonOne, buttonTwo);

    cp = new CaptionsTogglePlugin('#button_test_one, #button_test_two');
    cp.preload({ client: new Bellhop() });
  });

  it('construct', () => {
    expect(cp._captionsButtons[0].button).to.be.instanceof(HTMLButtonElement);
    expect(cp._captionsButtons[0].button.style.display).to.equal('');
    expect(cp._captionsButtons[0].button.classList.contains('disabled')).to.be.false;
  });

  it('.captionsButtonClick()', () => {
    cp._captionsButtons[0].button.click();
    expect(cp.captionsMuted).to.equal(true);
    //check that the data attribute is being set correctly for both control elements
    expect(cp._captionsButtons[0].button.classList.contains('muted')).to.equal(true);
    expect(cp._captionsButtons[1].button.classList.contains('muted')).to.equal(true);

    cp._captionsButtons[1].button.click();
    expect(cp.captionsMuted).to.equal(false);
    expect(cp._captionsButtons[0].button.classList.contains('unmuted')).to.equal(true);
    expect(cp._captionsButtons[1].button.classList.contains('unmuted')).to.equal(true);
  });

  it('should work without any controls', () => {
    //set up empty plugin
    cp = new CaptionsTogglePlugin();
    cp.preload({ client: new Bellhop() });
    cp.init();
    cp.client.trigger('features', {});
  });

  it('should work with HTMLElement as parameter', () => {
    //Does not include radio buttons as they only accept strings
    const buttonOne = makeButton('#button_test_one');
    document.body.appendChild(buttonOne);

    cp = new CaptionsTogglePlugin(buttonOne);
    cp.preload({ client: new Bellhop() });

    expect(cp.captionsMuted).to.equal(false);

    cp._captionsButtons[0].button.click();
    expect(cp.captionsMuted).to.equal(true);
    expect(cp._captionsButtons[0].button.classList.contains('muted')).to.equal(true);
  });
});
