Skip to content

Commit

Permalink
Add content category for items in tag page (#337)
Browse files Browse the repository at this point in the history
* - Added content category (principle/standard/pattern) to docs
- Added `displayContentCategory` to content document list macro - allows category to be displayed in collection view
- Displaying content category in tag page

* Added test to check document category is displayed in tag page and not principle/standard/pattern pages
  • Loading branch information
keithkennedyHO authored Nov 8, 2023
1 parent 8c75716 commit e154ddd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion _includes/layouts/tag.njk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
{{ documentList.contentDocumentList({
headingLevel: 3 if paginationHeading else 2,
classes: "app-document-list--large",
items: collections[tag] | orderPagesByTitle
items: collections[tag] | orderPagesByTitle,
displayContentCategory: true
}) }}

{{ appProseScope(content) if content }}
Expand Down
7 changes: 6 additions & 1 deletion _includes/macros/contentDocumentList.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
{% endif %}
{% if item.data.date or item.data.tags %}
<ul class="app-document-list__item-metadata">
{% if params.displayContentCategory === true and item.data.category %}
<li class="app-document-list__attribute document-category">
{{ item.data.category }}
</li>
{% endif %}
{% if item.data.id %}
<li class="app-document-list__attribute">
{{ item.data.id }}
Expand All @@ -35,4 +40,4 @@
<p class="govuk-body">No documents found.</p>
{% endif %}

{% endmacro %}
{% endmacro %}
32 changes: 32 additions & 0 deletions cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,35 @@ describe('Pagination links', () => {
cy.contains('h1', 'Principles')
})
})

describe('Content category displays in correct listing pages', () => {
it('finds the content category in tag page', () => {
cy.visit(testing_params.TEST_ROOT_URL + '/tags/ways-of-working/')
cy.get('ol.app-document-list').find('.document-category')
.its('length').should('be.gte', 5)
})

it('does not find the content category in principles page', () => {
cy.visit(testing_params.TEST_ROOT_URL)
cy.contains('Read our principles').click()
// No .document-category listed in this page
cy.get('ol.app-document-list').find('.document-category')
.should('have.length', 0)
})

it('does not find the content category in standards page', () => {
cy.visit(testing_params.TEST_ROOT_URL)
cy.contains('Read our standards').click()
// No .document-category listed in this page
cy.get('ol.app-document-list').find('.document-category')
.should('have.length', 0)
})

it('does not find the content category in patterns page', () => {
cy.visit(testing_params.TEST_ROOT_URL)
cy.contains('Read our patterns').click()
// No .document-category listed in this page
cy.get('ol.app-document-list').find('.document-category')
.should('have.length', 0)
})
})
1 change: 1 addition & 0 deletions docs/patterns/patterns.11tydata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
tags: [],
category: 'Pattern',
eleventyComputed: {
viewSource: data => `./docs${data.page.filePathStem}.md?plain=1`
},
Expand Down
1 change: 1 addition & 0 deletions docs/principles/principles.11tydata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
tags: [],
category: 'Principle',
eleventyComputed: {
viewSource: data => `./docs${data.page.filePathStem}.md?plain=1`
},
Expand Down
1 change: 1 addition & 0 deletions docs/standards/standards.11tydata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
tags: [],
category: 'Standard',
eleventyComputed: {
viewSource: data => `./docs${data.page.filePathStem}.md?plain=1`
},
Expand Down

0 comments on commit e154ddd

Please sign in to comment.