-
Notifications
You must be signed in to change notification settings - Fork 49
[Project Solar / Phase 1 / Engineering Follow-ups] Add tests for HDS theming service and components #3428
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive test coverage for the HDS theming system, including unit tests for the theming service and integration tests for the theme switcher and theme context components. These tests ensure proper functionality of theme selection, storage, and application across the design system.
Key changes:
- Added unit tests for the
hds-themingservice covering initialization, theme setting, localStorage persistence, and callbacks - Added integration tests for the
HdsThemeSwitchercomponent to verify rendering, theme selection, and user interactions - Added integration tests for the
HdsThemeContextcomponent to verify CSS class application and content yielding
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| showcase/tests/unit/services/hds-theming-test.js | Comprehensive unit tests for the theming service covering initialization, theme management, localStorage operations, error handling, and callbacks |
| showcase/tests/integration/components/hds/theme-switcher/index-test.js | Integration tests for the theme switcher component covering rendering, size options, theme display, dropdown interactions, and callbacks |
| showcase/tests/integration/components/hds/theme-context/index-test.js | Integration tests for the theme context component covering CSS class application for themes/modes and content yielding |
Comments suppressed due to low confidence (1)
showcase/tests/unit/services/hds-theming-test.js:1
- Corrected spelling of 'oen' to 'open' in the comment.
/**
showcase/tests/integration/components/hds/theme-switcher/index-test.js
Outdated
Show resolved
Hide resolved
…rompt)
Initial prompt (Gemini 2.5 / VSCode)
----
**Prompt:**
Hello! Your task is to add unit tests for the `hds-theming` service in the Helios Design System.
**Goal:**
Create a comprehensive unit test suite for the `hds-theming` service located at `packages/components/src/services/hds-theming.ts`.
**Context & Requirements:**
1. **File Location:** Create the new (single) test file at `showcase/tests/unit/services/hds-theming-test.js`.
2. **Code Conventions:**
* Use the existing unit tests in `showcase/tests/unit/services/` as a reference for our testing conventions and style.
* The files `showcase/tests/unit/services/hds-intl-test.js` and `showcase/tests/unit/services/hds-time-test.js` are a good example to follow.
* You can also reference some of the integration tests in `showcase/tests/integration/components/hds/`, as a reference for coding conventions, test structure, and best practices.
* Other code conventions:
* do not organize the tests in sub-`module()`s, keep everything flat under the main module
3. **Test Coverage:** Ensure your tests cover the following scenarios for the `HdsThemingService`:
* **Default State:** The service initializes with the correct default values.
* **`initializeTheme()`:**
* Test its behavior when `localStorage` is empty.
* Test its behavior with valid data in `localStorage`.
* Test its behavior with malformed JSON data in `localStorage`.
* **`setTheme()`:**
* Test setting each theme value (`Default`, `System`, `Light`, `Dark`, and `undefined`).
* Verify that the correct CSS classes (`hds-theme-*`, `hds-mode-*`) are applied to the `<html>` element.
* Verify that `localStorage` is correctly updated with the theme and options.
* Test setting custom light and dark theme options.
* Ensure the `onSetTheme` (local) and `globalOnSetTheme` (global) callbacks are triggered with the correct arguments.
* **Getters:** Verify that `currentTheme`, `currentMode`, `currentLightTheme`, and `currentDarkTheme` return the correct values.
**Debugging**
1. Condider the option of using my local IDE/environment to run the test, so you have access to the console and see the tests failures, and you can iteratively adapt your code until all tests are passing.
2. If after a certain number of iterations (max 10) you still see failing tests, ask me if you have to continue iterating or not. If the answer is not, stop generating code and offer me the option to save what you already have.
Please proceed with creating the test file and implementing the tests as described. Let me know if you have any questions.
----
… with localized AI prompts)
Initial prompt (Gemini 2.5 / VSCode) - Result: many tests are not passing
----
**Prompt:**
Hello! Your task is to add integration tests for the `HdsThemeSwitcher` component in the Helios Design System.
**Goal:**
Add comprehensive integration tests for the `HdsThemeSwitcher` component located at `packages/components/src/components/hds/theme-switcher`.
**Context & Requirements:**
1. **Source code:** The component's source code is in the folder `packages/components/src/components/hds/theme-switcher` which contains
* an Handlebars template file `index.hbs`
* a TypeScrip backing class file `index.ts`
2. **Analyze Component:** Examine the `HdsThemeSwitcher` component's arguments (`Args`), yielded blocks, and actions to determine what needs to be tested.
3. **File Location:** Create the new (single) test file at `showcase/tests/integration/components/hds/theme-switcher/index-test.js`.
4. **Code Conventions:**
* Integration tests for HDS components are located in `showcase/tests/integration/components/hds/`.
* Use existing integration tests, such as `showcase/tests/integration/components/hds/button/index-test.js` (use another 4 or 5 files at random), as a reference for coding conventions, test structure, and best practices.
* Follow the testing guidelines outlined in the project's `copilot-instructions.md` file.
5. **Test Coverage:** Ensure your tests cover the following scenarios for the `HdsThemeSwitcher`:
* Test that the component renders with the base `hds-theme-switcher` CSS class.
* Test that the component correctly displays the initial theme.
* Test the interaction of clicking the theme switcher button to open the theme menu.
* Test that clicking a theme in the menu calls the `@onSelectTheme` action with the correct theme name as the payload.
* Test any other arguments or states of the component.
**Debugging**
1. Condider the option of using my local IDE/environment to run the test, so you have access to the console and see the tests failures, and you can iteratively adapt your code until all tests are passing.
2. If after a certain number of iterations (max 10) you still see failing tests, ask me if you have to continue iterating or not. If the answer is not, stop generating code and offer me the option to save what you already have.
Please proceed with creating the test file and implementing the tests as described. Let me know if you have any questions.
----
Same prompt (Claude Sonnet 4.5 / VSCode) - Result: many tests are still not passing
Initial prompt (Gemini 2.5 / VSCode) - Result: some tests are not passing
- - - - -
**Prompt:**
Hello! Your task is to add integration tests for the `HdsThemeContext` component in the Helios Design System.
**Goal:**
Add comprehensive integration tests for the `HdsThemeContext` component located at `packages/components/src/components/hds/theme-context`.
**Context & Requirements:**
1. **Source code:** The component's source code is in the folder `packages/components/src/components/hds/theme-context` which contains
* an Handlebars template file `index.hbs`
* a TypeScrip backing class file `index.ts`
* a TypeScrip types definition file `types.ts`
2. **Analyze Component:** Examine the `HdsThemeContext` component's arguments (`Args`), yielded blocks, and actions to determine what needs to be tested.
3. **File Location:** Create the new (single) test file at `showcase/tests/integration/components/hds/theme-context/index-test.js`.
4. **Code Conventions:**
* Integration tests for HDS components are located in `showcase/tests/integration/components/hds/`.
* Use existing integration tests, such as `showcase/tests/integration/components/hds/button/index-test.js` (use another 4 or 5 files at random), as a reference for coding conventions, test structure, and best practices.
* Follow the testing guidelines outlined in the project's `copilot-instructions.md` file.
5. **Test Coverage:** Ensure your tests cover the following scenarios for the `HdsThemeContext`:
* Test that the component renders with the base `hds-theme-context` CSS class.
* Test that the component correctly applies the correct context
* Test that it correctly applies a different class depending if the context is a theme or a mode
* Test that it correctly yields the content
* Test that it correctly spreads the `...attributes`
* Test any other arguments or states of the component.
Please proceed with creating the test file and implementing the tests as described. Let me know if you have any questions.
- - - - - -
882d34c to
a8c8db8
Compare
a8c8db8 to
71b25cf
Compare
otherwise visual tests for `foundations/theming` page with different themes would not work
showcase/tests/integration/components/hds/theme-switcher/index-test.js
Outdated
Show resolved
Hide resolved
| <p id="test-content">This is yielded content</p> | ||
| </Hds::ThemeContext> | ||
| `); | ||
| assert.dom('#test-content').exists(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one seems a bit redundant perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We test to test the yielding of content. This one in particular makes sense to me, since it's one of the two main functions of this component (apply a class and yield the content)
|
|
||
| // change theme | ||
| const lightOptionButton = this.element.querySelector( | ||
| '.hds-dropdown-list-item:nth-of-type(3) button', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there another way the button could be selected that doesn't rely solely on the DOM structure like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I could think of (we could use the inner text, but the logic would become even more complex)
KristinLBradley
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just added a few very minor comments/suggestions.
Co-authored-by: Dylan Hyun <dylan.hyun@hashicorp.com> Co-authored-by: Kristin Bradley <kristin.bradley@hashicorp.com>
0c86eb6
into
project-solar/phase-1-main-feature-branch
…theming service and components (#3428) Co-authored-by: Dylan Hyun <dylan.hyun@hashicorp.com> Co-authored-by: Kristin Bradley <kristin.bradley@hashicorp.com>
…theming service and components (#3428) Co-authored-by: Dylan Hyun <dylan.hyun@hashicorp.com> Co-authored-by: Kristin Bradley <kristin.bradley@hashicorp.com>
📌 Summary
This PR adds:
hds-themingserviceHdsThemingSwitchercomponent (note: this is a temporary component, but better to cover it anyway)HdsThemingContext"headless" componentfoundations/themingpagefoundations/themingpageNote
Currently in the
mainbranch all the tests have been converted togtsformat. Once the feature branchproject-solar/phase-1-main-feature-branchhave been rebased tomain, we will update these tests too (unless @shleewhite can think of an alternative approach)🔗 External links
Jira ticket: https://hashicorp.atlassian.net/browse/HDS-5654
👀 Component checklist
💬 Please consider using conventional comments when reviewing this PR.
📋 PCI review checklist
Examples of changes to controls include access controls, encryption, logging, etc.
Examples include changes to operating systems, ports, protocols, services, cryptography-related components, PII processing code, etc.