Skip to content

Commit

Permalink
Add ability to hide headers
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed May 26, 2024
1 parent dcd7301 commit 7e2812e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
2 changes: 2 additions & 0 deletions MMM-CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Module.register('MMM-CTA', {
maxResultsTrain: 5,
routeIcons: true,
suffixStyle: 'long',
showHeaders: true,
stops: [],
},

Expand Down Expand Up @@ -52,6 +53,7 @@ Module.register('MMM-CTA', {
return {
loading: this.loading,
routeIcons: this.config.routeIcons,
showHeaders: this.config.showHeaders,
stops: this.data.stops?.map((stop) => ({
...stop,
arrivals: stop.arrivals?.map((arrival) => ({
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var config = {
| `maxResultsBus` | *Optional* | Maximum number of bus results to display <br>Default `5` |
| `maxResultsTrain` | *Optional* | Maximum number of train results to display <br>Default `5` |
| `routeIcons` | *Optional* | True/False - Display icons next to routes. <br>Default `true` |
| `showHeaders` | *Optional* | True/False - Display headers for each stop. <br>Default `true` |
| `suffixStyle` | *Optional* | Style of suffix for the arrival time. `long`, `short`, or `none` <br>Default `long` |

### `stops` option
Expand Down
13 changes: 13 additions & 0 deletions __tests__/MMM-CTA.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ it('has a default config', () => {
maxResultsBus: 5,
routeIcons: true,
suffixStyle: 'long',
showHeaders: true,
stops: [],
});
});
Expand Down Expand Up @@ -127,6 +128,7 @@ describe('getTemplateData', () => {
expect(MMMCTA.getTemplateData()).toEqual({
loading: MMMCTA.loading,
routeIcons: MMMCTA.config.routeIcons,
showHeaders: MMMCTA.config.showHeaders,
stops: [{
type: 'bus',
name: 'Mock Stop',
Expand Down Expand Up @@ -160,6 +162,16 @@ describe('getTemplateData', () => {
expect(MMMCTA.getTemplateData().routeIcons).toEqual(false);
});
});

describe('showHeaders turned off', () => {
beforeEach(() => {
MMMCTA.setConfig({ showHeaders: false });
});

it('returns showHeaders false', () => {
expect(MMMCTA.getTemplateData().showHeaders).toEqual(false);
});
});
});

describe('train information', () => {
Expand Down Expand Up @@ -200,6 +212,7 @@ describe('getTemplateData', () => {
expect(MMMCTA.getTemplateData()).toEqual({
loading: MMMCTA.loading,
routeIcons: MMMCTA.config.routeIcons,
showHeaders: MMMCTA.config.showHeaders,
stops: [{
type: 'train',
name: 'Mock Stop',
Expand Down
34 changes: 34 additions & 0 deletions __tests__/templates/MMM-CTA.njk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,40 @@ describe('bus stop', () => {
expect(template).not.toContain('fa-bus');
});
});

describe('showHeaders turned on', () => {
beforeEach(() => {
data.showHeaders = true;
template = nunjucks.render('MMM-CTA.njk', data);
data.stops = [{
type: 'bus',
name: 'Bus Stop',
arrivals: [
{
direction: 'North',
arrival: 5,
},
],
}];
});

it('shows headers', () => {
expect(template).toContain('DIRECTION');
expect(template).toContain('ARRIVAL');
});
});

describe('showHeaders turned off', () => {
beforeEach(() => {
data.showHeaders = false;
template = nunjucks.render('MMM-CTA.njk', data);
});

it('does not show headers', () => {
expect(template).not.toContain('DIRECTION');
expect(template).not.toContain('ARRIVAL');
});
});
});

describe('multiple stops', () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mmm-cta",
"version": "1.0.0",
"version": "1.1.0",
"description": "Magic Mirror Module for displaying CTA Train and Bus arrival times",
"main": "MMM-CTA.js",
"scripts": {
Expand Down
28 changes: 15 additions & 13 deletions templates/MMM-CTA.njk
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
</td>
</tr>

<tr class="small">
{% if stop.arrivals.length %}
{% if routeIcons %}
<th class="align-left"></th>
{% endif %}
<th class="align-left">
{{ "DIRECTION" | translate }}
</th>
{% if showHeaders %}
<tr class="small">
{% if stop.arrivals.length %}
{% if routeIcons %}
<th class="align-left"></th>
{% endif %}
<th class="align-left">
{{ "DIRECTION" | translate }}
</th>

<th class="align-right">
{{ "ARRIVAL" | translate }}
</th>
{% endif %}
</tr>
<th class="align-right">
{{ "ARRIVAL" | translate }}
</th>
{% endif %}
</tr>
{% endif %}
</thead>
<tbody>
{% if stop.arrivals.length %}
Expand Down

0 comments on commit 7e2812e

Please sign in to comment.