Skip to content

Commit 1004dc2

Browse files
author
Uditi Mehta
committed
Add tests
1 parent 77bd26b commit 1004dc2

File tree

3 files changed

+103
-23
lines changed

3 files changed

+103
-23
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { render } from '@ember/test-helpers';
2+
import { hbs } from 'ember-cli-htmlbars';
3+
import { setupMirage } from 'ember-cli-mirage/test-support';
4+
import { setupIntl, TestContext } from 'ember-intl/test-support';
5+
import { setupRenderingTest } from 'ember-qunit';
6+
import { module, test } from 'qunit';
7+
8+
import { OsfLinkRouterStub } from 'ember-osf-web/tests/integration/helpers/osf-link-router-stub';
9+
10+
module('Integration | Component | preprint-card', hooks => {
11+
setupRenderingTest(hooks);
12+
setupMirage(hooks);
13+
setupIntl(hooks);
14+
15+
hooks.beforeEach(function(this: TestContext) {
16+
this.store = this.owner.lookup('service:store');
17+
this.intl = this.owner.lookup('service:intl');
18+
});
19+
20+
test('it renders', async function(this: TestContext, assert) {
21+
this.owner.unregister('service:router');
22+
this.owner.register('service:router', OsfLinkRouterStub);
23+
const preprint = server.create('preprint', {
24+
tags: ['a', 'b', 'c'],
25+
description: 'Through the night',
26+
});
27+
server.create('contributor', { preprint, index: 0, bibliographic: true });
28+
server.create('contributor', { preprint, index: 1, bibliographic: true });
29+
server.create('contributor', { preprint, index: 2, bibliographic: true });
30+
const preprintModel = await this.store.findRecord(
31+
'preprint', preprint.id, { include: ['bibliographic_contributors'] },
32+
);
33+
this.set('preprint', preprintModel);
34+
35+
await render(hbs`
36+
<Preprints::-Components::PreprintCard
37+
@preprint={{this.preprint}}
38+
@showTags={{true}}
39+
/>
40+
`);
41+
assert.dom('[data-test-preprint-title]').exists('Preprint title exists');
42+
assert.dom('[data-test-preprint-title]').hasText(preprintModel.title, 'Node title is corrent');
43+
assert.dom('[data-test-contributors-label]').exists('Contributors label exists');
44+
assert.dom('[data-test-contributors-label]').hasText(
45+
this.intl.t('node_card.contributors'),
46+
'Contributors label is correct',
47+
);
48+
});
49+
});

mirage/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ export default function(this: Server) {
354354
osfResource(this, 'preprint');
355355
this.post('/preprints', createPreprint);
356356

357+
this.get('/preprints/:id', (schema, request) => {
358+
const id = request.params.id;
359+
return schema.preprints.find(id);
360+
});
361+
357362
osfNestedResource(this, 'preprint', 'contributors', {
358363
path: '/preprints/:parentID/contributors/',
359364
defaultSortKey: 'index',

mirage/serializers/preprint.ts

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
1515
}
1616

1717
buildRelationships(model: ModelInstance<PreprintMirageModel>) {
18-
const relationships: SerializedRelationships<PreprintMirageModel> = {
19-
provider: {
18+
const relationships: SerializedRelationships<PreprintMirageModel> = {};
19+
20+
if (model.provider) {
21+
relationships.provider = {
2022
data: {
2123
id: model.provider.id,
2224
type: 'preprint-providers',
@@ -27,32 +29,44 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
2729
meta: {},
2830
},
2931
},
30-
},
31-
contributors: {
32+
};
33+
}
34+
35+
if (model.contributors) {
36+
relationships.contributors = {
3237
links: {
3338
related: {
3439
href: `${apiUrl}/v2/preprints/${model.id}/contributors`,
3540
meta: this.buildRelatedLinkMeta(model, 'contributors'),
3641
},
3742
},
38-
},
39-
bibliographicContributors: {
43+
};
44+
}
45+
46+
if (model.bibliographicContributors) {
47+
relationships.bibliographicContributors = {
4048
links: {
4149
related: {
4250
href: `${apiUrl}/v2/preprints/${model.id}/bibliographic_contributors/`,
4351
meta: this.buildRelatedLinkMeta(model, 'bibliographicContributors'),
4452
},
4553
},
46-
},
47-
files: {
54+
};
55+
}
56+
57+
if (model.files) {
58+
relationships.files = {
4859
links: {
4960
related: {
5061
href: `${apiUrl}/v2/preprints/${model.id}/files/`,
5162
meta: this.buildRelatedLinkMeta(model, 'files'),
5263
},
5364
},
54-
},
55-
subjects: {
65+
};
66+
}
67+
68+
if (model.subjects) {
69+
relationships.subjects = {
5670
links: {
5771
self: {
5872
href: `${apiUrl}/v2/preprints/${model.id}/relationships/subjects/`,
@@ -63,43 +77,55 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
6377
meta: this.buildRelatedLinkMeta(model, 'subjects'),
6478
},
6579
},
66-
},
67-
reviewActions: {
80+
};
81+
}
82+
83+
if (model.reviewActions) {
84+
relationships.reviewActions = {
6885
links: {
6986
related: {
7087
href: `${apiUrl}/v2/preprints/${model.id}/review_actions/`,
7188
meta: this.buildRelatedLinkMeta(model, 'reviewActions'),
7289
},
7390
},
74-
},
75-
requests: {
91+
};
92+
}
93+
94+
if (model.requests) {
95+
relationships.requests = {
7696
links: {
7797
related: {
7898
href: `${apiUrl}/v2/preprints/${model.id}/requests/`,
7999
meta: this.buildRelatedLinkMeta(model, 'requests'),
80100
},
81101
},
82-
},
83-
citation: {
102+
};
103+
}
104+
105+
if (model.citation) {
106+
relationships.citation = {
84107
links: {
85108
related: {
86109
href: `${apiUrl}/v2/preprints/${model.id}/citation/`,
87110
meta: {},
88111
},
89112
},
90-
},
91-
identifiers: {
113+
};
114+
}
115+
116+
if (model.identifiers) {
117+
relationships.identifiers = {
92118
links: {
93119
related: {
94120
href: `${apiUrl}/v2/preprints/${model.id}/identifiers/`,
95121
meta: this.buildRelatedLinkMeta(model, 'identifiers'),
96122
},
97123
},
98-
},
99-
};
124+
};
125+
}
100126

101127
if (model.node) {
102-
relationships['node'] = {
128+
relationships.node = {
103129
links: {
104130
related: {
105131
href: `${apiUrl}/v2/nodes/${model.nodeId}`,
@@ -110,7 +136,7 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
110136
}
111137

112138
if (model.primaryFile) {
113-
relationships['primaryFile'] = {
139+
relationships.primaryFile = {
114140
links: {
115141
related: {
116142
href: `${apiUrl}/v2/files/${model.primaryFile.id}/`,
@@ -120,7 +146,7 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
120146
};
121147
}
122148

123-
if (model.license !== null) {
149+
if (model.license) {
124150
const { id } = model.license;
125151
relationships.license = {
126152
data: {

0 commit comments

Comments
 (0)