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

[DRAFT] Additional Tests for the Preprints index page #1931

Open
wants to merge 3 commits into
base: feature/search-improvements
Choose a base branch
from
Open
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: 1 addition & 1 deletion app/preprints/-components/branded-footer/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default class BrandedFooter extends Component<InputArgs> {
footerLinks = this.args.footerLinks;

get hasFooters(): boolean {
return this.footerLinks !== '';
return this.footerLinks !== '' && this.footerLinks !== undefined;
}
}
2 changes: 1 addition & 1 deletion app/preprints/-components/branded-footer/template.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#if this.hasFooters}}
<div local-class='branded-footer-links'>
<div local-class='branded-footer-links' data-test-footer-links>
{{html-safe this.footerLinks}}
</div>
{{/if}}
20 changes: 4 additions & 16 deletions lib/osf-components/addon/components/branded-header/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';
import Media from 'ember-responsive';

import ProviderModel from 'ember-osf-web/models/provider';
import Analytics from 'ember-osf-web/services/analytics';
import { tracked } from '@glimmer/tracking';
import { requiredAction } from 'ember-osf-web/decorators/component';
Expand All @@ -23,7 +22,6 @@ export default class BrandedHeader extends Component<InputArgs> {
@requiredAction onSearch!: (value: string) => void;
@tracked showingHelp = false;

providerModel?: ProviderModel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem related to adding new tests. This would have been a good addition to the "Changes" section of the PR, to let reviewers know that this is expected and what's going on here. Do you not have a providerModel any more?

notBranded = true;
localClassNameBindings = ['notBranded:Header'];
today = new Date();
Expand All @@ -43,20 +41,14 @@ export default class BrandedHeader extends Component<InputArgs> {
: this.intl.t(`${this.args.translationParent}.header.search_placeholder`);
}

@computed('providerModel.name', 'args.translationParent')
@computed('args.translationParent')
get headerAriaLabel() {
return this.providerModel ?
this.providerModel.name.concat(' ', this.intl.t(`${this.args.translationParent}.header.registrations`))
: this.intl.t(`${this.args.translationParent}.header.osf_registrations`);
return this.intl.t(`${this.args.translationParent}.header.osf_registrations`);
}

@action
onSubmit() {
if (this.providerModel) {
this.analytics.click('link', `Discover - Search ${this.providerModel.name}`, this.value);
} else {
this.analytics.click('link', 'Discover - Search', this.value);
}
this.analytics.click('link', 'Discover - Search', this.value);
this.args.onSearch(this.value);
}

Expand All @@ -68,11 +60,7 @@ export default class BrandedHeader extends Component<InputArgs> {
@action
keyPress(event: KeyboardEvent) {
if (event.keyCode !== 13) {
if (this.providerModel) {
this.analytics.track('input', 'onkeyup', `Discover - Search ${this.providerModel.name}`, this.value);
} else {
this.analytics.track('input', 'onkeyup', 'Discover - Search', this.value);
}
this.analytics.track('input', 'onkeyup', 'Discover - Search', this.value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@
{{/if}}
</form>
</div>
{{#if @providerModel.htmlSafeDescription}}
<div local-class='provider-description' data-test-provider-description>
{{@providerModel.htmlSafeDescription}}
</div>
{{/if}}

<div local-class='example-container'>
{{yield (hash row=(element ''))}}
Expand Down
45 changes: 45 additions & 0 deletions tests/acceptance/preprints/branded-footer-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Acceptance | preprints | branded-footer', hooks => {
setupRenderingTest(hooks);

test('it inserts the footerLink when present', async function(assert) {
// Given no list is provided
// When the component is rendered
await render(hbs`
<Preprints::-components::BrandedFooter
@footerLinks='these are the footer links'
>
</Preprints::-components::BrandedFooter>
`);

// Then the footer links are verified
assert.dom('[data-test-footer-links]').hasText('these are the footer links', 'The footer links are present');
});

test('it does not insert the footerLink when undefined', async function(assert) {
// Given no list is provided
// When the component is rendered
await render(hbs`<Preprints::-components::BrandedFooter/>`);

// Then the footer links are verified
assert.dom('[data-test-footer-links]').doesNotExist('The footer links are not present');
});

test('it does no insert the footerLink when it an empty string', async function(assert) {
// Given no list is provided
// When the component is rendered
await render(hbs`
<Preprints::-components::BrandedFooter
@footerLinks=''
>
</Preprints::-components::BrandedFooter>
`);

// Then the footer links are verified
assert.dom('[data-test-footer-links]').doesNotExist('The footer links are not present');
});
});
27 changes: 25 additions & 2 deletions tests/integration/components/branded-header/component-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,51 @@ module('Integration | Component | branded-header', hooks => {
@showHelp=true
@searchPlaceholder={{this.searchPlaceholder}}
as |branded-header|
></BrandedHeader>
>
{{#branded-header.lead}}
<div data-test-lead-yield>
This is the lead
</div>
{{/branded-header.lead}}
{{#branded-header.row}}
<div data-test-row-yield>
This is the row
</div>
{{/branded-header.row}}
</BrandedHeader>
`);

// Then the header container is verified
const headerContainer = this.element.querySelector('[data-test-header-container]');
assert.dom(headerContainer).exists();

// Then the header container is verified
// And the brand logo container is verified
assert.dom(this.element.querySelector('[data-test-brand-logo]')).hasAttribute('aria-label', 'OSF Preprints');

// And the perform search button is verified
// eslint-disable-next-line max-len
assert.dom(this.element.querySelector('[data-test-perform-search-button]')).hasAttribute('aria-label', 'Perform search');
assert.dom(this.element.querySelector('[data-test-perform-search-button]')).hasAttribute('type', 'button');

// And the search icon is verified
// eslint-disable-next-line max-len
assert.dom(this.element.querySelector('[data-test-search-icon]')).hasAttribute('data-icon', 'search');

// And the search box is verified
// eslint-disable-next-line max-len
assert.dom(this.element.querySelector('[data-test-search-box]')).hasAttribute('placeholder', 'preprints.header.search_placeholder');

// And the search help button is verified
// eslint-disable-next-line max-len
assert.dom(this.element.querySelector('[data-test-search-help-button]')).hasAttribute('aria-label', 'Search help');
assert.dom(this.element.querySelector('[data-test-search-help-button]')).hasAttribute('type', 'button');

// And the lead yield is verified
// eslint-disable-next-line max-len
assert.dom(this.element.querySelector('[data-test-lead-yield]')).hasText('This is the lead', 'The lead in yielded correctly');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.dom(this.element.querySelector('[data-test-lead-yield]')).hasText('This is the lead', 'The lead in yielded correctly');
assert.dom(this.element.querySelector('[data-test-lead-yield]')).hasText('This is the lead', 'The lead is yielded correctly');


// And the row yield is verified
// eslint-disable-next-line max-len
assert.dom(this.element.querySelector('[data-test-row-yield]')).hasText('This is the row', 'The lead in yielded correctly');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.dom(this.element.querySelector('[data-test-row-yield]')).hasText('This is the row', 'The lead in yielded correctly');
assert.dom(this.element.querySelector('[data-test-row-yield]')).hasText('This is the row', 'The row is yielded correctly');

});
});