<commit_before>import Immutable from "immutable";
import { remote } from "electron";

import { from } from "rxjs/observable/from";
import { of } from "rxjs/observable/of";

import * as nativeWindow from "../../src/notebook/native-window";
import { state as stateModule } from "@nteract/core";

const path = require("path");

describe("tildify", () => {
  test("returns an empty string if given no path", () => {
    expect(nativeWindow.tildify()).toBe("");
  });
  test("replaces the user directory with ~", () => {
    const fixture = path.join(remote.app.getPath("home"), "test-notebooks");
    const result = nativeWindow.tildify(fixture);
    if (process.platform === "win32") {
      expect(result).toBe(fixture);
    } else {
      expect(result).toContain("~");
    }
  });
});

describe("setTitleFromAttributes", () => {
  test("sets the window title", () => {
    // Set up our "Electron window"
    const win = {
      setRepresentedFilename: jest.fn(),
      setDocumentEdited: jest.fn(),
      setTitle: jest.fn()
    };

    remote.getCurrentWindow = jest.fn();
    remote.getCurrentWindow.mockReturnValue(win);

    const titleObject = {
      fullpath: "/tmp/test.ipynb",
      kernelStatus: "busy",
      modified: true
    };
    nativeWindow.setTitleFromAttributes(titleObject);

    expect(win.setTitle).toBeCalled();
  });
});

describe("createTitleFeed", () => {
  test("creates an observable that updates title attributes for modified notebook", async function() {
    const kernelRef = stateModule.createKernelRef();
    const currentContentRef = stateModule.createContentRef();

    const notebook = new Immutable.Map().setIn(
      ["metadata", "kernelspec", "display_name"],
      "python3000"
    );
    const state = {
      core: stateModule.makeStateRecord({
        kernelRef,
        currentContentRef,
        entities: stateModule.makeEntitiesRecord({
          contents: stateModule.makeContentsRecord({
            byRef: Immutable.Map({
              // $FlowFixMe: This really is a content ref, Flow can't handle typing it though
              [currentContentRef]: stateModule.makeNotebookContentRecord({
                filepath: "titled.ipynb"
              })
            })
          }),
          kernels: stateModule.makeKernelsRecord({
            byRef: Immutable.Map({
              // $FlowFixMe: This really is a kernel ref, Flow can't handle typing it though
              [kernelRef]: stateModule.makeRemoteKernelRecord({
                status: "not connected"
              })
            })
          })
        })
      }),
      app: stateModule.makeAppRecord()
    };

    const state$ = of(state);

    const attributes = await nativeWindow
      .createTitleFeed(currentContentRef, state$)
      .toPromise();
    expect(attributes).toEqual({
      modified: false,
      fullpath: "titled.ipynb",
      kernelStatus: "not connected"
    });
  });
});
<commit_msg>rely on plain currentRef naming<commit_after>import Immutable from "immutable";
import { remote } from "electron";

import { from } from "rxjs/observable/from";
import { of } from "rxjs/observable/of";

import * as nativeWindow from "../../src/notebook/native-window";
import { state as stateModule } from "@nteract/core";

const path = require("path");

describe("tildify", () => {
  test("returns an empty string if given no path", () => {
    expect(nativeWindow.tildify()).toBe("");
  });
  test("replaces the user directory with ~", () => {
    const fixture = path.join(remote.app.getPath("home"), "test-notebooks");
    const result = nativeWindow.tildify(fixture);
    if (process.platform === "win32") {
      expect(result).toBe(fixture);
    } else {
      expect(result).toContain("~");
    }
  });
});

describe("setTitleFromAttributes", () => {
  test("sets the window title", () => {
    // Set up our "Electron window"
    const win = {
      setRepresentedFilename: jest.fn(),
      setDocumentEdited: jest.fn(),
      setTitle: jest.fn()
    };

    remote.getCurrentWindow = jest.fn();
    remote.getCurrentWindow.mockReturnValue(win);

    const titleObject = {
      fullpath: "/tmp/test.ipynb",
      kernelStatus: "busy",
      modified: true
    };
    nativeWindow.setTitleFromAttributes(titleObject);

    expect(win.setTitle).toBeCalled();
  });
});

describe("createTitleFeed", () => {
  test("creates an observable that updates title attributes for modified notebook", async function() {
    const kernelRef = stateModule.createKernelRef();
    const contentRef = stateModule.createContentRef();

    const notebook = new Immutable.Map().setIn(
      ["metadata", "kernelspec", "display_name"],
      "python3000"
    );
    const state = {
      core: stateModule.makeStateRecord({
        kernelRef,
        entities: stateModule.makeEntitiesRecord({
          contents: stateModule.makeContentsRecord({
            byRef: Immutable.Map({
              // $FlowFixMe: This really is a content ref, Flow can't handle typing it though
              [contentRef]: stateModule.makeNotebookContentRecord({
                filepath: "titled.ipynb"
              })
            })
          }),
          kernels: stateModule.makeKernelsRecord({
            byRef: Immutable.Map({
              // $FlowFixMe: This really is a kernel ref, Flow can't handle typing it though
              [kernelRef]: stateModule.makeRemoteKernelRecord({
                status: "not connected"
              })
            })
          })
        })
      }),
      app: stateModule.makeAppRecord()
    };

    const state$ = of(state);

    const attributes = await nativeWindow
      .createTitleFeed(contentRef, state$)
      .toPromise();
    expect(attributes).toEqual({
      modified: false,
      fullpath: "titled.ipynb",
      kernelStatus: "not connected"
    });
  });
});

{'fraction_non_alphanumeric': 0.13703576341127924, 'fraction_numerical': 0.0020632737276478678, 'mean_word_length': 2.6816455696202532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3107494', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1630, 'n_words': 377}