<commit_before>import {watchWorkspaceItem} from '../lib/watch-workspace-item';

describe('watchWorkspaceItem', function() {
  let sub, atomEnv, workspace, component;

  beforeEach(function() {
    atomEnv = global.buildAtomEnvironment();
    workspace = atomEnv.workspace;

    component = {
      state: {},
      setState: sinon.stub().resolves(),
    };

    workspace.addOpener(uri => {
      if (uri.startsWith('atom-github://')) {
        return {
          getURI() { return uri; },
        };
      } else {
        return undefined;
      }
    });
  });

  afterEach(function() {
    sub && sub.dispose();
    atomEnv.destroy();
  });

  describe('initial state', function() {
    it('creates component state if none is present', function() {
      component.state = undefined;

      sub = watchWorkspaceItem(workspace, 'atom-github://item', component, 'aKey');
      assert.deepEqual(component.state, {aKey: false});
    });

    it('is false when the pane is not open', async function() {
      await workspace.open('atom-github://nonmatching');

      sub = watchWorkspaceItem(workspace, 'atom-github://item', component, 'someKey');
      assert.isFalse(component.state.someKey);
    });

    it('is true when the pane is already open', async function() {
      await workspace.open('atom-github://item/one');
      await workspace.open('atom-github://item/two');

      sub = watchWorkspaceItem(workspace, 'atom-github://item/one', component, 'theKey');

      assert.isTrue(component.state.theKey);
    });

    it('is true when multiple panes matching the URI pattern are open', async function() {
      await workspace.open('atom-github://item/one');
      await workspace.open('atom-github://item/two');
      await workspace.open('atom-github://nonmatch');

      sub = watchWorkspaceItem(workspace, 'atom-github://item/{pattern}', component, 'theKey');

      assert.isTrue(component.state.theKey);
    });
  });

  describe('workspace events', function() {
    it('becomes true when the pane is opened', async function() {
      sub = watchWorkspaceItem(workspace, 'atom-github://item/{pattern}', component, 'theKey');

      assert.isFalse(component.state.theKey);

      await workspace.open('atom-github://item/match');<commit_msg>Cover that last conditional :ok_hand:<commit_after>import {watchWorkspaceItem} from '../lib/watch-workspace-item';
import URIPattern from '../lib/atom/uri-pattern';

describe('watchWorkspaceItem', function() {
  let sub, atomEnv, workspace, component;

  beforeEach(function() {
    atomEnv = global.buildAtomEnvironment();
    workspace = atomEnv.workspace;

    component = {
      state: {},
      setState: sinon.stub().resolves(),
    };

    workspace.addOpener(uri => {
      if (uri.startsWith('atom-github://')) {
        return {
          getURI() { return uri; },
        };
      } else {
        return undefined;
      }
    });
  });

  afterEach(function() {
    sub && sub.dispose();
    atomEnv.destroy();
  });

  describe('initial state', function() {
    it('creates component state if none is present', function() {
      component.state = undefined;

      sub = watchWorkspaceItem(workspace, 'atom-github://item', component, 'aKey');
      assert.deepEqual(component.state, {aKey: false});
    });

    it('is false when the pane is not open', async function() {
      await workspace.open('atom-github://nonmatching');

      sub = watchWorkspaceItem(workspace, 'atom-github://item', component, 'someKey');
      assert.isFalse(component.state.someKey);
    });

    it('is true when the pane is already open', async function() {
      await workspace.open('atom-github://item/one');
      await workspace.open('atom-github://item/two');

      sub = watchWorkspaceItem(workspace, 'atom-github://item/one', component, 'theKey');

      assert.isTrue(component.state.theKey);
    });

    it('is true when multiple panes matching the URI pattern are open', async function() {
      await workspace.open('atom-github://item/one');
      await workspace.open('atom-github://item/two');
      await workspace.open('atom-github://nonmatch');

      sub = watchWorkspaceItem(workspace, 'atom-github://item/{pattern}', component, 'theKey');

      assert.isTrue(component.state.theKey);
    });

    it('accepts a preconstructed URIPattern', async function() {
      await workspace.open('atom-github://item/one');
      const u = new URIPattern('atom-github://item/{pattern}');

      sub = watchWorkspaceItem(workspace, u, component, 'theKey');
      assert.isTrue(component.state.theKey);
    });
  });

  describe('workspace events', function() {
    it('becomes true when the pane is opened', async function() {
      sub = watchWorkspaceItem(workspace, 'atom-github://item/{pattern}', component, 'theKey');

      assert.isFalse(component.state.theKey);

      await workspace.open('atom-github://item/match');
{'fraction_non_alphanumeric': 0.16070333265180944, 'fraction_numerical': 0.0, 'mean_word_length': 3.242844752818734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7038485', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1410, 'n_words': 301}