From 7e2812e8430cd8edb2c9df29894d4e92eb8b697f Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Sun, 26 May 2024 15:23:22 -0500 Subject: [PATCH] Add ability to hide headers --- MMM-CTA.js | 2 ++ README.md | 1 + __tests__/MMM-CTA.spec.js | 13 ++++++++++ __tests__/templates/MMM-CTA.njk.spec.js | 34 +++++++++++++++++++++++++ package.json | 2 +- templates/MMM-CTA.njk | 28 ++++++++++---------- 6 files changed, 66 insertions(+), 14 deletions(-) diff --git a/MMM-CTA.js b/MMM-CTA.js index e427da7..3044563 100644 --- a/MMM-CTA.js +++ b/MMM-CTA.js @@ -16,6 +16,7 @@ Module.register('MMM-CTA', { maxResultsTrain: 5, routeIcons: true, suffixStyle: 'long', + showHeaders: true, stops: [], }, @@ -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) => ({ diff --git a/README.md b/README.md index 7954eda..c16eb3a 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ var config = { | `maxResultsBus` | *Optional* | Maximum number of bus results to display
Default `5` | | `maxResultsTrain` | *Optional* | Maximum number of train results to display
Default `5` | | `routeIcons` | *Optional* | True/False - Display icons next to routes.
Default `true` | +| `showHeaders` | *Optional* | True/False - Display headers for each stop.
Default `true` | | `suffixStyle` | *Optional* | Style of suffix for the arrival time. `long`, `short`, or `none`
Default `long` | ### `stops` option diff --git a/__tests__/MMM-CTA.spec.js b/__tests__/MMM-CTA.spec.js index 024f81e..e1d7615 100644 --- a/__tests__/MMM-CTA.spec.js +++ b/__tests__/MMM-CTA.spec.js @@ -25,6 +25,7 @@ it('has a default config', () => { maxResultsBus: 5, routeIcons: true, suffixStyle: 'long', + showHeaders: true, stops: [], }); }); @@ -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', @@ -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', () => { @@ -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', diff --git a/__tests__/templates/MMM-CTA.njk.spec.js b/__tests__/templates/MMM-CTA.njk.spec.js index 5812a20..2c441dd 100644 --- a/__tests__/templates/MMM-CTA.njk.spec.js +++ b/__tests__/templates/MMM-CTA.njk.spec.js @@ -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', () => { diff --git a/package.json b/package.json index 4ee0568..b79067d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/templates/MMM-CTA.njk b/templates/MMM-CTA.njk index d071240..683fcc3 100644 --- a/templates/MMM-CTA.njk +++ b/templates/MMM-CTA.njk @@ -22,20 +22,22 @@ - - {% if stop.arrivals.length %} - {% if routeIcons %} - - {% endif %} - - {{ "DIRECTION" | translate }} - + {% if showHeaders %} + + {% if stop.arrivals.length %} + {% if routeIcons %} + + {% endif %} + + {{ "DIRECTION" | translate }} + - - {{ "ARRIVAL" | translate }} - - {% endif %} - + + {{ "ARRIVAL" | translate }} + + {% endif %} + + {% endif %} {% if stop.arrivals.length %}