Skip to content

Commit

Permalink
fix(tabs): fix controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored and dpellier committed Jan 16, 2024
1 parent 82b3e5d commit 6a20fac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ describe('spec:ods-tabs-controller', () => {
});

item1 = document.createElement('osds-tab-bar-item') as OsdsTabBarItem & HTMLElement;
item1.panel = '1';
item1.setAttribute('panel','1');
item2 = document.createElement('osds-tab-bar-item') as OsdsTabBarItem & HTMLElement;
item2.panel = '2';
item2.setAttribute('panel','2');

panel1 = document.createElement('osds-tabs-panel') as OsdsTabsPanel & HTMLElement;
panel1.name = '1';
Expand Down Expand Up @@ -204,8 +204,8 @@ describe('spec:ods-tabs-controller', () => {
const key = new KeyboardEvent('keypress', { code : 'ArrowRight' });
controller.handleArrowKey(key);

expect(item1.getAttribute('active')).toEqual("");
expect(item2.getAttribute('active')).toEqual(null);
expect(item2.active).toEqual(true);
expect(item1.active).toEqual(false);
});

it('should set active to tab 1', () => {
Expand All @@ -215,8 +215,8 @@ describe('spec:ods-tabs-controller', () => {
const key = new KeyboardEvent('keypress', { code : 'ArrowLeft' });
controller.handleArrowKey(key);

expect(item2.getAttribute('active')).toEqual("");
expect(item1.getAttribute('active')).toEqual(null);
expect(item1.active).toEqual(true);
expect(item2.active).toEqual(false);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class OdsTabsController {
changeActivePanel(panel: string): void {
const items = this.tabItems;
// if not item found, select the first one
if (!items.find((item) => item.panel === panel) && items.length) {
panel = items[0].panel;
if (!items.find((item) => item.getAttribute('panel') === panel) && items.length) {
panel = items[0].getAttribute('panel')!;
}
items.forEach((item) => item.active = item.panel === panel);
items.forEach((item) => item.active = item.getAttribute('panel') === panel);
this.tabPanels.forEach((tabPanel) => tabPanel.active = tabPanel.name === panel);
if (this.component.panel !== panel) {
this.component.panel = panel;
Expand Down

0 comments on commit 6a20fac

Please sign in to comment.