Skip to content

Commit bde2fa6

Browse files
authored
Improve documentation for groupBy (#6109)
1 parent 8e4932c commit bde2fa6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

docs/partials/_views.mdx

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Cypress automatically groups certain URL patterns to create views. However, for URLs that are not automatically grouped (e.g., `/users/alice` and `/users/bob` are not automatically grouped into `/users/*`), the `views` property allows you to specify custom URL patterns to define views. This configuration enhances the clarity and organization of your coverage reports.
22

3-
The `groupBy` property of a view definition allows you to create multiple views with a single URL pattern, grouping URLs by the specified named parameter(s).
3+
The `groupBy` property allows you to create multiple views from a single URL pattern by specifying which parts of the URL should create distinct groupings.
44

55
## Why use views?
66

@@ -11,6 +11,19 @@ This cannot be nested.
1111

1212
- **Group Dynamic URLs**: Group URLs with dynamic path parameters (e.g., `/users/alice` and `/users/bob`) that are not ids or uuids into a single view.
1313
- **Organize by Query Parameters**: Create views based on query parameters to group URLs where query strings are important to the context of the page.
14+
- **Create Distinct View Groups**: Use `groupBy` to maintain separate views for meaningful URL parameters while still grouping dynamic content.
15+
16+
## Using groupBy
17+
18+
The `groupBy` property creates distinct views based on named parameters in your URL pattern. For example, if your pattern is `/analytics/:type/:id`, using `groupBy: ["type"]` would create separate views for each unique value of `type` (like `/analytics/performance/:id` and `/analytics/usage/:id`).
19+
20+
This is particularly useful when:
21+
22+
- Different parameter values represent distinct functional areas
23+
- You want to track coverage separately for different categories of content
24+
- URL parameters determine significant UI changes
25+
26+
URLs with the same values for the specified parameters will be grouped together, while different values create distinct views.
1427

1528
## Syntax
1629

@@ -31,10 +44,10 @@ This cannot be nested.
3144

3245
The first pattern that a given URL matches is used as its view. If a URL doesn't match any of the patterns, it is grouped by the default view grouping rules, if possible.
3346

34-
| Option | Required | Default | Description |
35-
| --------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36-
| `pattern` | Required | | A URL pattern to group matching URLs into a single view. Uses [URL Pattern API](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) syntax. |
37-
| `groupBy` | Optional | | An array of named URL parameters used to further subdivide the URLs into multiple views within the same pattern. This is useful for dynamic applications where URLs represent different user interactions or data segments. |
47+
| Option | Required | Default | Description |
48+
| --------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
49+
| `pattern` | Required | | A URL pattern to group matching URLs into a single view. Uses [URL Pattern API](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) syntax. |
50+
| `groupBy` | Optional | | An array of named parameters from your pattern that should create separate views. |
3851

3952
## Examples
4053

0 commit comments

Comments
 (0)