<commit_before>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import expect = require('expect.js');

import {
  ServiceManager, IServiceManager
} from 'jupyter-js-services';

import {
  Context, TextModelFactory
} from '../../../lib/docregistry/context';


describe('docregistry/context', () => {

  let manager: IServiceManager;
  let factory = new TextModelFactory();

  before((done) => {
    ServiceManager.create().then(m => {
      manager = m;
      done();
    });
  }

  describe('Context', () => {

    let context: Context;

    beforeEach(() => {
      let path = 'foo';
      context = new Context({ manager, factory, path });
    });

    describe('#constructor()', () => {

      it('should create a new context', () => {

      });

    });

    describe('#kernelChanged', () => {

    });

    describe('#pathChanged', () => {

    });

    describe('#fileChanged', () => {

    });

    describe('#populated', () => {

    });

    describe('#disposed', () => {

    });

    describe('#model', () => {

    });

    describe('#kernel', () => {

    });

    describe('#path', () => {

    });

    describe('#contentsModel', () => {

    });

    describe('#kernelspecs', () => {

    });

    describe('#isPopulated', () => {

    });

    describe('#factoryName', () => {<commit_msg>wip tests<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import expect = require('expect.js');

import {
  ServiceManager, IServiceManager
} from 'jupyter-js-services';

import {
  Context, DocumentRegistry, TextModelFactory
} from '../../../lib/docregistry';


describe('docregistry/context', () => {

  let manager: IServiceManager;
  let factory = new TextModelFactory();

  before((done) => {
    ServiceManager.create().then(m => {
      manager = m;
      done();
    }).catch(done);
  });

  describe('Context', () => {

    let context: Context<DocumentRegistry.IModel>;

    beforeEach(() => {
      context = new Context({ manager, factory, path: 'foo' });
    });

    afterEach(() => {
      context.dispose();
    });

    describe('#constructor()', () => {

      it('should create a new context', () => {
        context = new Context({ manager, factory, path: 'bar' });
        expect(context).to.be.a(Context);
      });

    });

    describe('#kernelChanged', () => {

      it('should be emitted when the kernel changes', (done) => {
        let name = manager.kernelspecs.default;
        context.kernelChanged.connect((sender, args) => {
          expect(sender).to.be(context);
          expect(args.name).to.be(name);
          context.kernel.shutdown().then(() => {
            done();
          }).catch(done);
        });
        context.changeKernel({ name });
      });

    });

    describe('#pathChanged', () => {

      it('should be emitted when the path changes', (done) => {
        context.pathChanged.connect((sender, args) => {
          expect(sender).to.be(context);
          expect(args).to.be('foo');
          done();
        });
        context.setPath('foo');
      });

    });

    describe('#fileChanged', () => {

      it('should be emitted when the file is saved', (done) => {
        context.fileChanged.connect((sender, args) => {
          expect(sender).to.be(context);
          expect(args.name).to.be('foo');
          done();
        });
        context.save();
      });

    });

    describe('#populated', () => {

      it('should be emitted when the file is saved for the first time', (done) => {
        let count = 0;
        context.populated.connect((sender, args) => {
          expect(sender).to.be(context);
          expect(args).to.be(void 0);
          count++;
        });
        context.save().then(() => {
          expect(count).to.be(1);
          return context.save();
        }).then(() => {
          expect(count).to.be(1);
          done();
        }).catch(done);
      });

    });

    describe('#disposed', () => {

      it('should be emitted when the context is disposed', (done) => {
        context.disposed.connect((sender, args) => {
          expect(sender).to.be(context);
          expect(args).to.be(void 0);
          done();
        });
        context.dispose();
      });

    });

    describe('#model', () => {

      it('should be the model associated with the document', () => {
        expect(context.model.toString()).to.be('');
      });

    });

    describe('#kernel', () => {

      it('should default to `null`', () => {
        expect(context.kernel).to.be(null);
      });

      it('should be set after switching kernels', (done) => {
        let name = manager.kernelspecs.default;
        context.changeKernel({ name }).then(() => {
          expect(context.kernel.name).to.be(name);
          return context.kernel.shutdown();
        }).then(() => {
          done();
        }).catch(done);
      });

    });

    describe('#path', () => {

      it('should be the current path for the context', () => {
        expect(context.path).to.be('foo');
      });

    });

    describe('#contentsModel', () => {

      it('should be `null` before poulation', () => {
        expect(context.contentsModel).to.be(null);
      });

      it('should be set after poulation', (done) => {
        context.populated.connect(() => {
          expect(context.contentsModel.name).to.be('foo');
          done();
        });
        context.save().catch(done);
      });

    });

    describe('#kernelspecs', () => {

    });

    describe('#isPopulated', () => {

    });

    describe('#factoryName', () => {
{'fraction_non_alphanumeric': 0.19851380042462846, 'fraction_numerical': 0.0008846426043878273, 'mean_word_length': 2.210107893242476, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6596521', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1593, 'n_words': 310}