diff --git a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-actions.ts b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-actions.ts index 76574636502..c78b1ae92dc 100644 --- a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-actions.ts +++ b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-actions.ts @@ -5,11 +5,17 @@ import { const resultQuickviewActions = (selector: ResultQuickviewSelector) => { return { - clickPreview: (variant?: string) => + clickPreview: () => selector - .buttonPreview(variant) + .buttonPreview() .click() .logAction('When clicking preview button'), + + hoverOverPreview: () => + selector + .buttonPreviewContainer() + .trigger('mouseenter') + .logAction('When hovering over the preview button'), }; }; diff --git a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-expectations.ts b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-expectations.ts index 064b032114b..b94ff442599 100644 --- a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-expectations.ts +++ b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-expectations.ts @@ -7,14 +7,29 @@ import { ResultQuickviewSelectors, } from './result-quickview-selectors'; +export type PreviewVariantType = 'brand' | 'outline-brand' | 'result-action'; + function resultQuickviewExpectations(selector: ResultQuickviewSelector) { return { - displayButtonPreview: (display: boolean, variant?: string) => { + displayButtonPreview: (display: boolean) => { selector - .buttonPreview(variant) + .buttonPreview() .should(display ? 'exist' : 'not.exist') .logDetail(`${should(display)} display the button preview`); }, + displayCorrectPreviewButtonVariant: (variant: PreviewVariantType) => { + const expectedCssVariantClasses = { + brand: 'slds-button_brand', + 'outline-brand': 'slds-button_outline-brand', + 'result-action': 'slds-button_icon-border-filled', + }; + selector + .buttonPreview() + .should('have.class', expectedCssVariantClasses[`${variant}`]) + .log( + `the preview button should be displayed in the ${variant} variant` + ); + }, displayButtonPreviewIcon: (display: boolean) => { selector .buttonPreviewIcon() @@ -29,9 +44,9 @@ function resultQuickviewExpectations(selector: ResultQuickviewSelector) { .should('contain', iconName) .logDetail(`the icon in button preview should contain "${iconName}"`); }, - buttonPreviewIsDisabled: (disabled: boolean, variant?: string) => { + buttonPreviewIsDisabled: (disabled: boolean) => { selector - .buttonPreview(variant) + .buttonPreview() .invoke('attr', 'disabled') .should(disabled ? 'exist' : 'not.exist') .logDetail(`The button preview ${should(disabled)} be disabled`); diff --git a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-selectors.ts b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-selectors.ts index 8865c1bdfc7..5bb61e5ab46 100644 --- a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-selectors.ts +++ b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview-selectors.ts @@ -3,7 +3,8 @@ import {ComponentSelector, CypressSelector} from '../../common-selectors'; export const resultQuickviewComponent = 'c-quantic-result-quickview'; export interface ResultQuickviewSelector extends ComponentSelector { - buttonPreview: (variant?: string) => CypressSelector; + buttonPreview: () => CypressSelector; + buttonPreviewContainer: () => CypressSelector; buttonPreviewIcon: () => CypressSelector; sectionPreview: () => CypressSelector; closeButton: () => CypressSelector; @@ -19,10 +20,12 @@ export interface ResultQuickviewSelector extends ComponentSelector { export const ResultQuickviewSelectors: ResultQuickviewSelector = { get: () => cy.get(resultQuickviewComponent), - buttonPreview: (variant?: string) => - variant - ? ResultQuickviewSelectors.get().find('.slds-button_' + variant) - : ResultQuickviewSelectors.get().find('.quickview__button-base'), + buttonPreviewContainer: () => + ResultQuickviewSelectors.get().find( + '[data-cy="quick-view-button__container"]' + ), + buttonPreview: () => + ResultQuickviewSelectors.get().find('[data-cy="quick-view-button"]'), buttonPreviewIcon: () => ResultQuickviewSelectors.buttonPreview().find('lightning-icon'), sectionPreview: () => ResultQuickviewSelectors.get().find('section'), @@ -40,5 +43,5 @@ export const ResultQuickviewSelectors: ResultQuickviewSelector = { ResultQuickviewSelectors.get().find( '.quickview__content-container .iframe-wrapper .quickview__spinner-container' ), - tooltip: () => ResultQuickviewSelectors.get().find('.slds-popover'), + tooltip: () => ResultQuickviewSelectors.get().find('[data-cy="tooltip"]'), }; diff --git a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview.cypress.ts b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview.cypress.ts index 4bfc43aef8c..1c3d8695a41 100644 --- a/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview.cypress.ts +++ b/packages/quantic/cypress/e2e/default-2/result-quickview/result-quickview.cypress.ts @@ -5,14 +5,19 @@ import { } from '../../../page-objects/search'; import {scope} from '../../../reporters/detailed-collector'; import {ResultQuickviewActions as Actions} from './result-quickview-actions'; -import {ResultQuickviewExpectations as Expect} from './result-quickview-expectations'; +import { + ResultQuickviewExpectations as Expect, + PreviewVariantType, +} from './result-quickview-expectations'; + +const variants = ['brand', 'outline-brand', 'result-action']; interface ResultQuickviewOptions { result: string; maximumPreviewSize: number; previewButtonIcon: string; previewButtonLabel: string; - previewButtonVariant: string; + previewButtonVariant: PreviewVariantType; tooltip: string; } @@ -101,17 +106,6 @@ describe('quantic-result-quickview', () => { Expect.displaySectionPreview(true); }); - scope('custom #previewButtonVariant', () => { - visitResultQuickview({ - previewButtonVariant: 'outline-brand', - }); - mockResultHtmlContent('div'); - - Expect.displayButtonPreview(true, 'outline-brand'); - Actions.clickPreview('outline-brand'); - Expect.displaySectionPreview(true); - }); - scope('custom #tooltip', () => { const customTooltip = 'Quick view'; visitResultQuickview({ @@ -120,21 +114,29 @@ describe('quantic-result-quickview', () => { mockResultHtmlContent('div'); Expect.displayButtonPreview(true); + Actions.hoverOverPreview(); Expect.displayTooltip(customTooltip); }); }); }); - describe('with #previewButtonVariant set to result-action', () => { - it('should display the quickview button as a result action', () => { - visitResultQuickview({ - previewButtonVariant: 'result-action', - }); - mockResultHtmlContent('div'); + describe('the preview button with custom variants', () => { + variants.forEach((variantValue) => { + it(`should display the quick view button in the ${variantValue} variant`, () => { + visitResultQuickview({ + previewButtonVariant: variantValue, + }); + mockResultHtmlContent('div'); - scope('when loading the page', () => { - Expect.events.receivedEvent(true, resultActionRegister); - Expect.displayButtonPreview(true, 'icon-border-filled'); + scope('when loading the page', () => { + if (variantValue === 'result-action') { + Expect.events.receivedEvent(true, resultActionRegister); + } + Expect.displayButtonPreview(true); + Expect.displayCorrectPreviewButtonVariant( + variantValue + ); + }); }); }); }); diff --git a/packages/quantic/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js b/packages/quantic/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js index 60b6c8ae6e2..5e5e27ac779 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js +++ b/packages/quantic/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js @@ -6,6 +6,11 @@ const functionsMocks = { listener: jest.fn(() => {}), }; +const selectors = { + tooltip: 'c-quantic-tooltip', + tooltipContent: 'c-quantic-tooltip > div[slot="content"]', +}; + const exampleLabel = 'example label'; const exampleSelectedLabel = 'example label on'; const exampleIconName = 'example icon name'; @@ -91,11 +96,15 @@ describe('c-quantic-result-action', () => { const resultActionButton = element.shadowRoot.querySelector( 'lightning-button-icon-stateful' ); - const tooltip = element.shadowRoot.querySelector('.slds-popover_tooltip'); + const tooltip = element.shadowRoot.querySelector(selectors.tooltip); + const tooltipContent = element.shadowRoot.querySelector( + selectors.tooltipContent + ); expect(resultActionButton).not.toBeNull(); expect(tooltip).not.toBeNull(); - expect(tooltip.textContent).toBe(exampleLabel); + expect(tooltipContent).not.toBeNull(); + expect(tooltipContent.textContent).toBe(exampleLabel); expect(resultActionButton.iconName).toBe(exampleIconName); }); @@ -190,10 +199,14 @@ describe('c-quantic-result-action', () => { const element = createTestComponent({...defaultOptions, selected: true}); await flushPromises(); - const tooltip = element.shadowRoot.querySelector('.slds-popover_tooltip'); + const tooltip = element.shadowRoot.querySelector(selectors.tooltip); + const tooltipContent = element.shadowRoot.querySelector( + selectors.tooltipContent + ); expect(tooltip).not.toBeNull(); - expect(tooltip.textContent).toBe(exampleSelectedLabel); + expect(tooltipContent).not.toBeNull(); + expect(tooltipContent.textContent).toBe(exampleSelectedLabel); }); it('should display the correct icon', async () => { diff --git a/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.html b/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.html index b91ea51835e..ba92d09931a 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.html +++ b/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.html @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.js b/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.js index 1d7e853f865..88d15c999b0 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.js +++ b/packages/quantic/force-app/main/default/lwc/quanticResultAction/quanticResultAction.js @@ -130,6 +130,21 @@ export default class QuanticResultAction extends LightningElement { this.dispatchEvent(resultActionEvent); } + showTooltip() { + this.tooltipComponent?.showTooltip(); + } + + hideTooltip() { + this.tooltipComponent?.hideTooltip(); + } + + /** + * @returns {Object} + */ + get tooltipComponent() { + return this.template.querySelector('c-quantic-tooltip'); + } + /** * Returns the label to be displayed in the tooltip. */ diff --git a/packages/quantic/force-app/main/default/lwc/quanticResultActionStyles/quanticResultActionStyles.css b/packages/quantic/force-app/main/default/lwc/quanticResultActionStyles/quanticResultActionStyles.css index 287e14264e6..11dd77ee025 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticResultActionStyles/quanticResultActionStyles.css +++ b/packages/quantic/force-app/main/default/lwc/quanticResultActionStyles/quanticResultActionStyles.css @@ -1,30 +1,9 @@ -.slds-nubbin_bottom-left:before, -.slds-nubbin_bottom-left:after { - left: 50%; -} - -.slds-popover_tooltip { - width: max-content; -} - -.result-action_tooltip { - position: absolute; - top: -3rem; - left: 50%; - transform: translate(-50%, 0); -} - .result-action_white-container { background-color: white; display: inline-block; border-radius: var(--lwc-borderRadiusMedium, 0.25rem); } -.result-action_container:hover > .result-action_tooltip { - visibility: visible; - opacity: 1; -} - .result-action_button { --lwc-borderWidthThin: 0.5px; } diff --git a/packages/quantic/force-app/main/default/lwc/quanticResultQuickview/quanticResultQuickview.html b/packages/quantic/force-app/main/default/lwc/quanticResultQuickview/quanticResultQuickview.html index d1c1e72e25e..9ae92190e19 100644 --- a/packages/quantic/force-app/main/default/lwc/quanticResultQuickview/quanticResultQuickview.html +++ b/packages/quantic/force-app/main/default/lwc/quanticResultQuickview/quanticResultQuickview.html @@ -1,6 +1,6 @@