Add ponyhead URL generation with tests

This commit is contained in:
Hamcha 2019-09-09 17:42:07 +02:00
parent e061aa660b
commit 49b74a124e
Signed by: hamcha
GPG Key ID: 44AD3571EB09A39E
3 changed files with 26 additions and 1 deletions

View File

@ -1,7 +1,7 @@
<template>
<section class="decklist">
<article v-for="(card, i) in cards" :key="i">
<div class="name">{{ cardFullName(card) }}</div>
<div class="name">{{ fullName(card) }}</div>
</article>
</section>
</template>
@ -22,5 +22,9 @@ import { Card, cardFullName } from "@/mlpccg";
export default class DeckList extends Vue {
@Prop()
public cards!: Card[];
private fullName(card: Card): string {
return cardFullName(card);
}
}
</script>

View File

@ -6,3 +6,8 @@ export function cardFullName(card: Card): string {
}
return card.Name;
}
export function createPonyheadURL(cards: Card[]): string {
const cardlist = cards.map(c => `${c.ID}x1`);
return "https://ponyhead.com/deckbuilder?v1code=" + cardlist.join("-");
}

View File

@ -0,0 +1,16 @@
import { Card, createPonyheadURL, cardFullName } from "@/mlpccg";
describe("mlpccg/cards", () => {
test("Card full names are correctly generated in all cases", () => {
const card1 = { Name: "Name", Subname: "" };
const card2 = { Name: "Name1", Subname: "the Name2" };
expect(cardFullName(card1 as Card)).toEqual("Name");
expect(cardFullName(card2 as Card)).toEqual("Name1, the Name2");
});
test("Ponyhead URL is generated correctly", () => {
const cards: any[] = [{ ID: "pr10" }, { ID: "pr12" }, { ID: "pr13" }];
const url = "https://ponyhead.com/deckbuilder?v1code=pr10x1-pr12x1-pr13x1";
expect(createPonyheadURL(cards!)).toEqual(url);
});
});