From a543c25e5522e8b41ce661529d3c837be87bb357 Mon Sep 17 00:00:00 2001 From: Brian Pilati Date: Fri, 11 Aug 2023 13:18:46 -0600 Subject: [PATCH] Added taxonomy tests --- .../-components/branded-footer/template.hbs | 2 +- .../taxonomy-top-list/component.ts | 4 + .../taxonomy-top-list/template.hbs | 4 +- app/preprints/index/template.hbs | 2 +- .../preprints/taxonomy-top-list-test.ts | 156 ++++++++++++++++++ 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 tests/acceptance/preprints/taxonomy-top-list-test.ts diff --git a/app/preprints/-components/branded-footer/template.hbs b/app/preprints/-components/branded-footer/template.hbs index af11557a71..ffee3b5b5a 100644 --- a/app/preprints/-components/branded-footer/template.hbs +++ b/app/preprints/-components/branded-footer/template.hbs @@ -1,5 +1,5 @@ {{#if this.hasFooters}}
- {{html-safe this.footerLinks 'footer-links'}} + {{html-safe this.footerLinks}}
{{/if}} \ No newline at end of file diff --git a/app/preprints/-components/taxonomy-top-list/component.ts b/app/preprints/-components/taxonomy-top-list/component.ts index 029bb65c61..7928328c24 100644 --- a/app/preprints/-components/taxonomy-top-list/component.ts +++ b/app/preprints/-components/taxonomy-top-list/component.ts @@ -62,6 +62,10 @@ export default class TaxonomyTopList extends Component { } + if (pairedList.length > 0 && typeof this.args.provider !== 'string') { + throw new Error('A provider string must be provided with a valid list'); + } + return pairedList; } } diff --git a/app/preprints/-components/taxonomy-top-list/template.hbs b/app/preprints/-components/taxonomy-top-list/template.hbs index cabcea5f22..d49088def3 100644 --- a/app/preprints/-components/taxonomy-top-list/template.hbs +++ b/app/preprints/-components/taxonomy-top-list/template.hbs @@ -1,7 +1,7 @@ {{#each this.sortedList as |pair|}} -
+
{{#each pair as |subject|}} -
+
- {{html-safe this.theme.provider.advisoryBoard 'advisory-board'}} + {{html-safe this.theme.provider.advisoryBoard}}
{{/if}} diff --git a/tests/acceptance/preprints/taxonomy-top-list-test.ts b/tests/acceptance/preprints/taxonomy-top-list-test.ts new file mode 100644 index 0000000000..bf7c42fe77 --- /dev/null +++ b/tests/acceptance/preprints/taxonomy-top-list-test.ts @@ -0,0 +1,156 @@ +import { render } from '@ember/test-helpers'; +import Ember from 'ember'; +import { hbs } from 'ember-cli-htmlbars'; +import { EnginesTestContext } from 'ember-engines/test-support'; +import SubjectModel from 'ember-osf-web/models/subject'; +import { setupRenderingTest } from 'ember-qunit'; +import { module, test } from 'qunit'; + +module('Acceptance | preprints | taxonomy-top-list', hooks => { + setupRenderingTest(hooks); + + test('it creates no rows when the list is undefined', async function(this: EnginesTestContext,assert) { + // Given no list is provided + // When the component is rendered + await render(hbs` + + + `); + + // Then the subject container is verified + assert.dom('[data-test-subject-container]').doesNotExist('no subjects are displayed'); + }); + + test('it creates no rows when the list is empty', async function(this: EnginesTestContext,assert) { + // Given the taxonomy list is created with two subjects + this.set('list', [ ]); + + // When the component is rendered + await render(hbs` + + + `); + + // Then the subject container is verified + assert.dom('[data-test-subject-container]').doesNotExist('no subjects are displayed'); + }); + + test('it throws an error with a list and no provider', async function(this: EnginesTestContext,assert) { + Ember.onerror = (error: Error) => { + assert.equal(error.message, + 'A provider string must be provided with a valid list'); + }; + + // Given the taxonomy list is created with two subjects + this.set('list', [ + { + text: 'elephant', + taxonomyName: 'forgetful', + } as SubjectModel, + ]); + + // When the component is rendered + await render(hbs` + + + `); + }); + + test('it creates a row of two subjects in desktop mode', async function(this: EnginesTestContext,assert) { + // Given the taxonomy list is created with two subjects + this.set('list', [ + { + text: 'elephant', + taxonomyName: 'forgetful', + } as SubjectModel, + { + text: 'deer', + taxonomyName: 'The sneaky', + } as SubjectModel, + ]); + + // When the component is rendered + await render(hbs` + + + `); + + // Then the subject container is verified + const subjectContainers = this.element.querySelectorAll('[data-test-subject-container]'); + assert.equal(subjectContainers.length, 1, 'The subject container has 1 container'); + + // And the link containers are verified + const linkContainers = subjectContainers[0].querySelectorAll('[data-test-taxonomy-container]'); + assert.equal(linkContainers.length, 2, 'The link container is grouped in two'); + + // And the first link is verified to be sorted correctly + const links = linkContainers[0].querySelectorAll('[data-test-taxonomy-link]'); + assert.dom(links[0]).hasText('deer', 'The first link is deer'); + // And the href is corrected + // eslint-disable-next-line max-len + assert.dom(links[0]).hasAttribute('href', 'preprints/outdoorLife/discover?subject=The sneaky', 'The href is blank'); + }); + + test('it creates two rows of two and one subject in desktop mode', async function(this: EnginesTestContext,assert) { + // Given the taxonomy list is created with two subjects + this.set('list', [ + { + text: 'elephant', + taxonomyName: 'forgetful', + } as SubjectModel, + { + text: 'bamboon', + taxonomyName: 'The great red bum', + } as SubjectModel, + { + text: 'deer', + taxonomyName: 'The sneaky', + } as SubjectModel, + ]); + + // When the component is rendered + await render(hbs` + + + `); + + + // Then the subject container is verified + const subjectContainers = this.element.querySelectorAll('[data-test-subject-container]'); + assert.equal(subjectContainers.length, 2, 'The subject container has 1 container'); + + // And the link containers are verified + let linkContainers = subjectContainers[0].querySelectorAll('[data-test-taxonomy-container]'); + assert.equal(linkContainers.length, 2, 'The link container is grouped in two'); + + // And the first link is verified to be sorted correctly + let links = linkContainers[1].querySelectorAll('[data-test-taxonomy-link]'); + assert.dom(links[0]).hasText('deer', 'The first link is deer'); + // And the href is corrected + // eslint-disable-next-line max-len + assert.dom(links[0]).hasAttribute('href', 'preprints/outdoorLife/discover?subject=The sneaky', 'The href is blank'); + + linkContainers = subjectContainers[1].querySelectorAll('[data-test-taxonomy-container]'); + assert.equal(linkContainers.length, 1, 'The link container is grouped in one'); + + // And the third link is verified to be sorted correctly + links = linkContainers[0].querySelectorAll('[data-test-taxonomy-link]'); + assert.dom(links[0]).hasText('elephant', 'The first link is elephant'); + // And the href is corrected + // eslint-disable-next-line max-len + assert.dom(links[0]).hasAttribute('href', 'preprints/outdoorLife/discover?subject=forgetful', 'The href is blank'); + }); +});