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

Add visual tests for KDropdownMenu (header, icons, multiple, single) and rename KDropdownMenu.vue to index.vue #933

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

GautamBytes
Copy link

@GautamBytes GautamBytes commented Feb 7, 2025

Description

This PR adds visual tests for the KDropdownMenu component, covering the following scenarios:

  • Rendering with a single item
  • Rendering with multiple items
  • Rendering items with icons
  • Rendering with a header slot

Additionally, the KDropdownMenu component file has been renamed from KDropdownMenu.vue to KDropdownMenu/index.vue to better organize the component structure.

Issue addressed

Closes #926

Before/after screenshots

NA

Changelog

  • Description: Added visual tests for KDropdownMenu (covering single, multiple, icons, and header slot scenarios) and renamed KDropdownMenu.vue to KDropdownMenu/index.vue.

  • Products impact: None

  • Addresses: [Visual testing]: Add visual tests for KDropdownMenu #926

  • Components: KDropdownMenu

  • Breaking: No

  • Impacts a11y: No

  • Guidance: Visual tests are implemented in separate test files following the approach used for KButton visual tests. This ensures that different configurations of KDropdownMenu render correctly and consistently.

Steps to test

  1. Pull down the branch and build the project.
  2. Run the visual tests using -- yarn test:visual
  3. Verify that the visual tests for KDropdownMenu pass for:
  • Single item
  • Multiple items
  • Items with icons
  • With header slot
  1. Check the Percy build to confirm that snapshots are captured correctly.

(optional) Implementation notes

At a high level, how did you implement this?

  • Added four separate visual test files for KDropdownMenu in lib/KDropdownMenu/tests/ to isolate each scenario.
    The tests render KDropdownMenu via a KButton’s menu slot, simulating a user click to open the dropdown before taking snapshots.
    The visual test utility was updated to accept an optional selector (knownSelector) to wait for an element (e.g., [data-test="dropdown-menu"]) indicating that the dropdown is rendered.
    Renamed KDropdownMenu.vue to KDropdownMenu/index.vue for improved component organization.

Does this introduce any tech-debt items?

No, these changes follow the existing testing infrastructure and component guidelines.

Testing checklist

  • [✅ ] Contributor has fully tested the PR manually
  • [✅ ] If there are any front-end changes, before/after screenshots are included
  • [✅] Critical and brittle code paths are covered by unit tests
  • [✅] The change is described in the changelog section above

Reviewer guidance

  • Verify that the visual tests run as expected and that Percy snapshots accurately reflect the UI changes.

  • Confirm that renaming the component file to index.vue does not break any existing imports.

  • Ensure that the new tests follow the pattern used in the KButton visual tests.

  • [✅] Is the code clean and well-commented?

  • [✅] Are there tests for this change?

Comments

Please let me know if there are any questions or further adjustments needed.

@GautamBytes
Copy link
Author

Hello @AlexVelezLl , I have added the visual test for kdropdownmenu , it passed all 4 cases capturing the required snapshots. You can have a look and suggest me if anything further changes are required!

Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @GautamBytes! Thanks a lot for this! I have left an initial review :). If there are any questions, please let us know 👐.

@@ -0,0 +1,30 @@
import { renderComponent, takeSnapshot, click } from '../../../jest.conf/visual.testUtils';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep the test suite just as the example I linked in the issue. So lets just have one KDropdownMenu.specs.js file, where we have this structure:

describe.visual('KDropdownMenu', () => {
  it(...visual test for test 1)
  it(...visual test for test 2)
  it(...visual test for test 3)
  it(...visual test for test 4)
})

// For KDropdownMenu, use a known selector from Keen's UI Menu.
// Adjust the selector as needed (e.g., it might be '.ui-menu', '.keen-ui-menu', or a data attribute).
const knownSelector =
component === 'KDropdownMenu'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As linked previously, we should be able to able to render the dropdown menu with the current implementation of our visual.testUtils, please lets try not to modify this file too much as right now is pretty stable, and if we do need to modify it, we should try to avoid hardcoding specific components in it, because this is a general file with general methods.

This is the rendered example of the linked test:

image

* Example:
* {
* default: {
* element: "div", // or any Vue component like KIcon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets revert this change, please :). JsDocs are super super important for methods like this.

const beforeRenderState = await page.evaluate(() => {
const testing_playground = document.querySelector('#testing-playground');
return testing_playground ? testing_playground.innerHTML : '';
});

// Trigger rendering via postMessage.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets revert these comments too.

);

// Check if the component has been rendered by comparing the initial state with the current state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

*
* For a full list of available options, refer to the Percy documentation:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem. This is really really super important for other people to have a reference of the availabe option, its not here just because. :) Lets revert these changes, please 👐

},
},
},
dropdownSelector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont have a fourth argument for this method 😅

@GautamBytes
Copy link
Author

Hey @AlexVelezLl , did the suggested changes , can you please check now and suggest if any improvements are needed. Thanks!
Attaching snapshots for reference)
WhatsApp Image 2025-02-09 at 22 45 20_62799c23
WhatsApp Image 2025-02-09 at 22 45 21_8de64063
WhatsApp Image 2025-02-09 at 22 45 21_4063edbb
WhatsApp Image 2025-02-09 at 22 45 22_6ced219b

@AlexVelezLl AlexVelezLl self-assigned this Feb 11, 2025
@GautamBytes
Copy link
Author

Hey @AlexVelezLl , I noticed there is a conflict in file -- lib/kdropdownmenu.vue , but i am unable to resolve the conflict and can't understand the cause , can you suggest me what to do?

@RONAK-AI647
Copy link
Contributor

Hey @AlexVelezLl , I noticed there is a conflict in file -- lib/kdropdownmenu.vue , but i am unable to resolve the conflict and can't understand the cause , can you suggest me what to do?

May be your branch is not up to date ..update it . Rest @AlexVelezLl could point out the accurate reason.

@GautamBytes
Copy link
Author

It is up-to-date , already checked that
image

@AlexVelezLl
Copy link
Member

Hey @GautamBytes! The conflict is because of an modify/rename file conflict, you can keep your current changes, and make sure that the changes introduced in https://github.com/learningequality/kolibri-design-system/pull/856/files are still available in the renamed file :).

On a side note. I opened this PR that will properly fix the remount of the components, so you wont need to override the styles with the percyCSS field. Once that PR is merged I will suggest some changes here 👐. Thanks in advance :).

@GautamBytes
Copy link
Author

Sure @AlexVelezLl , will wait till your pr is merged and meanwhile i will check if the changes are kept in renamed file!

@GautamBytes
Copy link
Author

Hey @AlexVelezLl , I have solved the conflict and also added the changes from your referenced pr to the renamed file . You can have a look and also suggest me what changes to do once your PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Visual testing]: Add visual tests for KDropdownMenu
3 participants