diff --git a/assets/components/LogEventSource.vue b/assets/components/LogEventSource.vue new file mode 100644 index 00000000..5753ad14 --- /dev/null +++ b/assets/components/LogEventSource.vue @@ -0,0 +1,52 @@ + + + diff --git a/assets/components/LogViewer.vue b/assets/components/LogViewer.vue new file mode 100644 index 00000000..1f346f6b --- /dev/null +++ b/assets/components/LogViewer.vue @@ -0,0 +1,150 @@ + + + + diff --git a/assets/components/ScrollbarNotification.vue b/assets/components/ScrollbarNotification.vue index 1debe0cc..c0c83348 100644 --- a/assets/components/ScrollbarNotification.vue +++ b/assets/components/ScrollbarNotification.vue @@ -36,8 +36,7 @@ export default { const scrollTop = document.documentElement.scrollTop || document.body.scrollTop; const scrollBottom = (document.documentElement.scrollHeight || document.body.scrollHeight) - document.documentElement.clientHeight; - const diff = Math.abs(scrollTop - scrollBottom); - this.visible = diff > 50; + this.visible = scrollBottom - scrollTop > 50; if (!this.visible) { this.hasNew = false; } diff --git a/assets/pages/Container.spec.js b/assets/pages/Container.spec.js index 1408baf7..287341cd 100644 --- a/assets/pages/Container.spec.js +++ b/assets/pages/Container.spec.js @@ -1,14 +1,16 @@ import EventSource from "eventsourcemock"; import { sources } from "eventsourcemock"; -import { shallowMount } from "@vue/test-utils"; +import { shallowMount, mount } from "@vue/test-utils"; import MockDate from "mockdate"; import Container from "./Container"; +import LogViewer from "../components/LogViewer.vue"; describe("", () => { beforeEach(() => { global.BASE_PATH = ""; global.EventSource = EventSource; MockDate.set("6/12/2019", 0); + window.scrollTo = jest.fn(); }); afterEach(() => MockDate.reset()); @@ -19,12 +21,12 @@ describe("", () => { }); test("renders correctly", async () => { - const wrapper = shallowMount(Container); + const wrapper = mount(Container); expect(wrapper.element).toMatchSnapshot(); }); test("should connect to EventSource", async () => { - shallowMount(Container, { + mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); @@ -32,7 +34,7 @@ describe("", () => { }); test("should close EventSource", async () => { - const wrapper = shallowMount(Container, { + const wrapper = mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); @@ -41,12 +43,12 @@ describe("", () => { }); test("should parse messages", async () => { - const wrapper = shallowMount(Container, { + const wrapper = mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); sources["/api/logs/stream?id=abc"].emitMessage({ data: `2019-06-12T10:55:42.459034602Z "This is a message."` }); - const [message, _] = wrapper.vm.messages; + const [message, _] = wrapper.find(LogViewer).vm.messages; expect(message).toMatchInlineSnapshot(` Object { @@ -58,7 +60,7 @@ describe("", () => { }); test("should render messages", async () => { - const wrapper = shallowMount(Container, { + const wrapper = mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); @@ -72,7 +74,7 @@ describe("", () => { }); test("should render messages with color", async () => { - const wrapper = shallowMount(Container, { + const wrapper = mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); @@ -88,7 +90,7 @@ describe("", () => { }); test("should render messages with html entities", async () => { - const wrapper = shallowMount(Container, { + const wrapper = mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); @@ -104,7 +106,7 @@ describe("", () => { }); test("should render messages with filter", async () => { - const wrapper = shallowMount(Container, { + const wrapper = mount(Container, { propsData: { id: "abc" } }); sources["/api/logs/stream?id=abc"].emitOpen(); @@ -115,7 +117,7 @@ describe("", () => { data: `2019-06-12T10:55:42.459034602Z This is a test ` }); - wrapper.setData({ filter: "test" }); + wrapper.find(LogViewer).setData({ filter: "test" }); expect(wrapper.find("ul.events")).toMatchInlineSnapshot(`
    diff --git a/assets/pages/Container.vue b/assets/pages/Container.vue index 6b5f5073..fb576640 100644 --- a/assets/pages/Container.vue +++ b/assets/pages/Container.vue @@ -1,198 +1,26 @@ - + diff --git a/assets/pages/__snapshots__/Container.spec.js.snap b/assets/pages/__snapshots__/Container.spec.js.snap index f2fe4428..4fe01731 100644 --- a/assets/pages/__snapshots__/Container.spec.js.snap +++ b/assets/pages/__snapshots__/Container.spec.js.snap @@ -1,50 +1,62 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[` renders correctly 1`] = ` -
    + -
    + +
    + + + +
    - -
      - - - + `; diff --git a/package.json b/package.json index 7960df21..7af36604 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "vue": "./node_modules/vue/dist/vue.esm.js" }, "jest": { + "clearMocks": true, "moduleFileExtensions": [ "js", "json",