Skip to content

Commit

Permalink
feat: update docs and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Osman Minaz committed Mar 21, 2024
1 parent adc9675 commit 0d6a968
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 58 deletions.
29 changes: 26 additions & 3 deletions src/components/timetable-row/timetable-row.sample-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const defaultTrip: DeepPartial<ITripItem> = {
line: '37',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-37',
corporateIdentityPictogram: 'train-right',
},
},
};
Expand All @@ -52,6 +54,8 @@ export const cancelledTrip: DeepPartial<ITripItem> = {
line: '37',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-37',
corporateIdentityPictogram: 'train-right',
},
tripStatus: {
cancelled: true,
Expand Down Expand Up @@ -79,6 +83,8 @@ export const progressTrip: DeepPartial<ITripItem> = {
line: '37',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-37',
corporateIdentityPictogram: 'train-right',
},
},
};
Expand All @@ -99,6 +105,8 @@ export const partiallyCancelled: DeepPartial<ITripItem> = {
line: '37',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-37',
corporateIdentityPictogram: 'train-right',
},
tripStatus: {
partiallyCancelled: true,
Expand All @@ -123,6 +131,8 @@ export const pastTrip: DeepPartial<ITripItem> = {
line: '37',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-37',
corporateIdentityPictogram: 'train-right',
},
tripStatus: {
partiallyCancelled: false,
Expand All @@ -145,6 +155,7 @@ export const skippedLastArrivalStopTrip: DeepPartial<ITripItem> = {
line: '502',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityPictogram: 'bus-right',
},
},
};
Expand All @@ -164,6 +175,7 @@ export const skippedArrivalStopTrip: DeepPartial<ITripItem> = {
line: '502',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityPictogram: 'bus-right',
},
},
};
Expand All @@ -183,6 +195,7 @@ export const skippedDepartureStopTrip: DeepPartial<ITripItem> = {
line: '502',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityPictogram: 'bus-right',
},
},
};
Expand All @@ -202,6 +215,7 @@ export const skippedFirstDepartureStopTrip: DeepPartial<ITripItem> = {
line: '502',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityPictogram: 'bus-right',
},
},
};
Expand Down Expand Up @@ -255,6 +269,7 @@ export const disturbanceTrip: DeepPartial<ITripItem> = {
number: '2204',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityPictogram: 'bus-right',
},
occupancy: {
firstClass: 'MEDIUM',
Expand Down Expand Up @@ -306,6 +321,7 @@ export const quayChangeTrip: DeepPartial<ITripItem> = {
number: '2204',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityPictogram: 'bus-right',
},
occupancy: {
firstClass: 'MEDIUM',
Expand Down Expand Up @@ -338,6 +354,8 @@ export const trainTrip: DeepPartial<ITripItem> = {
number: '2377',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ic-35',
corporateIdentityPictogram: 'train-right',
},
occupancy: {
firstClass: 'LOW',
Expand All @@ -364,12 +382,12 @@ export const busTrip: DeepPartial<ITripItem> = {
departureWalk: 0,
direction: 'Spiegel, Blinzern',
product: {
name: 'B 19 27014',
name: 'B 19',
line: '19',
number: '27014',
vehicleMode: 'BUS',
vehicleSubModeShortName: 'B',
corporateIdentityIcon: 'SBB_oev_b_t06',
corporateIdentityPictogram: 'bus-right',
},
occupancy: {
firstClass: 'LOW',
Expand Down Expand Up @@ -398,6 +416,7 @@ export const shipTrip: DeepPartial<ITripItem> = {
product: {
line: null,
vehicleMode: 'SHIP',
corporateIdentityPictogram: 'jetty-right',
},
tripStatus: {},
},
Expand Down Expand Up @@ -543,7 +562,7 @@ export const walkTimeTrip: DeepPartial<ITripItem> = {
number: '2258',
vehicleMode: 'TRAMWAY',
vehicleSubModeShortName: 'T',
corporateIdentityIcon: 'SBB_oev_b_t04',
corporateIdentityPictogram: 'tram-right',
},
occupancy: {
firstClass: 'LOW',
Expand Down Expand Up @@ -581,6 +600,8 @@ export const extendedEnterTimeTrip: DeepPartial<ITripItem> = {
number: '2377',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-35',
corporateIdentityPictogram: 'train-right',
},
occupancy: {},
tripStatus: {},
Expand Down Expand Up @@ -664,6 +685,8 @@ export const noticesTrip: DeepPartial<ITripItem> = {
number: '2377',
vehicleMode: 'TRAIN',
vehicleSubModeShortName: 'IR',
corporateIdentityIcon: 'ir-35',
corporateIdentityPictogram: 'train-right',
},
occupancy: {
firstClass: 'LOW',
Expand Down
100 changes: 47 additions & 53 deletions src/components/timetable-row/timetable-row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ import { waitForLitRender } from '../core/testing';
import type { ITripItem, Notice, PtSituation } from '../core/timetable';

import type { SbbTimetableRowElement } from './timetable-row';
import {
filterNotices,
getCus,
getHimIcon,
getTransportIcon,
isProductIcon,
sortSituation,
} from './timetable-row';
import { filterNotices, getCus, getHimIcon, sortSituation } from './timetable-row';
import {
defaultTrip,
busTrip,
Expand All @@ -39,32 +32,69 @@ describe('sbb-timetable-row', () => {
`);

expect(element).shadowDom.to.be.equal(`
<sbb-card color="white" data-action-role="button" data-has-action size="l">
<sbb-card-button dir="ltr" role="button" slot="action" tabindex="0" data-action data-button>
<sbb-card
color="white"
data-action-role="button"
data-has-action=""
size="l"
>
<sbb-card-button
data-action=""
data-button=""
dir="ltr"
role="button"
slot="action"
tabindex="0"
>
Departure: 11:08, Train, IR 37, Direction Basel SBB, Arrival: 12:13, Travel time 1 Hour 15 Minutes,
</sbb-card-button>
<div class="sbb-timetable__row" role="row">
<div class="sbb-timetable__row-header" role="gridcell">
<div
class="sbb-timetable__row"
role="row"
>
<div
class="sbb-timetable__row-header"
role="gridcell"
>
<div class="sbb-timetable__row-details">
<span class="sbb-timetable__row-transport-wrapper">
<sbb-icon aria-hidden="true" data-namespace="picto" role="img" class="sbb-timetable__row-transport-icon" name="picto:train-right"></sbb-icon>
<sbb-icon
aria-hidden="true"
class="sbb-timetable__row-transport-icon"
data-namespace="picto"
name="picto:train-right"
role="img"
>
</sbb-icon>
<span class="sbb-screenreaderonly">
Train
</span>
</span>
<span class="sbb-timetable__row-transport">
<sbb-icon aria-hidden="true" data-namespace="default" role="img" name="ir-37"></sbb-icon>
<sbb-icon
aria-hidden="true"
data-namespace="default"
name="ir-37"
role="img"
>
</sbb-icon>
<span class="sbb-screenreaderonly">
ir-37
</span>
</span>
</div>
<p>
Direction Basel SBB
</p>
</div>
<sbb-pearl-chain-time data-now="1660662000000" role="gridcell"></sbb-pearl-chain-time>
<div class="sbb-timetable__row-footer" role="gridcell">
<sbb-pearl-chain-time
data-now="1660662000000"
role="gridcell"
>
</sbb-pearl-chain-time>
<div
class="sbb-timetable__row-footer"
role="gridcell"
>
<time>
<span class="sbb-screenreaderonly">
Travel time 1 Hour 15 Minutes
Expand Down Expand Up @@ -179,42 +209,6 @@ describe('sbb-timetable-row', () => {
});
});

describe('getTransportIcon', () => {
it('should return ship / jetty', () => {
expect(getTransportIcon('SHIP', '', 'de')).to.be.equal('jetty-right');
});

it('should return empty string', () => {
expect(getTransportIcon('UNKNOWN', '', 'de')).to.be.equal('');
});

it('should return metro string', () => {
expect(getTransportIcon('METRO', 'PB', 'fr')).to.be.equal('metro-right-fr');
});

it('should return metro en string', () => {
expect(getTransportIcon('METRO', 'PB', 'en')).to.be.equal('metro-right-de');
});

it('should return cableway string', () => {
expect(getTransportIcon('GONDOLA', 'PB', 'de')).to.be.equal('cableway-right');
});

it('should return gondola string', () => {
expect(getTransportIcon('GONDOLA', 'GB', 'de')).to.be.equal('gondola-lift-right');
});
});

describe('isProductIcon', () => {
it('should return true', () => {
expect(isProductIcon('ic')).to.be.equal(true);
});

it('should return false', () => {
expect(isProductIcon('icc')).to.be.equal(false);
});
});

describe('sortSituation', () => {
it('should return sorted array', () => {
expect(
Expand Down
4 changes: 2 additions & 2 deletions src/components/timetable-row/timetable-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface Price {

export const renderIconProduct = (icon: string, name: string): TemplateResult => {
return html`<span class="sbb-timetable__row-transport">
<sbb-icon name="picto:${icon}"></sbb-icon>
<sbb-icon name="${icon}"></sbb-icon>
<span class="sbb-screenreaderonly">${name}</span>
</span>`;
};
Expand Down Expand Up @@ -509,7 +509,7 @@ export class SbbTimetableRowElement extends LitElement {
html`<span class="sbb-timetable__row-transport-wrapper">
<sbb-icon
class="sbb-timetable__row-transport-icon"
name=${'picto:${product.corporateIdentityPictogram}'}
name="picto:${product.corporateIdentityPictogram}"
></sbb-icon>
<span class="sbb-screenreaderonly">
${product &&
Expand Down

0 comments on commit 0d6a968

Please sign in to comment.