<commit_before>import FragmentAnchor from '../dom-anchor-fragment'

describe('FragmentAnchor', () => {
  before(() => {
    fixture.setBase('test/fixtures')
  });

  beforeEach(() => {
    fixture.load('test.html');
  });

  afterEach(() => {
    fixture.cleanup();
  });

  it('is a function', () => {
    assert.isFunction(FragmentAnchor)
  });

  it('requires an id argument to the constructor', () => {
    let construct = () => new FragmentAnchor();
    assert.throws(construct,'required parameter');
    let instance = new FragmentAnchor('foo');
    assert.instanceOf(instance, FragmentAnchor);
  });

  describe('fromRange', () => {
    it('requires a range argument', () => {
      let construct = () => FragmentAnchor.fromRange();
      assert.throws(construct, 'required parameter');
    });

    it('throws an error if no fragment identifier is found', () => {
      let range = global.document.createRange();
      range.selectNode(fixture.el);
      assert.throws(() => FragmentAnchor.fromRange(range), 'no fragment');
    });

    it('returns a FragmentAnchor if the common ancestor has an id', () => {
      let range = global.document.createRange();
      range.selectNode(fixture.el.childNodes[0]);
      let anchor = FragmentAnchor.fromRange(range);
      assert.equal(anchor.id, fixture.el.id);
    });

    it('returns a FragmentAnchor if any ancestor has an id', () => {
      let range = global.document.createRange();
      range.selectNode(fixture.el.childNodes[0].childNodes[0]);
      let anchor = FragmentAnchor.fromRange(range);
      assert.equal(anchor.id, fixture.el.id);
    });
  });
});<commit_msg>Tests for fromSelector<commit_after>import FragmentAnchor from '../dom-anchor-fragment'

describe('FragmentAnchor', () => {
  before(() => {
    fixture.setBase('test/fixtures')
  });

  beforeEach(() => {
    fixture.load('test.html');
  });

  afterEach(() => {
    fixture.cleanup();
  });

  it('is a function', () => {
    assert.isFunction(FragmentAnchor)
  });

  it('requires an id argument to the constructor', () => {
    let construct = () => new FragmentAnchor();
    assert.throws(construct,'required parameter');
    let instance = new FragmentAnchor('foo');
    assert.instanceOf(instance, FragmentAnchor);
  });

  describe('fromRange', () => {
    it('requires a range argument', () => {
      let construct = () => FragmentAnchor.fromRange();
      assert.throws(construct, 'required parameter');
    });

    it('throws an error if no fragment identifier is found', () => {
      let range = global.document.createRange();
      range.selectNode(fixture.el);
      assert.throws(() => FragmentAnchor.fromRange(range), 'no fragment');
    });

    it('returns a FragmentAnchor if the common ancestor has an id', () => {
      let range = global.document.createRange();
      range.selectNode(fixture.el.childNodes[0]);
      let anchor = FragmentAnchor.fromRange(range);
      assert.equal(anchor.id, fixture.el.id);
    });

    it('returns a FragmentAnchor if any ancestor has an id', () => {
      let range = global.document.createRange();
      range.selectNode(fixture.el.childNodes[0].childNodes[0]);
      let anchor = FragmentAnchor.fromRange(range);
      assert.equal(anchor.id, fixture.el.id);
    });
  });

  describe('fromSelector', () => {
    it('requires a selector argument', () => {
      let construct = () => FragmentAnchor.fromSelector();
      assert.throws(construct, 'required parameter');
    });

    it('returns a FragmentAnchor from the value of the selector', () => {
      let selector = {
        value: 'foo',
      };
      let anchor = FragmentAnchor.fromSelector(selector);
      assert(anchor.id === selector.value);
    });
  });
});
{'fraction_non_alphanumeric': 0.16845781837721654, 'fraction_numerical': 0.0016120365394948952, 'mean_word_length': 3.3240418118466897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '1189474', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1034, 'n_words': 229}