From 9ef710b8990aaf67c7cc323a9ed7a9363951726e Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Fri, 22 Dec 2023 23:20:26 +0000 Subject: [PATCH] Add tests for current page filter --- test/lib/filters/current-page.js | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/lib/filters/current-page.js diff --git a/test/lib/filters/current-page.js b/test/lib/filters/current-page.js new file mode 100644 index 00000000..671cdeb4 --- /dev/null +++ b/test/lib/filters/current-page.js @@ -0,0 +1,37 @@ +const assert = require('assert/strict') +const { describe, it } = require('node:test') +const currentPage = require('../../../lib/filters/current-page.js') + +const navigationData = [ + { text: 'Home', href: '/' }, + { text: 'Styles', href: '/styles' } +] + +describe('currentPage filter', () => { + it('Indicates the home page is current', () => { + const result = currentPage(navigationData, '/') + + assert.deepEqual(result, [ + { text: 'Home', href: '/', current: true }, + { text: 'Styles', href: '/styles', current: false } + ]) + }) + + it('Indicates the section page is current', () => { + const result = currentPage(navigationData, '/styles') + + assert.deepEqual(result, [ + { text: 'Home', href: '/', current: false }, + { text: 'Styles', href: '/styles', current: true } + ]) + }) + + it('Indicates the section sub page is current', () => { + const result = currentPage(navigationData, '/styles/colour') + + assert.deepEqual(result, [ + { text: 'Home', href: '/', current: false }, + { text: 'Styles', href: '/styles', current: true } + ]) + }) +})