diff --git a/app/components/submissions-repoid-cell/index.js b/app/components/submissions-repoid-cell/index.js index 649f04b8..d2261453 100644 --- a/app/components/submissions-repoid-cell/index.js +++ b/app/components/submissions-repoid-cell/index.js @@ -9,8 +9,6 @@ export default class SubmissionsRepoidCell extends Component { @tracked repoCopies = null; - jscholarshipCheckString = '/handle/'; - @action async setUpRepoidCell() { const publication = await this.args.record.publication; @@ -50,6 +48,24 @@ export default class SubmissionsRepoidCell extends Component { } } + /** + * Format a repository ID for display. + * If the ID includes one of the markers, return the ID after the marker + * This deals with DSpace handle and item URLs. + */ + formatId(id) { + const markers = ['/handle/', '/items/']; + + for (let marker of markers) { + let index = id.indexOf(marker); + if (index !== -1) { + return id.slice(index + marker.length); + } + } + + return id; + } + /** * Formatted: * [ @@ -73,14 +89,10 @@ export default class SubmissionsRepoidCell extends Component { return rc .filter((repoCopy) => !!repoCopy.externalIds) .map((repoCopy) => { - const check = this.jscholarshipCheckString; - - // If an ID has the 'check' string, only display the sub-string after the 'check' string let ids = repoCopy.externalIds.map((id) => { - // eslint-disable-line return { title: id, - display: id.includes(check) ? id.slice(id.indexOf(check) + check.length) : id, + display: this.formatId(id), }; }); return { diff --git a/tests/integration/components/submissions-repoid-cell-test.js b/tests/integration/components/submissions-repoid-cell-test.js index eb37a01a..32ba3325 100644 --- a/tests/integration/components/submissions-repoid-cell-test.js +++ b/tests/integration/components/submissions-repoid-cell-test.js @@ -13,7 +13,19 @@ module('Integration | Component | submissions repoid cell', (hooks) => { // Inject mocked store that on query returns a single user hooks.beforeEach(function () { let store = Service.extend({ - query: (type, q) => Promise.resolve([EmberObject.create({ id: 'test' })]), + query: (type, q) => + Promise.resolve([ + EmberObject.create({ + id: 'test', + accessUrl: 'https://dspace.example.com/handle/12345/67890', + externalIds: ['https://dspace.example.com/handle/12345/67890'], + }), + EmberObject.create({ + id: 'test2', + accessUrl: 'https://dspace.example.com/items/abcde-12345', + externalIds: ['https://dspace.example.com/items/abcde-12345'], + }), + ]), }); run(() => { @@ -69,4 +81,32 @@ module('Integration | Component | submissions repoid cell', (hooks) => { `); assert.ok(true); }); + + /** + * Make sure the DSpace ids with handles and items are formatted correctly + */ + test('DSpace ids are formatted correctly', async function (assert) { + assert.expect(4); + + const record = EmberObject.create({ + publication: EmberObject.create({ id: '2' }), + }); + this.record = record; + + await render(hbs` + + + + + +`); + + assert.ok(true); + console.log(this.element); + + const lis = this.element.querySelectorAll('li'); + assert.strictEqual(lis.length, 2); + assert.strictEqual(lis[0].textContent.trim(), '12345/67890'); + assert.strictEqual(lis[1].textContent.trim(), 'abcde-12345'); + }); });