Fixed PokemonCard render issue for single type, by using unit test

This commit is contained in:
Jason Zhu 2023-05-15 21:21:45 +10:00
parent c50862adbf
commit 8c442946d3
3 changed files with 22 additions and 5 deletions

View File

@ -30,3 +30,13 @@ export const Bulbasaur: Story = {
types: ['grass', 'poison'],
},
};
export const Pikachu: Story = {
args: {
id: 25,
name: 'pikachu',
image:
'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/dream-world/25.svg',
types: ['electric'],
},
};

View File

@ -0,0 +1,7 @@
import { colorTypeGradients } from './utils';
describe('Test utility functions', () => {
it('should return correct color for each type', () => {
expect(colorTypeGradients(['grass'])).toBe(['#a8ff98', '#a8ff98']);
});
});

View File

@ -1,4 +1,4 @@
const getColor = (type: string) => {
const getColor = (type: string): string => {
let returnColor: string;
switch (type) {
case 'grass':
@ -63,13 +63,13 @@ const getColor = (type: string) => {
return returnColor;
};
export const colorTypeGradients = (types: string[]) => {
let color2;
const color1 = getColor(types[0]);
export const colorTypeGradients = (types: string[]): string[] => {
const color1: string = getColor(types[0]);
let color2: string = color1;
if (types.length === 2) {
color2 = getColor(types[1]);
} else if (length === 1) {
} else if (types.length === 1) {
color2 = color1;
}