Skip to content

Commit fff7269

Browse files
committed
Minor component syntax updates for Cypress testing docs
1 parent 397b07b commit fff7269

File tree

11 files changed

+92
-66
lines changed

11 files changed

+92
-66
lines changed

docs/_includes/component.njk

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<h1>{{ component.name | classNameToComponentName }}</h1>
6363

6464
<div class="component-header__tag">
65-
<code>&lt;{{ component.tagName }}&gt; | {{ component.name }}</code>
65+
<code>{{ component.tagName }}</code>
6666
</div>
6767
</header>
6868

docs/assets/styles/docs.css

+4-4
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,10 @@ td.table-name code.prop,
715715

716716
.cy-table-desc + div > table > tbody tr:first-child,
717717
.cy-table-desc + div > table > tbody tr:nth-child(5),
718-
.cy-table-desc + div > table > tbody tr:nth-child(9),
719-
.cy-table-desc + div > table > tbody tr:nth-child(13),
720-
.cy-table-desc + div > table > tbody tr:nth-child(16),
721-
.cy-table-desc + div > table > tbody tr:nth-child(19) {
718+
.cy-table-desc + div > table > tbody tr:nth-child(7),
719+
.cy-table-desc + div > table > tbody tr:nth-child(11),
720+
.cy-table-desc + div > table > tbody tr:nth-child(14),
721+
.cy-table-desc + div > table > tbody tr:nth-child(17) {
722722
border-top: 2px solid var(--sl-color-neutral-300);
723723
}
724724

docs/pages/components/checkbox-group.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ testing: |
2222
2323
**Adding `data-test-id` to a component**
2424
25-
To test `<sl-checkbox-group>`, add the `data-test-id` attribute directly to the component. To test checkbox items in the group, add `data-test-id` to each item:
25+
To test `sl-checkbox-group`, add the `data-test-id` attribute directly to the component. To test checkbox items in the group, add `data-test-id` to each item:
2626
2727
```pug:slim
2828
sl-checkbox-group[
@@ -47,7 +47,7 @@ testing: |
4747
| Option 3
4848
```
4949
50-
To test `<sl-checkbox-group>` implemented with `ts_form_for`, add `data-test-id` to `wrapper_html`. To test checkbox items in the group, add `data-test-id` to each item in the collection array:
50+
To test `sl-checkbox-group` implemented with `ts_form_for`, add `data-test-id` to `wrapper_html`. To test checkbox items in the group, add `data-test-id` to each item in the collection array:
5151
5252
```js
5353
= ts_form_for ... do |f|
@@ -61,12 +61,12 @@ testing: |
6161
],
6262
wrapper_html: {
6363
data: {
64-
"test_id": "checkbox-group-test"
64+
test_id: "checkbox-group-test"
6565
}
6666
}
6767
```
6868
69-
**Cypress commands for `<sl-checkbox-group>`**
69+
**Cypress commands for `sl-checkbox-group`**
7070
7171
To **check** any checkbox in the checkbox group:
7272
```js

docs/pages/components/checkbox.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ testing: |
1313
1414
**Adding `data-test-id` to a component**
1515
16-
To test `<sl-checkbox>`, add the `data-test-id` attribute directly to the component:
16+
To test `sl-checkbox`, add the `data-test-id` attribute directly to the component:
1717
1818
```pug:slim
1919
sl-checkbox[
@@ -22,7 +22,7 @@ testing: |
2222
| Checkbox test
2323
```
2424
25-
To test `<sl-checkbox>` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
25+
To test `sl-checkbox` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
2626
2727
```js
2828
= ts_form_for ... do |f|
@@ -31,12 +31,12 @@ testing: |
3131
input_html: {
3232
label: "Checkbox text",
3333
data: {
34-
"test_id": "checkbox-test"
34+
test_id: "checkbox-test"
3535
}
3636
}
3737
```
3838
39-
**Cypress commands for `<sl-checkbox>`**
39+
**Cypress commands for `sl-checkbox`**
4040
4141
To **check** the checkbox:
4242
```js

docs/pages/components/drawer.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,41 @@ layout: component
1818
1919
<sl-button>Open Drawer</sl-button>
2020
21+
<sl-dropdown>
22+
<div slot="trigger"><sl-button caret>Dropdown</sl-button></div>
23+
<sl-menu>
24+
<sl-menu-item class="open-link">Open drawer</sl-menu-item>
25+
<sl-menu-item>Dropdown Item 2</sl-menu-item>
26+
<sl-menu-item>Dropdown Item 3</sl-menu-item>
27+
<sl-divider></sl-divider>
28+
<sl-menu-item type="checkbox" checked>Checkbox</sl-menu-item>
29+
<sl-menu-item disabled>Disabled</sl-menu-item>
30+
<sl-divider></sl-divider>
31+
<sl-menu-item>
32+
Prefix
33+
<sl-icon slot="prefix" name="gift"></sl-icon>
34+
</sl-menu-item>
35+
<sl-menu-item>
36+
Suffix Icon
37+
<sl-icon slot="suffix" name="heart"></sl-icon>
38+
</sl-menu-item>
39+
</sl-menu>
40+
</sl-dropdown>
41+
2142
<script>
2243
const drawer = document.querySelector('.drawer-overview');
23-
const openButton = drawer.nextElementSibling;
44+
// const openButton = drawer.nextElementSibling;
45+
const openButton = document.querySelector('.open-link');
2446
const closeButton = drawer.querySelector('sl-button[variant="primary"]');
47+
const dropdown = document.querySelector('sl-dropdown');
2548
26-
openButton.addEventListener('click', () => drawer.show());
49+
openButton.addEventListener('click', (event) => {
50+
// event.stopPropagation();
51+
drawer.show();
52+
// dropdown.hide();
53+
});
2754
closeButton.addEventListener('click', () => drawer.hide());
55+
2856
</script>
2957
```
3058

docs/pages/components/input.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ testing: |
9090
9191
**Adding `data-test-id` to a component**
9292
93-
To test `<sl-input>`, add the `data-test-id` attribute directly to the component:
93+
To test `sl-input`, add the `data-test-id` attribute directly to the component:
9494
9595
```pug:slim
9696
sl-input[
@@ -99,20 +99,20 @@ testing: |
9999
]
100100
```
101101
102-
To test `<sl-input>` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
102+
To test `sl-input` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
103103
104104
```js
105105
= ts_form_for ... do |f|
106106
= f.input :input_name,
107107
input_html: {
108108
label: "Name",
109109
data: {
110-
"test_id": "input-test"
110+
test_id: "input-test"
111111
}
112112
}
113113
```
114114
115-
**Cypress commands for `<sl-input>`**
115+
**Cypress commands for `sl-input`**
116116
117117
To **type** in the input:
118118
```js

docs/pages/components/radio-group.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ testing: |
2222
2323
**Adding `data-test-id` to a component**
2424
25-
To test `<sl-radio-group>`, add the `data-test-id` attribute directly to the component. To test radio items in the group, add `data-test-id` to each item:
25+
To test `sl-radio-group`, add the `data-test-id` attribute directly to the component. To test radio items in the group, add `data-test-id` to each item:
2626
2727
```pug:slim
2828
sl-radio-group[
@@ -48,7 +48,7 @@ testing: |
4848
| Option 3
4949
```
5050
51-
To test `<sl-radio-group>` implemented with `ts_form_for`, add `data-test-id` to `wrapper_html`. To test radio items in the group, add `data-test-id` to each item in the collection array:
51+
To test `sl-radio-group` implemented with `ts_form_for`, add `data-test-id` to `wrapper_html`. To test radio items in the group, add `data-test-id` to each item in the collection array:
5252
5353
```js
5454
= ts_form_for ... do |f|
@@ -62,12 +62,12 @@ testing: |
6262
],
6363
wrapper_html: {
6464
data: {
65-
"test_id": "radio-group-test"
65+
test_id: "radio-group-test"
6666
}
6767
}
6868
```
6969
70-
**Cypress commands for `<sl-radio-group>`**
70+
**Cypress commands for `sl-radio-group`**
7171
7272
To **select** a radio item in the radio group:
7373
```js

docs/pages/components/select.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ testing: |
3333
3434
**Adding `data-test-id` to a component**
3535
36-
To test `<sl-select>`, add the `data-test-id` attribute directly to the component:
36+
To test `sl-select`, add the `data-test-id` attribute directly to the component:
3737
3838
```pug:slim
3939
sl-select[
@@ -45,7 +45,7 @@ testing: |
4545
sl-option value="option-3" Option 3
4646
```
4747
48-
To test `<sl-select>` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
48+
To test `sl-select` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
4949
5050
```js
5151
= ts_form_for ... do |f|
@@ -58,12 +58,12 @@ testing: |
5858
input_html: {
5959
label: "Select an option",
6060
data: {
61-
"test_id": "select-test"
61+
test_id: "select-test"
6262
}
6363
}
6464
```
6565
66-
**Cypress commands for `<sl-select>`**
66+
**Cypress commands for `sl-select`**
6767
6868
To **select** an option:
6969
```js

docs/pages/components/switch.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ testing: |
4848
4949
**Adding `data-test-id` to a component**
5050
51-
To test `<sl-switch>`, add the `data-test-id` attribute directly to the component:
51+
To test `sl-switch`, add the `data-test-id` attribute directly to the component:
5252
5353
```
5454
sl-switch[
@@ -57,9 +57,9 @@ testing: |
5757
| Switch test
5858
```
5959
60-
**Cypress commands for `<sl-switch>`**
60+
**Cypress commands for `sl-switch`**
6161
62-
Because `<sl-switch>` uses `<input type="checkbox">`, we can test the switch the same way we would test the [checkbox](/components/checkbox/#testing).
62+
Because `sl-switch` uses `<input type="checkbox">`, we can test the switch the same way we would test the [checkbox](/components/checkbox/#testing).
6363
6464
To toggle the switch **ON**:
6565
```

docs/pages/components/textarea.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ testing: |
1313
1414
**Adding `data-test-id` to a component**
1515
16-
To test `<sl-textarea>`, add the `data-test-id` attribute directly to the component:
16+
To test `sl-textarea`, add the `data-test-id` attribute directly to the component:
1717
1818
```pug:slim
1919
sl-textarea[
@@ -22,7 +22,7 @@ testing: |
2222
]
2323
```
2424
25-
To test `<sl-textarea>` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
25+
To test `sl-textarea` implemented with `ts_form_for`, add `data-test-id` to `input_html`:
2626
2727
```js
2828
= ts_form_for ... do |f|
@@ -31,12 +31,12 @@ testing: |
3131
input_html: {
3232
label: "Bio",
3333
data: {
34-
"test_id": "textarea-test"
34+
test_id: "textarea-test"
3535
}
3636
}
3737
```
3838
39-
**Cypress commands for `<sl-textarea>`**
39+
**Cypress commands for `sl-textarea`**
4040
4141
To **type** in the textarea:
4242
```js

docs/pages/teamshares/recipes/cypress.md

+30-32
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,28 @@ Also see below for more on testing Shoelace design system components with Cypres
3838

3939
<div class="cy-table-desc">This is a quick reference guide to common test actions for form components.</div>
4040

41-
| Component | Test action | Cypress command |
42-
| --------------------- | ---------------------------------- | ---------------------------------------------------------------------- |
43-
| **Checkbox** | <span>check</span> | [`cy.slCheckboxCheck()`](#cy_slcheckboxcheck) |
44-
| | <span>uncheck</span> | [`cy.slCheckboxUncheck()`](#cy_slcheckboxuncheck) |
45-
| | <span>is checked?</span> | [`cy.get().should("have.prop", "checked", true)`](#shouldhave_prop) |
46-
| | <span>is not checked?</span> | [`cy.get().should("have.prop", "checked", false)`](#shouldhave_prop) |
47-
| **Checkbox Group** | <span>check</span> | [`cy.slCheckboxCheck()`](#cy_slcheckboxcheck) |
48-
| | <span>uncheck</span> | [`cy.slCheckboxUncheck()`](#cy_slcheckboxuncheck) |
49-
| | <span>items checked?</span> | [`cy.slCheckboxGroupValue()`](#cy_slcheckboxgroupvalue) |
50-
| | <span>items not checked?</span> | [`cy.get().should("not.have.value", "value")`](#shouldhave_value) |
51-
| **Input** | <span>focus</span> | [`cy.slFocus()`](#cy_slfocus) |
52-
| | <span>type</span> | [`cy.slInputType()`](#cy_slinputtype) |
53-
| | <span>clear</span> | [`cy.slClear()`](#cy_slclear) |
54-
| | <span>value?</span> | [`cy.get().should("have.value", "value")`](#shouldhave_value) |
55-
| **Radio/Radio Group** | <span>select radio in group</span> | [`cy.get().click()`](#click) |
56-
| | <span>radio selected?</span> | [`cy.get().should("have.value", "value")`](#shouldhave_value) |
57-
| | <span>radio not selected?</span> | [`cy.get().should("not.have.value", "value")`](#shouldhave_value) |
58-
| **Select** | <span>select option</span> | [`cy.slSelectByOptionText()`](#cy_slselectbyoptiontext) |
59-
| | <span>option selected?</span> | [`cy.slSelectValue().should("equal", "value")`](#cy_slselectvalue) |
60-
| | <span>option not selected?</span> | [`cy.slSelectValue().should("not.equal", "value")`](#cy_slselectvalue) |
61-
| **Textarea** | <span>focus</span> | [`cy.slFocus()`](#cy_slfocus) |
62-
| | <span>type</span> | [`cy.slTextAreaType()`](#cy_sltextareatype) |
63-
| | <span>clear</span> | [`cy.slTextAreaClear()`](#cy_sltextareaclear) |
64-
| | <span>value?</span> | [`cy.get().should("have.value", "value")`](#shouldhave_value) |
41+
| Component | Test action | Cypress command |
42+
| --------------------- | --------------------------------- | ---------------------------------------------------------------------- |
43+
| **Checkbox** | <span>check</span> | [`cy.slCheckboxCheck()`](#cy_slcheckboxcheck) |
44+
| | <span>uncheck</span> | [`cy.slCheckboxUncheck()`](#cy_slcheckboxuncheck) |
45+
| | <span>is checked?</span> | [`cy.get().should("have.prop", "checked", true)`](#shouldhave_prop) |
46+
| | <span>is not checked?</span> | [`cy.get().should("have.prop", "checked", false)`](#shouldhave_prop) |
47+
| **Checkbox Group** | <span>value?</span> | [`cy.slCheckboxGroupValue()`](#cy_slcheckboxgroupvalue) |
48+
| | <span>not value?</span> | [`cy.get().should("not.have.value", "value")`](#shouldhave_value) |
49+
| **Input** | <span>focus</span> | [`cy.slFocus()`](#cy_slfocus) |
50+
| | <span>type</span> | [`cy.slInputType()`](#cy_slinputtype) |
51+
| | <span>clear</span> | [`cy.slClear()`](#cy_slclear) |
52+
| | <span>value?</span> | [`cy.get().should("have.value", "value")`](#shouldhave_value) |
53+
| **Radio/Radio Group** | <span>select radio</span> | [`cy.get().click()`](#click) |
54+
| | <span>value?</span> | [`cy.get().should("have.value", "value")`](#shouldhave_value) |
55+
| | <span>not value?</span> | [`cy.get().should("not.have.value", "value")`](#shouldhave_value) |
56+
| **Select** | <span>select option</span> | [`cy.slSelectByOptionText()`](#cy_slselectbyoptiontext) |
57+
| | <span>option selected?</span> | [`cy.slSelectValue().should("equal", "value")`](#cy_slselectvalue) |
58+
| | <span>option not selected?</span> | [`cy.slSelectValue().should("not.equal", "value")`](#cy_slselectvalue) |
59+
| **Textarea** | <span>focus</span> | [`cy.slFocus()`](#cy_slfocus) |
60+
| | <span>type</span> | [`cy.slTextAreaType()`](#cy_sltextareatype) |
61+
| | <span>clear</span> | [`cy.slTextAreaClear()`](#cy_sltextareaclear) |
62+
| | <span>value?</span> | [`cy.get().should("have.value", "value")`](#shouldhave_value) |
6563

6664
## Generic Commands
6765

@@ -75,9 +73,9 @@ Use to **click** an element like [sl-button](/components/button) or radio item i
7573
cy.get(`[data-test-id="item-test-1"]`).click();
7674
```
7775

78-
<!-- :::tip
76+
:::tip
7977
What other elements does this work for?
80-
::: -->
78+
:::
8179

8280
### `should('have.prop')`
8381

@@ -108,9 +106,9 @@ Can also use to verify that an input does **NOT** have a certain value:
108106
cy.get(`[data-test-id="checkbox-group-test"]`).should('not.have.value', 'option-1');
109107
```
110108

111-
<!-- :::tip
109+
:::tip
112110
Does this also work for Checkbox Group? Select?
113-
::: -->
111+
:::
114112

115113
## Custom Commands
116114

@@ -164,9 +162,9 @@ Use to **focus** on elements like [sl-input](/components/input/#with-cypress) an
164162
cy.slFocus(`[data-test-id="input-test"]`);
165163
```
166164

167-
<!-- :::tip
165+
:::tip
168166
What other elements does this work for?
169-
::: -->
167+
:::
170168

171169
### `cy.slClear()`
172170

@@ -176,9 +174,9 @@ Use to **clear** [sl-input](/components/input/#with-cypress):
176174
cy.slClear(`[data-test-id="input-test"]`);
177175
```
178176

179-
<!-- :::tip
177+
:::tip
180178
What other elements does this work for?
181-
::: -->
179+
:::
182180

183181
### `cy.slTextAreaClear()`
184182

0 commit comments

Comments
 (0)