Skip to content

Commit

Permalink
test(atomic): add tests for atomic-tab-manager (#4216)
Browse files Browse the repository at this point in the history
This PR adds tests for the atomic-tab-manager component. It includes
tests for facet visibility based on the active tab. Tests for visibility
of other components will be added in their respective PRs.

https://coveord.atlassian.net/browse/CDX-1579

---------

Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Alex Prudhomme <[email protected]>
  • Loading branch information
fpbrault and alexprudhomme authored Aug 6, 2024
1 parent afcbe20 commit 87ef80c
Show file tree
Hide file tree
Showing 13 changed files with 504 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ AtomicSmartSnippetFeedbackModal,
AtomicSmartSnippetSuggestions,
AtomicSortDropdown,
AtomicSortExpression,
AtomicTabManager,
AtomicTableElement,
AtomicText,
AtomicTimeframe,
Expand Down Expand Up @@ -213,6 +214,7 @@ AtomicSmartSnippetFeedbackModal,
AtomicSmartSnippetSuggestions,
AtomicSortDropdown,
AtomicSortExpression,
AtomicTabManager,
AtomicTableElement,
AtomicText,
AtomicTimeframe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,28 @@ export class AtomicSortExpression {
export declare interface AtomicSortExpression extends Components.AtomicSortExpression {}


@ProxyCmp({
inputs: ['clearFiltersOnTabChange']
})
@Component({
selector: 'atomic-tab-manager',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['clearFiltersOnTabChange'],
})
export class AtomicTabManager {
protected el: HTMLElement;
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
}
}


export declare interface AtomicTabManager extends Components.AtomicTabManager {}


@ProxyCmp({
inputs: ['label']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const AtomicSmartSnippetFeedbackModal = /*@__PURE__*/createReactComponent
export const AtomicSmartSnippetSuggestions = /*@__PURE__*/createReactComponent<JSX.AtomicSmartSnippetSuggestions, HTMLAtomicSmartSnippetSuggestionsElement>('atomic-smart-snippet-suggestions');
export const AtomicSortDropdown = /*@__PURE__*/createReactComponent<JSX.AtomicSortDropdown, HTMLAtomicSortDropdownElement>('atomic-sort-dropdown');
export const AtomicSortExpression = /*@__PURE__*/createReactComponent<JSX.AtomicSortExpression, HTMLAtomicSortExpressionElement>('atomic-sort-expression');
export const AtomicTabManager = /*@__PURE__*/createReactComponent<JSX.AtomicTabManager, HTMLAtomicTabManagerElement>('atomic-tab-manager');
export const AtomicTableElement = /*@__PURE__*/createReactComponent<JSX.AtomicTableElement, HTMLAtomicTableElementElement>('atomic-table-element');
export const AtomicText = /*@__PURE__*/createReactComponent<JSX.AtomicText, HTMLAtomicTextElement>('atomic-text');
export const AtomicTimeframe = /*@__PURE__*/createReactComponent<JSX.AtomicTimeframe, HTMLAtomicTimeframeElement>('atomic-timeframe');
Expand Down
12 changes: 12 additions & 0 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,9 @@ export namespace Components {
*/
"name": string;
}
/**
* @alpha
*/
interface AtomicTabManager {
/**
* Whether to clear the filters when the active tab changes.
Expand Down Expand Up @@ -5482,6 +5485,9 @@ declare global {
prototype: HTMLAtomicTabElement;
new (): HTMLAtomicTabElement;
};
/**
* @alpha
*/
interface HTMLAtomicTabManagerElement extends Components.AtomicTabManager, HTMLStencilElement {
}
var HTMLAtomicTabManagerElement: {
Expand Down Expand Up @@ -8867,6 +8873,9 @@ declare namespace LocalJSX {
*/
"name": string;
}
/**
* @alpha
*/
interface AtomicTabManager {
/**
* Whether to clear the filters when the active tab changes.
Expand Down Expand Up @@ -9901,6 +9910,9 @@ declare module "@stencil/core" {
*/
"atomic-sort-expression": LocalJSX.AtomicSortExpression & JSXBase.HTMLAttributes<HTMLAtomicSortExpressionElement>;
"atomic-tab": LocalJSX.AtomicTab & JSXBase.HTMLAttributes<HTMLAtomicTabElement>;
/**
* @alpha
*/
"atomic-tab-manager": LocalJSX.AtomicTabManager & JSXBase.HTMLAttributes<HTMLAtomicTabManagerElement>;
/**
* The `atomic-table-element` element defines a table column in a result list.
Expand Down
11 changes: 8 additions & 3 deletions packages/atomic/src/components/common/tab-manager/tab-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ export const TabButton: FunctionalComponent<TabButtonProps> = (props) => {
: '';
const activeTabTextClass = props.isActive ? '' : 'text-neutral-dark';
return (
<div part="button-container" class={activeTabClass}>
<li
aria-current={props.isActive ? 'true' : 'false'}
aria-label={'tab for ' + props.label}
part="button-container"
class={activeTabClass}
>
<Button
style="text-transparent"
class={`w-full px-6 pb-1 text-xl ${activeTabTextClass}`}
text={props.label}
part="button"
part="tab-button"
onClick={props.handleClick}
></Button>
</div>
</li>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export const TabDropdown: FunctionalComponent<TabDropdownProps> = (
children
) => {
return (
<div class="dropdown-area hidden border-b pb-1">
<div
class="tab-dropdown-area hidden border-b pb-1"
aria-label="tab-dropdown-area"
>
<select
aria-label="tab-dropdown"
class="btn-text-primary cursor-pointer py-2 text-xl font-bold"
onChange={(e) =>
props.onTabChange((e.target as HTMLSelectElement).value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import {parameters} from '@coveo/atomic/storybookUtils/common-meta-parameters';
import {renderComponent} from '@coveo/atomic/storybookUtils/render-component';
import {wrapInSearchInterface} from '@coveo/atomic/storybookUtils/search-interface-wrapper';
import type {Meta, StoryObj as Story} from '@storybook/web-components';
import {html} from 'lit/static-html.js';

const {decorator, play} = wrapInSearchInterface();

const meta: Meta = {
component: 'atomic-tab-manager',
title: 'Atomic/Tabs',
id: 'atomic-tab-manager',

render: renderComponent,
decorators: [decorator],
parameters,
play,
args: {
'slots-default': `
<atomic-tab name="all" label="All" tab></atomic-tab>
<atomic-tab name="article" label="Articles"></atomic-tab>
<atomic-tab name="documentation" label="Documentation"></atomic-tab>
`,
},
};

export default meta;

export const Default: Story = {
name: 'atomic-tab-manager',
decorators: [
(story) => html`
${story()}
<div style="display: flex; justify-content: flex-start;">
<atomic-facet field="objecttype" label="Object type"></atomic-facet>
<atomic-facet
aria-label="included-facet"
tabs-included='["article"]'
field="filetype"
label="File type"
></atomic-facet>
<atomic-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
field="source"
label="Source"
></atomic-facet>
</div>
<div style="display: flex; justify-content: flex-start;">
<atomic-category-facet
aria-label="included-facet"
tabs-included='["article"]'
field="geographicalhierarchy"
label="World Atlas"
with-search
></atomic-category-facet>
<atomic-category-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
field="geographicalhierarchy"
label="World Atlas"
></atomic-category-facet>
<atomic-color-facet
aria-label="included-facet"
tabs-included='["article"]'
field="filetype"
label="Files"
number-of-values="6"
sort-criteria="occurrences"
></atomic-color-facet>
<atomic-color-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
field="filetype"
label="Files"
number-of-values="6"
sort-criteria="occurrences"
></atomic-color-facet>
</div>
<div style="display: flex; justify-content: flex-start;">
<atomic-rating-facet
aria-label="included-facet"
tabs-included='["article"]'
field="snrating"
label="Rating"
number-of-intervals="5"
></atomic-rating-facet>
<atomic-rating-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
field="snrating"
label="Rating"
number-of-intervals="5"
></atomic-rating-facet>
<atomic-rating-range-facet
aria-label="included-facet"
tabs-included='["article"]'
facet-id="snrating_range"
field="snrating"
label="Rating Range (auto)"
number-of-intervals="5"
></atomic-rating-range-facet>
<atomic-rating-range-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
facet-id="snrating_range_2"
field="snrating"
label="Rating Range (auto)"
number-of-intervals="5"
></atomic-rating-range-facet>
</div>
<div style="display: flex; justify-content: flex-start; padding:50px;">
<atomic-segmented-facet-scrollable>
<atomic-segmented-facet
aria-label="included-facet"
tabs-included='["article"]'
field="inat_kingdom"
label="Kingdom"
></atomic-segmented-facet>
</atomic-segmented-facet-scrollable>
<atomic-segmented-facet-scrollable>
<atomic-segmented-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
field="inat_kingdom"
label="Kingdom"
></atomic-segmented-facet>
</atomic-segmented-facet-scrollable>
</div>
<div style="display: flex; justify-content: flex-start;">
<atomic-timeframe-facet
aria-label="included-facet"
tabs-included='["article"]'
label="Timeframe"
with-date-picker
>
<atomic-timeframe unit="hour"></atomic-timeframe>
<atomic-timeframe unit="day"></atomic-timeframe>
<atomic-timeframe unit="week"></atomic-timeframe>
<atomic-timeframe unit="month"></atomic-timeframe>
<atomic-timeframe unit="quarter"></atomic-timeframe>
<atomic-timeframe unit="year"></atomic-timeframe>
<atomic-timeframe
unit="year"
amount="10"
period="next"
></atomic-timeframe
></atomic-timeframe-facet>
<atomic-timeframe-facet
aria-label="excluded-facet"
tabs-excluded='["article"]'
label="Timeframe"
with-date-picker
>
<atomic-timeframe unit="hour"></atomic-timeframe>
<atomic-timeframe unit="day"></atomic-timeframe>
<atomic-timeframe unit="week"></atomic-timeframe>
<atomic-timeframe unit="month"></atomic-timeframe>
<atomic-timeframe unit="quarter"></atomic-timeframe>
<atomic-timeframe unit="year"></atomic-timeframe>
<atomic-timeframe
unit="year"
amount="10"
period="next"
></atomic-timeframe
></atomic-timeframe-facet>
</div>
`,
],
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@import '../../../../global/global.pcss';

@media (max-width: 768px) {
.dropdown-area {
.tab-dropdown-area {
display: block;
}

.tabs-area {
.tab-area {
display: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import {TabDropdownOption} from '../../../common/tab-manager/tab-dropdown-option
import {Bindings} from '../../atomic-search-interface/atomic-search-interface';

/**
* @internal
* @alpha
*
* @part button-container - The container for the tab button.
* @part button - The tab button.
* @slot default
*/
@Component({
tag: 'atomic-tab-manager',
Expand Down Expand Up @@ -77,7 +78,11 @@ export class AtomicTabManager {
public render() {
return (
<div class="mb-2 overflow-x-auto">
<div class="tabs-area mb-2 flex w-full flex-row border-b">
<ul
role="list"
aria-label="tab-area"
class="tab-area mb-2 flex w-full flex-row border-b"
>
{this.tabs.map((tab) => (
<TabButton
isActive={tab.tabController.state.isActive}
Expand All @@ -89,7 +94,7 @@ export class AtomicTabManager {
}}
></TabButton>
))}
</div>
</ul>
<TabDropdown
tabs={this.tabs}
activeTab={this.tabManagerState.activeTab}
Expand Down
Loading

0 comments on commit 87ef80c

Please sign in to comment.