Skip to content

Commit

Permalink
Fixed track layout image of Miami (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcokreeft87 authored May 4, 2023
1 parent 80fceaf commit 4b08d01
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
6 changes: 3 additions & 3 deletions formulaone-card.js

Large diffs are not rendered by default.

Binary file modified formulaone-card.js.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formulaone-card",
"version": "1.5.0",
"version": "1.5.1",
"description": "Frontend card for Home Assistant to display Formula One data",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 10 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html, HTMLTemplateResult, LitElement, PropertyValues } from "lit";
import { FormulaOneCardConfig, FormulaOneCardType, LocalStorageItem, WeatherUnit } from "./types/formulaone-card-types";
import { Constructor, Driver, Race, Root } from "./api/f1-models";
import { Constructor, Driver, Race, Root, Location } from "./api/f1-models";
import FormulaOneCard from ".";
import { BaseCard } from "./cards/base-card";
import { formatDateTimeRaceInfo } from "./lib/format_date_time";
Expand Down Expand Up @@ -75,7 +75,9 @@ export const getTeamImage = (card: BaseCard, teamName: string) => {
return card.imageClient.GetImage(`${ImageConstants.TeamLogoCDN}/2023/${teamName.toLowerCase()}-logo.png.transform/2col-retina/image.png`);
}

export const getCircuitName = (circuitName: string) => {
export const getCircuitName = (location: Location) => {

let circuitName = location.country.replace(" ","-")
const exceptions = [{ countryDashed: 'UAE', name: 'Abu_Dhabi'}, { countryDashed: 'UK', name: 'Great_Britain'},
{ countryDashed: 'Monaco', name: 'Monoco'}, { countryDashed: 'Azerbaijan', name: 'Baku'}, { countryDashed: 'Saudi-Arabia', name: 'Saudi_Arabia'}];

Expand All @@ -85,6 +87,11 @@ export const getCircuitName = (circuitName: string) => {
circuitName = exception[0].name;
}

if(location.country == 'USA' && location.locality != 'Austin')
{
circuitName = location.locality;
}

return circuitName;
}

Expand All @@ -111,8 +118,7 @@ export const clickHandler = (node: LitElement, config: FormulaOneCardConfig, has

export const renderHeader = (card: BaseCard, race: Race, preventClick = false): HTMLTemplateResult => {

const countryDashed = race.Circuit.Location.country.replace(" ","-")
const circuitName = getCircuitName(countryDashed);
const circuitName = getCircuitName(race.Circuit.Location);

const _handleAction = (ev: ActionHandlerEvent): void => {
if (card.hass && card.config.actions && ev.detail.action && !preventClick) {
Expand Down
14 changes: 12 additions & 2 deletions tests/utils/getCircuitName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ import { getCircuitName } from '../../src/utils';

describe('Testing util file function getCircuitName', () => {
test('Passing Japan should return expected circuit name', () => {
expect(getCircuitName('Japan')).toBe('Japan')
expect(getCircuitName({
country: 'Japan',
lat: '',
long: '',
locality: ''
})).toBe('Japan')
}),
test('Passing UAE should return expected circuit name', () => {
expect(getCircuitName('UAE')).toBe('Abu_Dhabi')
expect(getCircuitName({
country: 'UAE',
lat: '',
long: '',
locality: ''
})).toBe('Abu_Dhabi')
})
})

11 changes: 11 additions & 0 deletions tests/utils/renderHeader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,16 @@ describe('Testing util file function renderHeader', () => {
const htmlResult = getRenderString(result);

expect(htmlResult).toMatch(`<h2 class="formulaone-font"><img height="25" src="">&nbsp; 17 : Singapore Grand Prix</h2>`);
}),
test('Calling renderHeader with Miami with image not clickable', async () => {
card.config.image_clickable = undefined;
card.config.hide_tracklayout = false;
lastRace.Circuit.Location.country = "USA";
lastRace.Circuit.Location.locality = "Miami";

const result = renderHeader(card, lastRace);
const htmlResult = getRenderString(result);

expect(htmlResult).toMatch(`<h2 class="formulaone-font"><img height="25" src="">&nbsp; 17 : Singapore Grand Prix</h2> <img width="100%" src="" @action=_handleAction .actionHandler= class=" clickable" /><br>`);
})
});

0 comments on commit 4b08d01

Please sign in to comment.