Add basic deck builder #12

Merged
hamcha merged 42 commits from feature/deckbuilder into master 2019-09-12 09:11:32 +00:00
3 changed files with 26 additions and 1 deletions
Showing only changes of commit 49b74a124e - Show all commits

View file

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

View file

@ -6,3 +6,8 @@ export function cardFullName(card: Card): string {
} }
return card.Name; 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);
});
});