diff --git a/test/nuxeo-audit-search.test.js b/test/nuxeo-audit-search.test.js index 2ff67d8bcb..8dcc41dd7e 100644 --- a/test/nuxeo-audit-search.test.js +++ b/test/nuxeo-audit-search.test.js @@ -101,5 +101,93 @@ suite('nuxeo-audit-search', () => { sinon.spy(element, '_formatComment'); expect(element._formatComment('file1.jpeg', 'view')).to.equal('View: [file1.jpeg]'); }); + test('Should return the comment only', () => { + sinon.spy(element, '_formatComment'); + expect(element._formatComment('file1.jpeg', '')).to.equal('file1.jpeg'); + }); + test('Should return the formatted date when date is passed as comment', () => { + sinon.spy(element, '_formatComment'); + expect(element._formatComment('2022-12-16T08:38:12.665Z', '')).to.equal('December 16, 2022 8:38 AM'); + }); + }); + suite('build params', () => { + test('Should return document id when document and uid is present', () => { + element.events = ['abc']; + element.document = { + uid: '123', + }; + element.category = 'test'; + element.startDate = '2022-12-16T08:38:12.665Z'; + element.endDate = '2022-12-15T08:38:12.665Z'; + sinon.spy(element, '_formatComment'); + element.visible = true; + expect(element.documentId).to.equal(element.document.uid); + }); + test('Should return empty document id when document is not present', () => { + element.events = ['abc']; + element.document = null; + sinon.spy(element, '_formatComment'); + element.visible = true; + expect(element.documentId).to.equal(''); + }); + test('Should return the text View to identify type of download alongwith file name', () => { + sinon.spy(element, '_formatComment'); + element.visible = true; + expect(element._buildParams().principalName).to.equal(''); + }); + }); + suite('get document url', () => { + test('Should not return when docUUID is not present', () => { + const item = { + properties: { + 'file:content': { + appLinks: [], + downloadUrl: null, + data: 'abc.docx?changeToken=1-0', + digest: '2e7d1a1ba7018c048bebdf1d07481ee3', + digestAlgorithm: 'MD5', + encoding: null, + length: '5763', + 'mime-type': 'image/jpeg', + name: 'kitten1 (4).jpeg', + }, + }, + }; + expect(element._getDocumentURL(item)).to.be.undefined; + }); + }); + suite('parse comment', () => { + test('Should not parse when properties are not set', () => { + expect(element._parseComment('file1.jpeg')).to.be.null; + }); + }); + suite('format document', () => { + test('Should not format when properties are not set', () => { + const item = { + properties: { + 'file:content': { + appLinks: [], + downloadUrl: null, + data: 'abc.docx?changeToken=1-0', + digest: '2e7d1a1ba7018c048bebdf1d07481ee3', + digestAlgorithm: 'MD5', + encoding: null, + length: '5763', + 'mime-type': 'image/jpeg', + name: 'kitten1 (4).jpeg', + }, + }, + }; + expect(element._formatDocument(item)).to.equal(''); + expect(element._formatDocument()).to.be.undefined; + }); + }); + suite('format i18n', () => { + test('Should return concat when key is present', () => { + expect(element._formati18n('audit', 1)).to.equal('audit1'); + }); + test('Should not return when key is not present', () => { + expect(element._formati18n('audit')).to.equal(''); + }); }); }); diff --git a/test/nuxeo-document-activity.test.js b/test/nuxeo-document-activity.test.js index 1c2f0e80cc..1b1fd53ec2 100644 --- a/test/nuxeo-document-activity.test.js +++ b/test/nuxeo-document-activity.test.js @@ -108,6 +108,26 @@ suite('nuxeo-document-activity', () => { }); test('Should display the activity name as download when user performs download action', async () => { + element.document = { + 'entity-type': 'document', + contextParameters: { + element: { + entries: [ + { + path: '/default-domain', + title: 'Domain', + type: 'Domain', + uid: '1', + }, + ], + }, + audit: [], + }, + path: '/default-domain/workspaces/my workspace/folder 1/folder 2/folder 3/my file', + title: 'my file', + type: 'File', + uid: '7', + }; const event = { extended: { clientReason: 'download', diff --git a/test/nuxeo-document-blob.test.js b/test/nuxeo-document-blob.test.js index 0e76c65ffc..e6b14463a6 100644 --- a/test/nuxeo-document-blob.test.js +++ b/test/nuxeo-document-blob.test.js @@ -42,5 +42,28 @@ suite('nuxeo-document-blob', () => { }; expect(element._getDownloadBlobUrl()).to.equal('abc.docx?changeToken=1-0'); }); + test('Should fetch download url when docunent is present', () => { + element.document = { + properties: { + 'file:content': { + appLinks: [], + data: 'abc.docx?changeToken=1-0', + digest: '2e7d1a1ba7018c048bebdf1d07481ee3', + digestAlgorithm: 'MD5', + length: '5763', + 'mime-type': 'image/jpeg', + name: 'kitten1 (4).jpeg', + }, + }, + }; + expect(element._getDownloadBlobUrl()).to.equal('abc.docx?changeToken=1-0'); + }); + test('Should not fetch download url when document is not present', () => { + expect(element._getDownloadBlobUrl()).to.equal(''); + }); + test('Should not fetch download url when document properties are not present', () => { + element.document = {}; + expect(element._getDownloadBlobUrl()).to.equal(''); + }); }); }); diff --git a/test/nuxeo-picture-formats.test.js b/test/nuxeo-picture-formats.test.js index fc1b12d5ab..7c8cda5081 100644 --- a/test/nuxeo-picture-formats.test.js +++ b/test/nuxeo-picture-formats.test.js @@ -72,6 +72,11 @@ suite('nuxeo-picture-formats', () => { element.xpath = 'file:content'; expect(element._getAdditionalFormats(document)).to.eql(additionalFormats); }); + test('Should not get additional formats for asset when document is not present', () => { + const additionalFormats = []; + element.xpath = 'file:content'; + expect(element._getAdditionalFormats()).to.eql(additionalFormats); + }); }); suite('fetch download url', () => { @@ -88,5 +93,8 @@ suite('nuxeo-picture-formats', () => { }; expect(element._getDownloadUrl(item)).to.equal('abc.docx?changeToken=1-0'); }); + test('Should not fetch download url when input is not provided', () => { + expect(element._getDownloadUrl()).to.equal(''); + }); }); });