Skip to content

Commit abcfa27

Browse files
authored
Merge pull request #1030 from futa-ikeda/feature/read-only-contributor-card
Update contributor card to handle unregistered users
2 parents 0026595 + c08a56e commit abcfa27

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

lib/osf-components/addon/components/contributors/card/readonly/template.hbs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
height='30'
1010
width='30'
1111
>
12-
<OsfLink
13-
data-test-contributor-link={{@contributor.id}}
14-
data-analytics-name='View user'
15-
@route='guid-user'
16-
@models={{array @contributor.users.id}}
17-
>
18-
{{@contributor.users.fullName}}
19-
</OsfLink>
12+
{{#if @contributor.unregisteredContributor}}
13+
{{@contributor.unregisteredContributor}}
14+
{{else}}
15+
<OsfLink
16+
data-test-contributor-link={{@contributor.id}}
17+
data-analytics-name='View user'
18+
@route='guid-user'
19+
@models={{array @contributor.users.id}}
20+
>
21+
{{@contributor.users.fullName}}
22+
</OsfLink>
23+
{{/if}}
2024
</span>
2125
<span
2226
data-test-contributor-permission={{@contributor.id}}

mirage/factories/contributor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ interface ContributorTraits {
1111
export default Factory.extend<Contributor & ContributorTraits>({
1212
permission: faker.list.cycle(...Object.values(Permission)),
1313
bibliographic: true,
14-
unregisteredContributor() {
15-
return faker.random.number(5) ? undefined : faker.name.firstName();
16-
},
14+
unregisteredContributor: undefined,
1715
index(i: number) {
1816
return i;
1917
},

tests/integration/components/contributors/component-test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ module('Integration | Component | contributors', hooks => {
7070
assert.ok(true, 'No a11y errors on page');
7171
});
7272

73+
test('read-only user card renders unregistered contributor', async function(assert) {
74+
const registration = server.create('draft-registration');
75+
const unregContributor = server.create('contributor', {
76+
draftRegistration: registration,
77+
}, 'unregistered');
78+
const registrationModel = await this.store.findRecord('draft-registration', registration.id);
79+
this.set('node', registrationModel);
80+
81+
await render(hbs`<Contributors::Widget @node={{this.node}} />`);
82+
const userPermission = t(`osf-components.contributors.permissions.${unregContributor.permission}`);
83+
const userCitation = t(`osf-components.contributors.citation.${unregContributor.bibliographic}`);
84+
85+
assert.dom('[data-test-contributor-card]').exists();
86+
assert.dom('[data-test-contributor-card-main]').exists();
87+
assert.dom('[data-test-contributor-gravatar]').exists();
88+
assert.dom('[data-test-contributor-link]').doesNotExist();
89+
assert.dom('[data-test-contributor-card-main]')
90+
.containsText(unregContributor.unregisteredContributor!);
91+
assert.dom(`[data-test-contributor-permission="${unregContributor.id}"]`)
92+
.hasText(userPermission);
93+
assert.dom(`[data-test-contributor-citation="${unregContributor.id}"]`)
94+
.hasText(userCitation);
95+
await a11yAudit(this.element);
96+
assert.ok(true, 'No a11y errors on page');
97+
});
98+
7399
test('editable user card renders', async function(assert) {
74100
const draftRegistration = server.create('draft-registration');
75101
const contributor = server.create('contributor', {

0 commit comments

Comments
 (0)