Skip to content

Commit

Permalink
Add different set of navbar links for preprints
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Nov 13, 2023
1 parent ae41bc1 commit 68caa77
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import CurrentUserService from 'ember-osf-web/services/current-user';
import config from 'ember-osf-web/config/environment';

interface Args {
onLinkClicked: () => void;
}
export default class OsfNavbarPreprintLinks extends Component<Args> {
@service currentUser!: CurrentUserService;

donateURL = `${config.OSF.donateUrl}`;
supportURL = `${config.support.faqPageUrl}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<li data-test-nav-my-preprints-link>
<OsfLink
@href='/myprojects/#preprints/'
data-analytics-name='My preprints'
{{on 'click' @onLinkClicked}}
>
{{t 'navbar.my_preprints'}}
</OsfLink>
</li>
{{#if this.currentUser.user.canViewReviews}}
<li data-test-nav-reviews-link>
<OsfLink
@href='/reviews/'
data-analytics-name='My reviews'
{{on 'click' @onLinkClicked}}
>
{{t 'navbar.reviews'}}
</OsfLink>
</li>
{{/if}}
<li data-test-nav-submit-preprint-link>
<OsfLink
@href='/preprints/submit/'
data-analytics-name='Add a preprint'
{{on 'click' @onLinkClicked}}
>
{{t 'navbar.add_a_preprint' preprintWord=(t 'documentType.preprint.singularCapitalized')}}
</OsfLink>
</li>
<li data-test-nav-search-link>
<OsfLink
@route='search'
@queryParams={{hash resourceType='Preprint'}}
data-analytics-name='Search'
{{on 'click' @onLinkClicked}}
>
{{t 'navbar.search'}}
</OsfLink>
</li>
<li data-test-nav-support-link>
<OsfLink
@href={{this.supportURL}}
data-analytics-name='Support'
{{on 'click' @onLinkClicked}}
>
{{t 'navbar.support'}}
</OsfLink>
</li>
<li class='navbar-donate-button' data-test-nav-donate-link>
<OsfLink
@href={{this.donateURL}}
data-analytics-name='Donate'
{{on 'click' @onLinkClicked}}
>
{{t 'navbar.donate'}}
</OsfLink>
</li>
9 changes: 8 additions & 1 deletion lib/osf-components/addon/components/osf-navbar/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@
links=(component 'osf-navbar/x-links'
onLinkClicked=(action 'onLinkClicked')
)
preprintLinks=(component 'osf-navbar/preprint-links'
onLinkClicked=(action 'onLinkClicked')
)
) as |ctx|}}
{{#if (has-block)}}
{{yield ctx}}
{{else}}
{{ctx.links}}
{{#if (eq this._activeService.name 'PREPRINTS')}}
{{ctx.preprintLinks}}
{{else}}
{{ctx.links}}
{{/if}}
{{/if}}
{{/let}}
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'osf-components/components/osf-navbar/preprint-links/component';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'osf-components/components/osf-navbar/preprint-links/template';
41 changes: 41 additions & 0 deletions tests/integration/components/osf-navbar/component-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { module, test } from 'qunit';

const routerStub = Service.extend({
currentURL: '/',
currentRouteName: 'dashboard',
urlFor() {
return '/FakeURL';
},
Expand Down Expand Up @@ -37,6 +38,10 @@ module('Integration | Component | osf-navbar', hooks => {
await render(hbs`<OsfNavbar />`);
assert.dom('.service-name').includesText('OSF');
assert.dom('.current-service').hasText('HOME');
assert.dom('[data-test-nav-my-projects-link]').exists();
assert.dom('[data-test-nav-search-link]').exists();
assert.dom('[data-test-nav-support-link]').exists();
assert.dom('[data-test-nav-donate-link]').exists();
});

test('service-dropdown: logged in', async function(assert) {
Expand Down Expand Up @@ -72,4 +77,40 @@ module('Integration | Component | osf-navbar', hooks => {
await click('[data-test-service-dropdown]');
await percySnapshot(assert);
});

test('osf-navbar: preprints, no moderation', async function(assert) {
this.owner.lookup('service:session').set('isAuthenticated', true);
this.owner.lookup('service:router').set('currentRouteName', 'preprints.place');

await render(hbs`<OsfNavbar />`);

assert.dom('.service-name').includesText('OSF');
assert.dom('.current-service').hasText('PREPRINTS');
assert.dom('[data-test-nav-my-preprints-link]').exists();
assert.dom('[data-test-nav-submit-preprint-link]').exists();
assert.dom('[data-test-nav-reviews-link]').doesNotExist();

assert.dom('[data-test-nav-search-link]').exists();
assert.dom('[data-test-nav-donate-link]').hasClass('navbar-donate-button');

assert.dom('[data-test-nav-my-projects-link]').doesNotExist();
});

test('osf-navbar: preprints with moderation', async function(assert) {
this.owner.lookup('service:session').set('isAuthenticated', true);
this.owner.lookup('service:router').set('currentRouteName', 'preprints.somewhere');
// this.owner.register('service:current-user', currentUserStub);
this.owner.lookup('service:current-user').set('user', { canViewReviews: true });

await render(hbs`<OsfNavbar />`);

assert.dom('.service-name').includesText('OSF');
assert.dom('.current-service').hasText('PREPRINTS');
assert.dom('[data-test-nav-my-preprints-link]').exists();
assert.dom('[data-test-nav-submit-preprint-link]').exists();
assert.dom('[data-test-nav-reviews-link]').exists();

assert.dom('[data-test-nav-my-projects-link]').doesNotExist();
await percySnapshot(assert);
});
});

0 comments on commit 68caa77

Please sign in to comment.