Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tab): update active tab when value is changed externally #402

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,59 @@ import { newE2EPage } from '@stencil/core/testing';

describe('bq-tab-group', () => {
it('should render', async () => {
const page = await newE2EPage();
await page.setContent(`
const page = await newE2EPage({
html: `
<bq-tab-group value="1">
<bq-tab tab-id="1">Tab 1</bq-tab>
<bq-tab tab-id="2">Tab 2</bq-tab>
</bq-tab-group>
`);
`,
});

const element = await page.find('bq-tab-group');

expect(element).toHaveClass('hydrated');
});

it('should have shadow root', async () => {
const page = await newE2EPage();
await page.setContent(`
const page = await newE2EPage({
html: `
<bq-tab-group value="1">
<bq-tab tab-id="1">Tab 1</bq-tab>
<bq-tab tab-id="2">Tab 2</bq-tab>
</bq-tab-group>
`);
`,
});

const element = await page.find('bq-tab-group');

expect(element.shadowRoot).not.toBeNull();
});

it('should change size of all tabs', async () => {
const page = await newE2EPage();
await page.setContent(`
const page = await newE2EPage({
html: `
<bq-tab-group value="1" size="medium">
<bq-tab tab-id="1">Tab 1</bq-tab>
<bq-tab tab-id="2">Tab 2</bq-tab>
</bq-tab-group>
`);
`,
});

const element = await page.find('bq-tab');

expect(await element.getProperty('size')).toBe('medium');
});

it('should emit bqChange on tab click', async () => {
const page = await newE2EPage();
await page.setContent(`
const page = await newE2EPage({
html: `
<bq-tab-group value="1">
<bq-tab tab-id="1">Tab 1</bq-tab>
<bq-tab tab-id="2">Tab 2</bq-tab>
</bq-tab-group>
`);
`,
});

const bqFocus = await page.spyOnEvent('bqFocus');
const bqChange = await page.spyOnEvent('bqChange');
Expand All @@ -65,15 +69,16 @@ describe('bq-tab-group', () => {
});

it('should emit bqChange on keyboard navigation', async () => {
const page = await newE2EPage();
await page.setContent(`
const page = await newE2EPage({
html: `
<bq-tab-group value="1">
<bq-tab tab-id="1">Tab 1</bq-tab>
<bq-tab tab-id="2">Tab 2</bq-tab>
<bq-tab tab-id="3">Tab 3</bq-tab>
<bq-tab tab-id="4">Tab 4</bq-tab>
</bq-tab-group>
`);
`,
});

const bqFocus = await page.spyOnEvent('bqFocus');
const bqChange = await page.spyOnEvent('bqChange');
Expand All @@ -89,4 +94,26 @@ describe('bq-tab-group', () => {
expect(bqChange).toHaveReceivedEventTimes(3);
expect(bqBlur).toHaveReceivedEventTimes(4);
});

it('should change active tab if value is change externally', async () => {
const page = await newE2EPage({
html: `
<bq-tab-group value="1">
<bq-tab tab-id="1">Tab 1</bq-tab>
<bq-tab tab-id="2">Tab 2</bq-tab>
<bq-tab tab-id="3">Tab 3</bq-tab>
<bq-tab tab-id="4">Tab 4</bq-tab>
</bq-tab-group>
`,
});

const element = await page.find('bq-tab-group');
element.setAttribute('value', '2');

await page.waitForChanges();

const activeElement = await page.find('bq-tab[active]');

expect(activeElement).toEqualText('Tab 2');
});
});
1 change: 1 addition & 0 deletions packages/bee-q/src/components/tab-group/bq-tab-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class BqTabGroup {
}

@Watch('size')
@Watch('value')
checkPropValues() {
validatePropValue(TAB_SIZE, 'medium', this.el, 'size');

Expand Down