Skip to content

Commit

Permalink
Pagination tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Dec 18, 2018
1 parent 71005b8 commit 2ebdd3f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/*
datasets/*
!datasets/.gitkeep

Expand Down
1 change: 0 additions & 1 deletion client/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ module.exports = {
"^@/(.*)$": "<rootDir>/src/$1"
},
snapshotSerializers: ["jest-serializer-vue"],

testURL: "http://localhost/"
};
8 changes: 4 additions & 4 deletions client/src/components/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@ export default {
};
},
methods: {
previousPage: function() {
previousPage() {
this.page -= 1;
if (this.page < 1) {
this.page = 1;
}
},
nextPage: function() {
nextPage() {
this.page += 1;
if (this.page > this.pages) {
this.page = this.pages;
}
}
},
watch: {
page: function(newPage, oldPage) {
page(newPage, oldPage) {
if (newPage === oldPage) return;
clearTimeout(this.timer);
this.timer = setTimeout(() => this.$emit("pagechange", this.page), 0);
}
},
computed: {
startPage: function() {
startPage() {
if (this.range > this.pages) {
return 0;
}
Expand Down
29 changes: 19 additions & 10 deletions client/src/components/__tests__/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ describe("Metadata.vue Empty", () => {
});

describe("Metadata.vue with metadata", () => {
let metadata = {
name: "ignore",
a: 0,
b: 1,
c: true,
d: 123
//e: { test: true, data: "info" }
};
const wrapper = shallowMount(Metadata, {
propsData: {
metadata: {
name: "ignore",
a: "0",
b: "1",
c: true,
d: 123,
e: { test: true, data: "info" }
},
exlcude: "name",
metadata: metadata,
exclude: "name",
keyTitle: "Custom Keys",
valueTitle: "Custom Values",
title: "Custom Title"
}
});

it("check component render", () => {
it("proper compoent proerpties", () => {
expect(wrapper.find(".fa-plus").exists()).toBeTruthy();
expect(wrapper.find(".meta-input").exists()).toBeTruthy();

Expand All @@ -70,5 +71,13 @@ describe("Metadata.vue with metadata", () => {
let subtitles = wrapper.findAll(".subtitle");
expect(subtitles.wrappers[0].text()).toEqual("Custom Keys");
expect(subtitles.wrappers[1].text()).toEqual("Custom Values");

let inputs = wrapper.findAll(".meta-input").wrappers;
expect(inputs.length).toEqual(4 * 2);
});

it("exporting data", () => {
delete metadata.name;
expect(wrapper.vm.export()).toEqual(metadata);
});
});
38 changes: 38 additions & 0 deletions client/src/components/__tests__/pagination.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { shallowMount } from "@vue/test-utils";
import Pagination from "@/components/Pagination";

describe("Pagination.vue", () => {
let pages = 50;
const wrapper = shallowMount(Pagination, {
propsData: { pages: pages }
});

it("first page", () => {
expect(wrapper.vm.startPage).toEqual(0);
expect(wrapper.vm.page).toEqual(1);
wrapper.vm.previousPage();
expect(wrapper.vm.page).toEqual(1);
wrapper.vm.nextPage();
expect(wrapper.vm.page).toEqual(2);
});

it("middle page", () => {
wrapper.vm.page = 25;
expect(wrapper.vm.startPage).toEqual(25 - 6);
expect(wrapper.vm.page).toEqual(25);
wrapper.vm.previousPage();
expect(wrapper.vm.page).toEqual(24);
wrapper.vm.nextPage();
expect(wrapper.vm.page).toEqual(25);
});

it("last page", () => {
wrapper.vm.page = 50;
expect(wrapper.vm.startPage).toEqual(50 - 11);
expect(wrapper.vm.page).toEqual(50);
wrapper.vm.nextPage();
expect(wrapper.vm.page).toEqual(50);
wrapper.vm.previousPage();
expect(wrapper.vm.page).toEqual(49);
});
});
2 changes: 1 addition & 1 deletion client/src/components/annotator/tools/PolygonTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default {
if (this.polygon.guidance && wasNull) this.polygon.path.add(event.point);
},
onMouseUp(event) {
onMouseUp() {
if (this.polygon.path == null) return;
let action = new UndoAction({
name: this.name,
Expand Down
1 change: 0 additions & 1 deletion client/src/components/annotator/tools/UndoButton.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import button from "@/mixins/toolBar/button";
import axios from "axios";
import { mapMutations } from "vuex";
Expand Down

0 comments on commit 2ebdd3f

Please sign in to comment.