Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix next race #18

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion formulaone-card.js

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

Binary file modified formulaone-card.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/cards/next-race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class NextRace extends BaseCard {
const raceDate = new Date(this.next_race.date + 'T' + this.next_race.time);
const freePractice1 = formatDateTimeRaceInfo(new Date(this.next_race.FirstPractice.date + 'T' + this.next_race.FirstPractice.time), this.hass.locale);
const freePractice2 = formatDateTimeRaceInfo(new Date(this.next_race.SecondPractice.date + 'T' + this.next_race.SecondPractice.time), this.hass.locale);
const freePractice3 = formatDateTimeRaceInfo(new Date(this.next_race.ThirdPractice.date + 'T' + this.next_race.ThirdPractice.time), this.hass.locale);
const freePractice3 = this.next_race.ThirdPractice !== undefined ? formatDateTimeRaceInfo(new Date(this.next_race.ThirdPractice.date + 'T' + this.next_race.ThirdPractice.time), this.hass.locale) : '-';
const raceDateFormatted = formatDateTimeRaceInfo(raceDate, this.hass.locale);
const qualifyingDate = this.next_race.Qualifying !== undefined ? formatDateTimeRaceInfo(new Date(this.next_race.Qualifying.date + 'T' + this.next_race.Qualifying.time), this.hass.locale) : '-';
const sprintDate = this.next_race.Sprint !== undefined ? formatDateTimeRaceInfo(new Date(this.next_race.Sprint.date + 'T' + this.next_race.Sprint.time), this.hass.locale) : '-';
Expand Down
2 changes: 1 addition & 1 deletion src/types/formulaone-card-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface Race {
time: string;
FirstPractice: FirstPractice;
SecondPractice: SecondPractice;
ThirdPractice: ThirdPractice;
ThirdPractice?: ThirdPractice;
Qualifying?: Qualifying;
Sprint?: Sprint;
Results?: Result[]
Expand Down
3 changes: 2 additions & 1 deletion tests/cards/next-race.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('Testing next-race file', () => {
}),
test('Calling render with Sprint with hass and sensor', () => {
const raceData = data as Race;
raceData.ThirdPractice = undefined;
raceData.Sprint = {
date: '2022-03-20',
time: '10:00'
Expand All @@ -103,6 +104,6 @@ describe('Testing next-race file', () => {
const result = card.render();
const htmlResult = getRenderString(result);

expect(htmlResult).toMatch('<table> <tbody> <tr> <td colspan="5"><h2><img height="25" src="https://www.countries-ofthe-world.com/flags-normal/flag-of-Bahrain.png">&nbsp; 1 : Bahrain Grand Prix</h2><a target="_new" href="http://en.wikipedia.org/wiki/Bahrain_International_Circuit"><img width="100%" src="https://www.formula1.com/content/dam/fom-website/2018-redesign-assets/Circuit%20maps%2016x9/Bahrain_Circuit.png.transform/7col/image.png"></a><br> </td> </tr> <tr><td>Date</td><td>20-03-22</td><td>&nbsp;</td><td>Practice 1</td><td align="right">vr 13:00</td></tr> <tr><td>Race</td><td>1</td><td>&nbsp;</td><td>Practice 2</td><td align="right">vr 16:00</td></tr> <tr><td>Race name</td><td>Bahrain Grand Prix</td><td>&nbsp;</td><td>Practice 3</td><td align="right">za 13:00</td></tr> <tr><td>Circuit name</td><td>Bahrain International Circuit</td><td>&nbsp;</td><td>Qualifying</td><td align="right">-</td></tr> <tr><td>Location</td><td>Bahrain</td><td>&nbsp;</td><td>Sprint</td><td align="right">zo 10:00</td></tr> <tr><td>City</td><td>Sakhir</td><td>&nbsp;</td><td>Race</td><td align="right">zo 16:00</td></tr> </tbody> </table>');
expect(htmlResult).toMatch('<table> <tbody> <tr> <td colspan="5"><h2><img height="25" src="https://www.countries-ofthe-world.com/flags-normal/flag-of-Bahrain.png">&nbsp; 1 : Bahrain Grand Prix</h2><a target="_new" href="http://en.wikipedia.org/wiki/Bahrain_International_Circuit"><img width="100%" src="https://www.formula1.com/content/dam/fom-website/2018-redesign-assets/Circuit%20maps%2016x9/Bahrain_Circuit.png.transform/7col/image.png"></a><br> </td> </tr> <tr><td>Date</td><td>20-03-22</td><td>&nbsp;</td><td>Practice 1</td><td align="right">vr 13:00</td></tr> <tr><td>Race</td><td>1</td><td>&nbsp;</td><td>Practice 2</td><td align="right">vr 16:00</td></tr> <tr><td>Race name</td><td>Bahrain Grand Prix</td><td>&nbsp;</td><td>Practice 3</td><td align="right">-</td></tr> <tr><td>Circuit name</td><td>Bahrain International Circuit</td><td>&nbsp;</td><td>Qualifying</td><td align="right">-</td></tr> <tr><td>Location</td><td>Bahrain</td><td>&nbsp;</td><td>Sprint</td><td align="right">zo 10:00</td></tr> <tr><td>City</td><td>Sakhir</td><td>&nbsp;</td><td>Race</td><td align="right">zo 16:00</td></tr> </tbody> </table>');
})
});