<commit_before>import expect from "expect.js";
import { actions, selectors, createStore } from "../../utils/test-head";

const mockThreadClient = {
  evaluate: (script, { frameId }) => {
    return new Promise((resolve, reject) => {
      resolve("bla");
    });
  }
};

describe("expressions", () => {
  it("should add an expression", () => {
    const { dispatch, getState } = createStore();

    dispatch(actions.addExpression("foo"));
    dispatch(actions.addExpression("bar", { visible: false }));

    expect(selectors.getExpressions(getState()).size).to.be(2);
    expect(selectors.getVisibleExpressions(getState()).size).to.be(1);
  });

  it("should update an expression", () => {
    const { dispatch, getState } = createStore();

    dispatch(actions.addExpression("foo"));
    const expression = selectors.getExpression(getState(), "foo");
    dispatch(actions.updateExpression("bar", expression));

    expect(selectors.getExpression(getState(), "bar").input).to.be("bar");
  });

  it("should delete an expression", () => {
    const { dispatch, getState } = createStore();

    dispatch(actions.addExpression("foo"));
    dispatch(actions.addExpression("bar", { visible: false }));

    expect(selectors.getExpressions(getState()).size).to.be(2);

    const expression = selectors.getExpression(getState(), "foo");
    dispatch(actions.deleteExpression(expression));

    expect(selectors.getExpressions(getState()).size).to.be(1);
    expect(selectors.getExpression(getState(), "bar").input).to.be("bar");
  });

  it("should evaluate expressions", async () => {
    const { dispatch, getState } = createStore(mockThreadClient);
    const frameId = "baa";

    dispatch(actions.addExpression("foo"));
    dispatch(actions.addExpression("bar", { visible: false }));

    expect(selectors.getExpression(getState(), "foo").value).to.be(null);
    expect(selectors.getExpression(getState(), "bar").value).to.be(null);

    await dispatch(actions.evaluateExpressions(frameId))

    expect(selectors.getExpression(getState(), "foo").value).to.be("bla");
    expect(selectors.getExpression(getState(), "bar").value).to.be("bla");
  });

});<commit_msg>lint fix<commit_after>import expect from "expect.js";
import { actions, selectors, createStore } from "../../utils/test-head";

const mockThreadClient = {
  evaluate: (script, { frameId }) => {
    return new Promise((resolve, reject) => {
      resolve("bla");
    });
  }
};

describe("expressions", () => {
  it("should add an expression", () => {
    const { dispatch, getState } = createStore();

    dispatch(actions.addExpression("foo"));
    dispatch(actions.addExpression("bar", { visible: false }));

    expect(selectors.getExpressions(getState()).size).to.be(2);
    expect(selectors.getVisibleExpressions(getState()).size).to.be(1);
  });

  it("should update an expression", () => {
    const { dispatch, getState } = createStore();

    dispatch(actions.addExpression("foo"));
    const expression = selectors.getExpression(getState(), "foo");
    dispatch(actions.updateExpression("bar", expression));

    expect(selectors.getExpression(getState(), "bar").input).to.be("bar");
  });

  it("should delete an expression", () => {
    const { dispatch, getState } = createStore();

    dispatch(actions.addExpression("foo"));
    dispatch(actions.addExpression("bar", { visible: false }));

    expect(selectors.getExpressions(getState()).size).to.be(2);

    const expression = selectors.getExpression(getState(), "foo");
    dispatch(actions.deleteExpression(expression));

    expect(selectors.getExpressions(getState()).size).to.be(1);
    expect(selectors.getExpression(getState(), "bar").input).to.be("bar");
  });

  it("should evaluate expressions", async () => {
    const { dispatch, getState } = createStore(mockThreadClient);
    const frameId = "baa";

    dispatch(actions.addExpression("foo"));
    dispatch(actions.addExpression("bar", { visible: false }));

    expect(selectors.getExpression(getState(), "foo").value).to.be(null);
    expect(selectors.getExpression(getState(), "bar").value).to.be(null);
    await dispatch(actions.evaluateExpressions(frameId))

    expect(selectors.getExpression(getState(), "foo").value).to.be("bla");
    expect(selectors.getExpression(getState(), "bar").value).to.be("bla");
  });

});
{'fraction_non_alphanumeric': 0.18860055607043558, 'fraction_numerical': 0.0018535681186283596, 'mean_word_length': 4.794630872483221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1664503', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1247, 'n_words': 197}