|
1 | 1 | import OptionManager from './optionManager.js';
|
2 | 2 | import React from 'react';
|
| 3 | +import DefaultOptions from './defaultOptions.js'; |
| 4 | +import DefaultTabInnerComponent from '../../../tab/defaulTabInner.js'; |
3 | 5 | let obj;
|
4 | 6 | beforeEach(() => {
|
5 |
| - const options = {}; |
| 7 | + const options = { |
| 8 | + tabs: [{ id: '1', title: 'a' }, { id: '2', title: 'b' }] |
| 9 | + }; |
6 | 10 | obj = new (OptionManager)({ options });
|
7 | 11 | });
|
8 | 12 | afterEach(() => {
|
9 | 13 | obj = null;
|
10 | 14 | });
|
| 15 | +describe('OptionManager constructor : ', () => { |
| 16 | + test('it should throw an error when is called with undefined parameter', () => { |
| 17 | + expect.assertions(2); |
| 18 | + try { |
| 19 | + const obj = new (OptionManager)(); |
| 20 | + } catch (er) { |
| 21 | + expect(1).toBe(1); |
| 22 | + } |
| 23 | + try { |
| 24 | + const obj = new (OptionManager)(undefined); |
| 25 | + } catch (er) { |
| 26 | + expect(1).toBe(1); |
| 27 | + } |
| 28 | + }); |
| 29 | + test('object parameter should have options property', () => { |
| 30 | + expect.assertions(1); |
| 31 | + try { |
| 32 | + const obj = new (OptionManager)({}); |
| 33 | + } catch (er) { |
| 34 | + expect(1).toBe(1); |
| 35 | + } |
| 36 | + }); |
| 37 | + test('parameter should be type of an object', () => { |
| 38 | + expect.assertions(1); |
| 39 | + try { |
| 40 | + const obj = new (OptionManager)([]); |
| 41 | + } catch (er) { |
| 42 | + expect(1).toBe(1); |
| 43 | + } |
| 44 | + }); |
| 45 | + test('structure of setting property', () => { |
| 46 | + const _setting = { |
| 47 | + tabClass: 'rc-dyn-tabs-tab', |
| 48 | + titleClass: 'rc-dyn-tabs-title', |
| 49 | + iconClass: 'rc-dyn-tabs-icon', |
| 50 | + selectedClass: 'rc-dyn-tabs-selected', |
| 51 | + hoverClass: 'rc-dyn-tabs-hover', |
| 52 | + tablistClass: 'rc-dyn-tabs-tablist', |
| 53 | + closeClass: 'rc-dyn-tabs-close', |
| 54 | + panelClass: 'rc-dyn-tabs-panel', |
| 55 | + panellistClass: 'rc-dyn-tabs-panellist', |
| 56 | + disableClass: 'rc-dyn-tabs-disable', |
| 57 | + ltrClass: 'rc-dyn-tabs-ltr', |
| 58 | + rtlClass: 'rc-dyn-tabs-rtl', |
| 59 | + panelIdTemplate: expect.any(Function), |
| 60 | + ariaLabelledbyIdTemplate: expect.any(Function), |
| 61 | + getDefaultTabData: expect.any(Function) |
| 62 | + }; |
| 63 | + expect(obj.setting).toEqual(_setting); |
| 64 | + }); |
| 65 | + test('setting.panelIdTemplate should return result correctly', () => { |
| 66 | + expect(obj.setting.panelIdTemplate('2')).toBe('rc-dyn-tabs-p-2'); |
| 67 | + }); |
| 68 | + test('setting.ariaLabelledbyIdTemplate should return result correctly', () => { |
| 69 | + expect(obj.setting.ariaLabelledbyIdTemplate('2')).toBe('rc-dyn-tabs-l-2'); |
| 70 | + }); |
| 71 | + test('setting.getDefaultTabData should return result correctly', () => { |
| 72 | + const defaultTabData = obj.setting.getDefaultTabData(); |
| 73 | + expect(defaultTabData).toEqual({ |
| 74 | + title: "", |
| 75 | + tooltip: "", |
| 76 | + panelComponent: obj.options.defaultPanelComponent, |
| 77 | + closable: true, |
| 78 | + iconClass: "", |
| 79 | + disable: false, |
| 80 | + id: defaultTabData.id |
| 81 | + }); |
| 82 | + expect(defaultTabData.id.includes('tab_')).toBe(true); |
| 83 | + }); |
| 84 | +}); |
| 85 | +describe('OptionManager options prop : ', () => { |
| 86 | + test('it should be equal to defaultOptions if options parameter is an empty object', () => { |
| 87 | + const obj = new (OptionManager)({ options: {} }); |
| 88 | + expect(obj.options).toEqual(obj._defaultOptions); |
| 89 | + }); |
| 90 | +}); |
11 | 91 | describe('OptionManager.prototype.validateTabData : ', () => {
|
12 | 92 | test('validateTabData method should work correctly with empty object as a parameter', () => {
|
13 | 93 | const tabData = obj.validateTabData({});
|
@@ -57,5 +137,35 @@ describe('OptionManager.prototype.validateTabData : ', () => {
|
57 | 137 | expect(typeof tabData.id === 'string').toBe(true);
|
58 | 138 | });
|
59 | 139 | });
|
| 140 | +describe('OptionManager.prototype.setOption : ', () => { |
| 141 | + it('it can not set tabs option', () => { |
| 142 | + const tabs = obj.getOption('tabs'); |
| 143 | + obj.setOption('tabs', [{ id: '3', title: 'c' }]); |
| 144 | + const newTabs = obj.getOption('tabs'); |
| 145 | + expect(tabs).toBe(newTabs); |
| 146 | + }); |
| 147 | + it('it can not set selectedTabID option', () => { |
| 148 | + const selectedTabID = obj.getOption('selectedTabID'); |
| 149 | + obj.setOption('selectedTabID', '2'); |
| 150 | + const newSelectedTabID = obj.getOption('selectedTabID'); |
| 151 | + expect(selectedTabID).toBe(newSelectedTabID); |
| 152 | + }); |
| 153 | +}); |
| 154 | +describe('OptionManager.prototype.getOption : ', () => { |
| 155 | + it('it returns tabs prop as an immutable array', () => { |
| 156 | + const newTitle = 'newTitle'; |
| 157 | + let oldTitle; |
| 158 | + const tabs = obj.getOption('tabs'); |
| 159 | + oldTitle = tabs[0].title; |
| 160 | + tabs[0].title = newTitle; |
| 161 | + const newTabs = obj.getOption('tabs'); |
| 162 | + expect(newTabs[0].title).toBe(oldTitle); |
| 163 | + }); |
| 164 | + it('it returns undefined when it is called with wrong option name', () => { |
| 165 | + const result = obj.getOption('Tabs'); |
| 166 | + expect(result).toBe(undefined); |
| 167 | + }); |
| 168 | +}); |
| 169 | + |
60 | 170 |
|
61 | 171 |
|
0 commit comments