Create settings page and image cache #27

Merged
hamcha merged 6 commits from feature/image-cache into master 2019-09-20 10:49:16 +00:00
4 changed files with 25 additions and 4 deletions
Showing only changes of commit 9b639a52d1 - Show all commits

View file

@ -2,7 +2,7 @@ module.exports = {
moduleFileExtensions: ["js", "jsx", "json", "vue", "ts", "tsx"],
transform: {
"^.+\\.vue$": "vue-jest",
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$":
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2|webp)$":
"jest-transform-stub",
"^.+\\.tsx?$": "ts-jest"
},

View file

@ -3,3 +3,4 @@ export * from "./MockPeer";
export * from "./MockHelper";
export * from "./EventHook";
export * from "./IDBShim";
export * from "./sync-utils";

View file

@ -0,0 +1,5 @@
export function seconds(ms: number): Promise<void> {
return new Promise(resolve => {
setTimeout(resolve, ms * 1000);
});
}

View file

@ -1,5 +1,7 @@
import CardPicker from "@/components/DeckBuilder/CardPicker.vue";
import { shallowMount } from "@vue/test-utils";
import CardImage from "@/components/Cards/CardImage.vue";
import { shallowMount, mount } from "@vue/test-utils";
import { seconds } from "@/testing";
// Generate 10 test cards
const testCards = new Array(10)
@ -8,8 +10,8 @@ const testCards = new Array(10)
const testSlots = testCards.map(c => ({ data: c, limit: 3, howmany: 1 }));
describe("components/DeckBuilder/CardPicker", () => {
test("CardPicker correctly creates images for each card", () => {
const wrapper = shallowMount(CardPicker, {
test("CardPicker correctly instances images for each card", () => {
const wrapper = mount(CardPicker, {
propsData: {
rows: 2,
columns: 5,
@ -20,6 +22,19 @@ describe("components/DeckBuilder/CardPicker", () => {
expect(cards.contains("img")).toBe(true);
});
test("CardImage correctly resolves to an URL after a while", async () => {
const wrapper = mount(CardImage, {
propsData: {
id: "sb1"
}
});
let src = wrapper.attributes("src");
expect(src).toBe(""); // Should be placeholder but it gets stubbed
await seconds(0.5);
src = wrapper.attributes("src");
expect(src).toMatch(/^https?:|^blob:/);
});
test("CardPicker correctly aligns items in a grid", () => {
const wrapper = shallowMount(CardPicker, {
propsData: {