<commit_before>import "jest";
import { createLocalVue, shallow, mount } from "@vue/test-utils";
import curi from "@curi/core";
import InMemory from "@hickory/in-memory";
import CuriPlugin from "../src/plugin";

describe("CuriPlugin", () => {
  const history = InMemory();
  const routes = [];
  const router = curi(history, routes);

  describe("$router", () => {
    it("Adds the router to global Vue vars as $router", () => {
      const Vue = createLocalVue();
      const FakeComponent = {
        render: function(h) {
          return h("div");
        }
      };
      Vue.use(CuriPlugin, { router });

      const wrapper = shallow(FakeComponent, {
        localVue: Vue
      });

      expect(wrapper.vm.$router).toBe(router);
    });
  });

  describe("$curi", () => {
    it("Adds $curi property to all components", done => {
      const Vue = createLocalVue();
      const FakeComponent = {
        render: function(h) {
          return h("div");
        }
      };
      router.respond(({ response, navigation }) => {
        Vue.use(CuriPlugin, { router });

        const wrapper = shallow(FakeComponent, {
          localVue: Vue
        });

        expect(wrapper.vm.$curi.response).toBe(response);
        expect(wrapper.vm.$curi.navigation).toBe(navigation);

        done();
      });
    });

    describe("reactive properties", () => {
      function makeFake(done) {
        return {
          render: function(h) {
            // need to include response to trigger re-render
            return h("div", {}, this.$curi.response.location.pathname);
          },
          mounted: function() {
            expect(this.$curi.response.location.pathname).toBe("/");
          },
          updated: function() {
            expect(this.$curi.response.location.pathname).toBe("/another-one");
            done();
          }
        };
      }

      let history, router;
      const routes = [];

      beforeEach(() => {
        history = InMemory();
        router = curi(history, routes);
      });

      it("re-renders when updating curi object", done => {
        const Vue = createLocalVue();
        const FakeComponent = makeFake(done);

        let wrapper;
        Vue.use(CuriPlugin, { router });

        if (!wrapper) {
          wrapper = shallow(FakeComponent, {
            localVue: Vue
          });
          router.history.push("/another-one");
        }
      });

      it("re-renders nested components", done => {
        const Vue = createLocalVue();
        const FakeComponent = makeFake(done);

        let wrapper;
        Vue.use(CuriPlugin, { router });

        if (!wrapper) {
          wrapper = mount(
            {
              template: "<div><FakeComponent /></div>",
              components: { FakeComponent }
            },
            {
              localVue: Vue
            }
          );
          router.history.push("/another-one");
        }
      });
    });<commit_msg>Don't sync Vue tests<commit_after>import "jest";
import { createLocalVue, shallow, mount } from "@vue/test-utils";
import curi from "@curi/core";
import InMemory from "@hickory/in-memory";
import CuriPlugin from "../src/plugin";

describe("CuriPlugin", () => {
  const history = InMemory();
  const routes = [];
  const router = curi(history, routes);

  describe("$router", () => {
    it("Adds the router to global Vue vars as $router", () => {
      const Vue = createLocalVue();
      const FakeComponent = {
        render: function(h) {
          return h("div");
        }
      };
      Vue.use(CuriPlugin, { router });

      const wrapper = shallow(FakeComponent, {
        localVue: Vue
      });

      expect(wrapper.vm.$router).toBe(router);
    });
  });

  describe("$curi", () => {
    it("Adds $curi property to all components", done => {
      const Vue = createLocalVue();
      const FakeComponent = {
        render: function(h) {
          return h("div");
        }
      };
      router.respond(({ response, navigation }) => {
        Vue.use(CuriPlugin, { router });

        const wrapper = shallow(FakeComponent, {
          localVue: Vue
        });

        expect(wrapper.vm.$curi.response).toBe(response);
        expect(wrapper.vm.$curi.navigation).toBe(navigation);

        done();
      });
    });

    describe("reactive properties", () => {
      function makeFake(done) {
        return {
          render: function(h) {
            // need to include response to trigger re-render
            return h("div", {}, this.$curi.response.location.pathname);
          },
          mounted: function() {
            expect(this.$curi.response.location.pathname).toBe("/");
          },
          updated: function() {
            expect(this.$curi.response.location.pathname).toBe("/another-one");
            done();
          }
        };
      }

      let history, router;
      const routes = [];

      beforeEach(() => {
        history = InMemory();
        router = curi(history, routes);
      });

      it("re-renders when updating curi object", done => {
        const Vue = createLocalVue();
        const FakeComponent = makeFake(done);

        let wrapper;
        Vue.use(CuriPlugin, { router });

        if (!wrapper) {
          wrapper = shallow(FakeComponent, {
            localVue: Vue,
            sync: false
          });
          router.history.push("/another-one");
        }
      });

      it("re-renders nested components", done => {
        const Vue = createLocalVue();
        const FakeComponent = makeFake(done);

        let wrapper;
        Vue.use(CuriPlugin, { router });

        if (!wrapper) {
          wrapper = mount(
            {
              template: "<div><FakeComponent /></div>",
              components: { FakeComponent }
            },
            {
              localVue: Vue,
              sync: false
            }
          );
          router.history.push("/another-one");
        }
      });
    });
{'fraction_non_alphanumeric': 0.14819175777964677, 'fraction_numerical': 0.0, 'mean_word_length': 1.8100189035916825, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '6064899', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1641, 'n_words': 349}