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

Add ability to hide headers #16

Merged
merged 1 commit into from
May 26, 2024
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: 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
Loading