mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculm): add user story and test for theme switcher (#66636)
Co-authored-by: Anna <a.rcottrill521@gmail.com> Co-authored-by: sembauke <semboot699@gmail.com>
This commit is contained in:
@@ -33,6 +33,7 @@ In this lab, you will build an app that switches between different themes. When
|
||||
9. When the `#theme-dropdown` element is displayed, the `aria-expanded` attribute should be set to `"true"` for the `button` element.
|
||||
10. When the users clicks on the `#theme-switcher-button` while the `#theme-dropdown` element is displayed, the menu should be closed and the `hidden` attribute should be added and the `aria-expanded` attribute should be set to `"false"`.
|
||||
11. When a user clicks on the `#theme-switcher-button` and selects a theme, the corresponding `theme-<name>` class should be added to the `body` element and the related theme message you set in the `themes` array should display in the `aria-live="polite"` element.
|
||||
12. When a user clicks on the `#theme-switcher-button` and selects a different theme than the current one, the `body` theme class and status message should update to match the new selection.
|
||||
|
||||
# --before-all--
|
||||
|
||||
@@ -299,6 +300,29 @@ const selectedTheme = themes?.find(theme => theme.name === selectedThemeName);
|
||||
assert.equal(liveRegion?.textContent, selectedTheme?.message);
|
||||
```
|
||||
|
||||
When a user clicks on the `#theme-switcher-button` and selects two different themes, the `body` class and status message should update to match each selected theme.
|
||||
|
||||
```js
|
||||
const liveRegion = document.querySelector('[aria-live="polite"]');
|
||||
const themeDropdownBtn = document.getElementById("theme-switcher-button");
|
||||
const listItems = document.querySelectorAll("#theme-dropdown li");
|
||||
|
||||
themeDropdownBtn?.dispatchEvent(new Event("click"));
|
||||
listItems[0]?.dispatchEvent(new Event("click", { bubbles: true }));
|
||||
const firstClass = document.body.className;
|
||||
const firstMessage = liveRegion?.textContent;
|
||||
|
||||
themeDropdownBtn?.dispatchEvent(new Event("click"));
|
||||
listItems[1]?.dispatchEvent(new Event("click", { bubbles: true }));
|
||||
const secondClass = document.body.className;
|
||||
const secondMessage = liveRegion?.textContent;
|
||||
|
||||
assert.equal(firstClass, listItems[0]?.id);
|
||||
assert.equal(secondClass, listItems[1]?.id);
|
||||
assert.notEqual(firstClass, secondClass);
|
||||
assert.notEqual(firstMessage, secondMessage);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
Reference in New Issue
Block a user