Skip to content

Commit

Permalink
fix(tabs): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skhamvon authored and dpellier committed Jan 16, 2024
1 parent 006d4f6 commit 7a959d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ describe('spec:ods-tabs-controller', () => {
controller.changeActivePanel('');
});
it('should set active on the first item', () => {
expect(item1.active).toEqual(true);
expect(item2.active).toEqual(false);
expect(item1.active).toBe(true);
expect(item2.active).toBe(false);
});
it('should set active ont the first panel', () => {
expect(panel1.active).toEqual(true);
expect(panel2.active).toEqual(false);
expect(panel1.active).toBe(true);
expect(panel2.active).toBe(false);
});
it('should set default panel to first one in component', () => {
expect(component.panel).toEqual('1');
Expand All @@ -141,12 +141,12 @@ describe('spec:ods-tabs-controller', () => {
controller.changeActivePanel('2');
});
it('should set active on the right item', () => {
expect(item1.active).toEqual(false);
expect(item2.active).toEqual(true);
expect(item1.active).toBe(false);
expect(item2.active).toBe(true);
});
it('should set active ont the right panel', () => {
expect(panel1.active).toEqual(false);
expect(panel2.active).toEqual(true);
expect(panel1.active).toBe(false);
expect(panel2.active).toBe(true);
});
it('should set default panel to right one in component', () => {
expect(component.panel).toEqual('2');
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('spec:ods-tabs-controller', () => {
controller.handleArrowKey(key);

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

it('should do nothing if arrowRight is pressed on last tab', () => {
Expand All @@ -204,8 +204,8 @@ describe('spec:ods-tabs-controller', () => {
const key = new KeyboardEvent('keypress', { code : 'ArrowRight' });
controller.handleArrowKey(key);

expect(item2.active).toEqual(true);
expect(item1.active).toEqual(false);
expect(item2.active).toBe(true);
expect(item1.active).toBe(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(item1.active).toEqual(true);
expect(item2.active).toEqual(false);
expect(item1.active).toBe(true);
expect(item2.active).toBe(false);
});
});

Expand All @@ -227,16 +227,16 @@ describe('spec:ods-tabs-controller', () => {

it('should set contrasted on all items', () => {
controller.propagateContrastedToItems(true);
expect(item1.contrasted).toEqual(true);
expect(item2.contrasted).toEqual(true);
expect(item1.contrasted).toBe(true);
expect(item2.contrasted).toBe(true);
});

it('should set not contrasted on all items', () => {
item1.contrasted = true;
item2.contrasted = true;
controller.propagateContrastedToItems(false);
expect(item1.contrasted).toEqual(false);
expect(item2.contrasted).toEqual(false);
expect(item1.contrasted).toBe(false);
expect(item2.contrasted).toBe(false);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class OdsTabsController {
if (event.code === 'ArrowLeft') {
const previousPanel = this.tabItems[currentSelectedTabIndex - 1].getAttribute('panel');
this.changeActivePanel(previousPanel!);
this.tabItems.find((tab) => tab.panel === previousPanel )!.focus();
this.tabItems.find((tab) => tab.panel === previousPanel )?.focus();
} else {
const nextPanel = this.tabItems[currentSelectedTabIndex + 1].getAttribute('panel');
this.changeActivePanel(nextPanel!);
this.tabItems.find((tab) => tab.panel === nextPanel )!.focus();
this.tabItems.find((tab) => tab.panel === nextPanel )?.focus();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export class OsdsTabs implements OdsTabsAttribute, OdsTabsEvent {
}

componentDidLoad(): void {
this.controller.changeActivePanel(this.panel);
this.setTabItems();
this.setTabPanels();
this.controller.changeActivePanel(this.panel);
}

render(): JSX.Element {
Expand Down

0 comments on commit 7a959d6

Please sign in to comment.