Skip to content

Commit

Permalink
NXP-32384: fix unit test for nuxeo-retian-button
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnadipa-dev committed Mar 19, 2024
1 parent 8c14e54 commit fc79347
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nuxeo-retention-web/test/nuxeo-attach-rule-button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
All Hyland product names are registered or unregistered trademarks of Hyland Software, Inc. or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use attachEl file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Expand Down
2 changes: 1 addition & 1 deletion nuxeo-retention-web/test/nuxeo-hold-toggle-button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
All Hyland product names are registered or unregistered trademarks of Hyland Software, Inc. or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use attachEl file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Expand Down
74 changes: 74 additions & 0 deletions nuxeo-retention-web/test/nuxeo-retain-button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
@license
©2023 Hyland Software, Inc. and its affiliates. All rights reserved.
All Hyland product names are registered or unregistered trademarks of Hyland Software, Inc. or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { fixture, html } from '@nuxeo/testing-helpers';
import '../elements/nuxeo-retain-button.js';
import sinon from 'sinon';
import { expect } from 'chai';

window.nuxeo.I18n.language = 'en';
window.nuxeo.I18n.en = window.nuxeo.I18n.en || {};
window.nuxeo.I18n.en['retention.action.retain'] = 'Extend retention';

suite('nuxeo-retain-button', () => {
let attachEl;

setup(async () => {
attachEl = await fixture(html` <nuxeo-retain-button></nuxeo-retain-button> `);
});

suite('test _isAvailable', () => {
test('Should return true if canSetRetention permission is available', async () => {
sinon.stub(attachEl, 'canSetRetention').returns(true);
expect(attachEl._isAvailable()).equal(true);
});

test('Should return false if canSetRetention permission is not available', async () => {
sinon.stub(attachEl, 'canSetRetention').returns(false);
expect(attachEl._isAvailable()).equal(false);
});
});

suite('test _computeLabel', () => {
test('Should return i18n label for extend retention button', async () => {
expect(attachEl._computeLabel()).equal('Extend retention');
});
});

suite('test _toggleDialog', () => {
test('Should toggle dialog', async () => {
sinon.stub(attachEl.$.dialog, 'toggle');
attachEl._toggleDialog();
expect(attachEl.$.dialog.toggle.calledOnce).to.equal(true);
});
});

suite('test _retain', () => {
test('Should toggle dialog', async () => {
sinon.stub(attachEl.$.retainOp, 'execute').resolves();
sinon.spy(attachEl, '_toggleDialog');
sinon.spy(attachEl, 'dispatchEvent');
attachEl.until = '2025-05-09';
attachEl._retain();
expect(attachEl.$.retainOp.params).to.deep.equal({ until: '2025-05-09' });
setTimeout(() => {
expect(attachEl.dispatchEvent.calledOnce).to.equal(true);
expect(attachEl._toggleDialog.calledOnce).to.equal(true);
}, 0);
});
});
});
2 changes: 1 addition & 1 deletion nuxeo-retention-web/test/nuxeo-retention-behavior.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
All Hyland product names are registered or unregistered trademarks of Hyland Software, Inc. or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use retentionBehaviorInstance file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Expand Down
2 changes: 1 addition & 1 deletion nuxeo-retention-web/test/nuxeo-retention-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
All Hyland product names are registered or unregistered trademarks of Hyland Software, Inc. or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use attachEl file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
All Hyland product names are registered or unregistered trademarks of Hyland Software, Inc. or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use attachEl file except in compliance with the License.
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Expand Down

0 comments on commit fc79347

Please sign in to comment.