Skip to content

Commit

Permalink
WEBUI-1232: Unit test cases coverage improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuljain-dev committed Sep 6, 2023
1 parent ee86352 commit b020907
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
88 changes: 88 additions & 0 deletions test/nuxeo-audit-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
});
});
20 changes: 20 additions & 0 deletions test/nuxeo-document-activity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 23 additions & 0 deletions test/nuxeo-document-blob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
});
});
8 changes: 8 additions & 0 deletions test/nuxeo-picture-formats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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('');
});
});
});

0 comments on commit b020907

Please sign in to comment.