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 Aug 10, 2023
1 parent b2cc992 commit 8369a16
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 28 deletions.
92 changes: 90 additions & 2 deletions test/nuxeo-audit-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ suite('nuxeo-audit-search', () => {
server = await login();
element = await fixture(
html`
<nuxeo-audit-search name="document-history" id="document-history" .document=${document}"> </nuxeo-audit-search>
`,
<nuxeo-audit-search name="document-history" id="document-history" .document=${document}"> </nuxeo-audit-search>
`,
);
});

Expand All @@ -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 2:08 PM');
});
});
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('');
});
});
});
88 changes: 62 additions & 26 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 Expand Up @@ -142,37 +162,53 @@ suite('nuxeo-document-activity', () => {
});

test('Should gather the download actions as one group', async () => {
const a = {
extended: {
clientReason: 'download',
const original = [
{
extended: {
clientReason: 'download',
},
eventDate: '2022-12-15T08:38:12.665Z',
principalName: 'John Doe',
},
eventDate: '2022-12-15T08:38:12.665Z',
principalName: 'John Doe',
};
const b = {
extended: {
clientReason: 'download',
{
extended: {
clientReason: 'download',
},
eventDate: '2022-12-15T08:36:12.665Z',
principalName: 'John Doe',
},
eventDate: '2022-12-15T08:36:12.665Z',
principalName: 'John Doe',
};
expect(element._areGatherableActivities(a, b)).to.equal(true);
];
const expected = [
{
extended: { clientReason: 'download' },
eventDate: '2022-12-15T08:38:12.665Z',
principalName: 'John Doe',
},
];
expect(element._gatherDuplicatedActivities(original)[0].extended.clientReason).to.equal(
expected[0].extended.clientReason,
);
expect(element._gatherDuplicatedActivities(original)[0].eventDate).to.equal(expected[0].eventDate);
expect(element._gatherDuplicatedActivities(original)[0].principalName).to.equal(expected[0].principalName);
expect(element._gatherDuplicatedActivities(original).length).to.equal(1);
});
test('Should not group non-gatherable activities', async () => {
const a = {
extended: {
clientReason: 'download',
const original = [
{
extended: {
clientReason: 'download',
},
eventDate: '2022-12-15T08:38:12.665Z',
principalName: 'John Doe',
},
eventDate: '2022-12-15T08:38:12.665Z',
principalName: 'John Doe',
};
const b = {
eventId: 'documentCreated',
extended: {},
eventDate: '2022-12-15T08:36:12.665Z',
principalName: 'John Doe',
};
expect(element._areGatherableActivities(a, b)).to.equal(false);
{
eventId: 'documentCreated',
extended: {},
eventDate: '2022-12-15T08:36:12.665Z',
principalName: 'John Doe',
},
];
expect(element._gatherDuplicatedActivities(original).length).to.equal(2);
});
});
});
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 8369a16

Please sign in to comment.