|
1 | 1 | import React from "react";
|
2 |
| -import { PolarisAutoForm } from "../../../../src/auto/polaris/PolarisAutoForm.js"; |
3 |
| -import { PolarisAutoInput } from "../../../../src/auto/polaris/inputs/PolarisAutoInput.js"; |
4 |
| -import { PolarisAutoBelongsToForm } from "../../../../src/auto/polaris/inputs/relationships/PolarisAutoBelongsToForm.js"; |
5 |
| -import { PolarisAutoSubmit } from "../../../../src/auto/polaris/submit/PolarisAutoSubmit.js"; |
6 |
| -import { PolarisSubmitResultBanner } from "../../../../src/auto/polaris/submit/PolarisSubmitResultBanner.js"; |
7 | 2 | import { api } from "../../../support/api.js";
|
8 |
| -import { PolarisWrapper } from "../../../support/auto.js"; |
| 3 | +import { describeForEachAutoAdapter } from "../../../support/auto.js"; |
| 4 | +import { SUITE_NAMES } from "../../../support/constants.js"; |
9 | 5 |
|
10 | 6 | const originalSectionLinkedToWidget = { id: "1", name: "Section 1", label: "Label 1" };
|
11 | 7 |
|
12 |
| -describe("PolarisAutoBelongsToForm", () => { |
13 |
| - const interceptModelUpdateActionMetadata = () => { |
14 |
| - cy.intercept({ method: "POST", url: `${api.connection.endpoint}?operation=ModelActionMetadata` }, RealWidgetMetadata).as( |
15 |
| - "ModelCreateActionMetadata" |
16 |
| - ); |
17 |
| - }; |
| 8 | +describeForEachAutoAdapter( |
| 9 | + "AutoBelongsToForm", |
| 10 | + ({ name, adapter: { AutoForm, AutoInput, AutoSubmit, SubmitResultBanner, AutoBelongsToForm }, wrapper }) => { |
| 11 | + const interceptModelUpdateActionMetadata = () => { |
| 12 | + cy.intercept({ method: "POST", url: `${api.connection.endpoint}?operation=ModelActionMetadata` }, RealWidgetMetadata).as( |
| 13 | + "ModelCreateActionMetadata" |
| 14 | + ); |
| 15 | + }; |
18 | 16 |
|
19 |
| - const expectUpdateActionSubmissionVariables = (expectedQueryValue?: any) => { |
20 |
| - cy.intercept({ method: "POST", url: `${api.connection.endpoint}?operation=updateWidget` }, (req) => { |
21 |
| - // eslint-disable-next-line |
22 |
| - expect(req.body.variables).to.deep.equal(expectedQueryValue); |
23 |
| - req.reply({ data: { updateWidget: { success: true, errors: null, x: {} } } }); |
24 |
| - }).as("updateWidget"); |
25 |
| - }; |
| 17 | + const getDropdownMenuTriggerSelector = () => { |
| 18 | + return name == SUITE_NAMES.SHADCN ? "[data-testid='widget.section-dropdown-menu-trigger']" : ".Polaris-Button__Icon"; |
| 19 | + }; |
26 | 20 |
|
27 |
| - const interceptWidgetQuery = () => { |
28 |
| - cy.intercept({ method: "POST", url: `${api.connection.endpoint}?operation=widget` }, (req) => { |
29 |
| - req.reply({ |
30 |
| - data: { |
31 |
| - widget: { |
32 |
| - __typename: "Widget", |
33 |
| - id: "42", |
34 |
| - name: "test record", |
35 |
| - section: originalSectionLinkedToWidget, |
36 |
| - sectionId: parseInt(originalSectionLinkedToWidget.id), |
37 |
| - }, |
38 |
| - }, |
39 |
| - }); |
40 |
| - }).as("widget"); |
41 |
| - }; |
| 21 | + const expectUpdateActionSubmissionVariables = (expectedQueryValue?: any) => { |
| 22 | + cy.intercept({ method: "POST", url: `${api.connection.endpoint}?operation=updateWidget` }, (req) => { |
| 23 | + // eslint-disable-next-line |
| 24 | + expect(req.body.variables).to.deep.equal(expectedQueryValue); |
| 25 | + req.reply({ data: { updateWidget: { success: true, errors: null, x: {} } } }); |
| 26 | + }).as("updateWidget"); |
| 27 | + }; |
42 | 28 |
|
43 |
| - const interceptSectionsOptionsQuery = () => { |
44 |
| - cy.intercept( |
45 |
| - { |
46 |
| - method: "POST", |
47 |
| - url: `${api.connection.endpoint}?operation=sections`, |
48 |
| - }, |
49 |
| - (req) => { |
50 |
| - const sections = [ |
51 |
| - { |
52 |
| - cursor: "eyJpZCI6IjEwODgifQ==", |
53 |
| - node: { |
54 |
| - __typename: "Section", |
55 |
| - id: "1", |
56 |
| - createdAt: "2023-09-07T19:18:50.742Z", |
57 |
| - name: "Section 1", |
58 |
| - label: "Label 1", |
59 |
| - updatedAt: "2024-07-09T14:42:20.788Z", |
| 29 | + const interceptWidgetQuery = () => { |
| 30 | + cy.intercept({ method: "POST", url: `${api.connection.endpoint}?operation=widget` }, (req) => { |
| 31 | + req.reply({ |
| 32 | + data: { |
| 33 | + widget: { |
| 34 | + __typename: "Widget", |
| 35 | + id: "42", |
| 36 | + name: "test record", |
| 37 | + section: originalSectionLinkedToWidget, |
| 38 | + sectionId: parseInt(originalSectionLinkedToWidget.id), |
60 | 39 | },
|
61 |
| - __typename: "SectionEdge", |
62 | 40 | },
|
63 |
| - ]; |
| 41 | + }); |
| 42 | + }).as("widget"); |
| 43 | + }; |
64 | 44 |
|
65 |
| - req.reply({ |
66 |
| - data: { |
67 |
| - sections: { |
68 |
| - pageInfo: { |
69 |
| - hasNextPage: false, |
70 |
| - hasPreviousPage: false, |
71 |
| - startCursor: "eyJpZCI6IjEifQ==", |
72 |
| - endCursor: "eyJpZCI6IjIifQ==", |
73 |
| - __typename: "PageInfo", |
| 45 | + const interceptSectionsOptionsQuery = () => { |
| 46 | + cy.intercept( |
| 47 | + { |
| 48 | + method: "POST", |
| 49 | + url: `${api.connection.endpoint}?operation=sections`, |
| 50 | + }, |
| 51 | + (req) => { |
| 52 | + const sections = [ |
| 53 | + { |
| 54 | + cursor: "eyJpZCI6IjEwODgifQ==", |
| 55 | + node: { |
| 56 | + __typename: "Section", |
| 57 | + id: "1", |
| 58 | + createdAt: "2023-09-07T19:18:50.742Z", |
| 59 | + name: "Section 1", |
| 60 | + label: "Label 1", |
| 61 | + updatedAt: "2024-07-09T14:42:20.788Z", |
74 | 62 | },
|
75 |
| - edges: sections, |
76 |
| - __typename: "SectionConnection", |
| 63 | + __typename: "SectionEdge", |
77 | 64 | },
|
78 |
| - gadgetMeta: { |
79 |
| - hydrations: { |
80 |
| - createdAt: "DateTime", |
81 |
| - updatedAt: "DateTime", |
| 65 | + ]; |
| 66 | + |
| 67 | + req.reply({ |
| 68 | + data: { |
| 69 | + sections: { |
| 70 | + pageInfo: { |
| 71 | + hasNextPage: false, |
| 72 | + hasPreviousPage: false, |
| 73 | + startCursor: "eyJpZCI6IjEifQ==", |
| 74 | + endCursor: "eyJpZCI6IjIifQ==", |
| 75 | + __typename: "PageInfo", |
| 76 | + }, |
| 77 | + edges: sections, |
| 78 | + __typename: "SectionConnection", |
| 79 | + }, |
| 80 | + gadgetMeta: { |
| 81 | + hydrations: { |
| 82 | + createdAt: "DateTime", |
| 83 | + updatedAt: "DateTime", |
| 84 | + }, |
| 85 | + __typename: "GadgetApplicationMeta", |
82 | 86 | },
|
83 |
| - __typename: "GadgetApplicationMeta", |
84 | 87 | },
|
85 |
| - }, |
86 |
| - }); |
87 |
| - } |
88 |
| - ).as("sections"); |
89 |
| - }; |
| 88 | + }); |
| 89 | + } |
| 90 | + ).as("sections"); |
| 91 | + }; |
90 | 92 |
|
91 |
| - beforeEach(() => { |
92 |
| - cy.viewport("macbook-13"); |
| 93 | + beforeEach(() => { |
| 94 | + cy.viewport("macbook-13"); |
93 | 95 |
|
94 |
| - interceptModelUpdateActionMetadata(); |
95 |
| - interceptSectionsOptionsQuery(); |
96 |
| - interceptWidgetQuery(); |
97 |
| - }); |
| 96 | + interceptModelUpdateActionMetadata(); |
| 97 | + interceptSectionsOptionsQuery(); |
| 98 | + interceptWidgetQuery(); |
| 99 | + }); |
98 | 100 |
|
99 |
| - it("renders form fields for related record", () => { |
100 |
| - cy.mountWithWrapper( |
101 |
| - <PolarisAutoForm action={api.widget.update} findBy="42"> |
102 |
| - <PolarisSubmitResultBanner /> |
103 |
| - <PolarisAutoBelongsToForm field="section" primaryLabel="name" secondaryLabel="label"> |
104 |
| - <PolarisAutoInput field="name" /> |
105 |
| - <PolarisAutoInput field="label" /> |
106 |
| - </PolarisAutoBelongsToForm> |
107 |
| - <PolarisAutoSubmit id="submit" /> |
108 |
| - </PolarisAutoForm>, |
109 |
| - PolarisWrapper |
110 |
| - ); |
| 101 | + it("renders form fields for related record", () => { |
| 102 | + cy.mountWithWrapper( |
| 103 | + <AutoForm action={api.widget.update} findBy="42"> |
| 104 | + <SubmitResultBanner /> |
| 105 | + <AutoBelongsToForm field="section" primaryLabel="name" secondaryLabel="label"> |
| 106 | + <AutoInput field="name" /> |
| 107 | + <AutoInput field="label" /> |
| 108 | + </AutoBelongsToForm> |
| 109 | + <AutoSubmit id="submit" /> |
| 110 | + </AutoForm>, |
| 111 | + wrapper |
| 112 | + ); |
111 | 113 |
|
112 |
| - cy.wait("@ModelCreateActionMetadata"); |
113 |
| - cy.wait("@widget"); |
| 114 | + cy.wait("@ModelCreateActionMetadata"); |
| 115 | + cy.wait("@widget"); |
114 | 116 |
|
115 |
| - cy.contains("Section 1"); // primary label |
116 |
| - cy.contains("Label 1"); // secondary label |
| 117 | + cy.contains("Section 1"); // primary label |
| 118 | + cy.contains("Label 1"); // secondary label |
117 | 119 |
|
118 |
| - cy.get(".Polaris-Button__Icon").first().click(); |
119 |
| - cy.contains("Edit section").click(); |
| 120 | + cy.get(getDropdownMenuTriggerSelector()).first().click(); |
| 121 | + cy.contains("Edit section").click(); |
120 | 122 |
|
121 |
| - cy.get('input[id="widget.section.name"]').should("exist").click().type(" - updated"); |
122 |
| - cy.get('input[id="widget.section.label"]').should("exist").click().type(" - updated"); |
| 123 | + cy.clickAndType('input[id="widget.section.name"]', "Section 1 - updated", true); |
| 124 | + cy.clickAndType('input[id="widget.section.label"]', "Label 1 - updated", true); |
123 | 125 |
|
124 |
| - cy.contains("Save").click(); |
| 126 | + cy.contains("Save").click(); |
125 | 127 |
|
126 |
| - expectUpdateActionSubmissionVariables({ |
127 |
| - id: "42", |
128 |
| - widget: { |
129 |
| - section: { update: { id: "1", name: "Section 1 - updated", label: "Label 1 - updated" } }, |
130 |
| - }, |
| 128 | + expectUpdateActionSubmissionVariables({ |
| 129 | + id: "42", |
| 130 | + widget: { |
| 131 | + section: { update: { id: "1", name: "Section 1 - updated", label: "Label 1 - updated" } }, |
| 132 | + }, |
| 133 | + }); |
| 134 | + cy.get('[id="submit"]').click(); |
| 135 | + cy.wait("@updateWidget"); |
131 | 136 | });
|
132 |
| - cy.get('[id="submit"]').click(); |
133 |
| - cy.wait("@updateWidget"); |
134 |
| - }); |
135 | 137 |
|
136 |
| - it("can unlink a belongsTo relationship", () => { |
137 |
| - cy.mountWithWrapper( |
138 |
| - <PolarisAutoForm action={api.widget.update} findBy="42"> |
139 |
| - <PolarisSubmitResultBanner /> |
140 |
| - <PolarisAutoBelongsToForm field="section" primaryLabel="name" secondaryLabel="label"> |
141 |
| - <PolarisAutoInput field="name" /> |
142 |
| - <PolarisAutoInput field="label" /> |
143 |
| - </PolarisAutoBelongsToForm> |
144 |
| - <PolarisAutoSubmit id="submit" /> |
145 |
| - </PolarisAutoForm>, |
146 |
| - PolarisWrapper |
147 |
| - ); |
| 138 | + it("can unlink a belongsTo relationship", () => { |
| 139 | + cy.mountWithWrapper( |
| 140 | + <AutoForm action={api.widget.update} findBy="42"> |
| 141 | + <SubmitResultBanner /> |
| 142 | + <AutoBelongsToForm field="section" primaryLabel="name" secondaryLabel="label"> |
| 143 | + <AutoInput field="name" /> |
| 144 | + <AutoInput field="label" /> |
| 145 | + </AutoBelongsToForm> |
| 146 | + <AutoSubmit id="submit" /> |
| 147 | + </AutoForm>, |
| 148 | + wrapper |
| 149 | + ); |
148 | 150 |
|
149 |
| - cy.wait("@ModelCreateActionMetadata"); |
150 |
| - cy.wait("@widget"); |
| 151 | + cy.wait("@ModelCreateActionMetadata"); |
| 152 | + cy.wait("@widget"); |
151 | 153 |
|
152 |
| - cy.contains("Section 1"); // primary label |
153 |
| - cy.contains("Label 1"); // secondary label |
| 154 | + cy.contains("Section 1"); // primary label |
| 155 | + cy.contains("Label 1"); // secondary label |
154 | 156 |
|
155 |
| - cy.get(".Polaris-Button__Icon").first().click(); |
156 |
| - cy.contains("Remove section").click(); |
| 157 | + cy.get(getDropdownMenuTriggerSelector()).first().click(); |
| 158 | + cy.contains("Remove section").click(); |
157 | 159 |
|
158 |
| - expectUpdateActionSubmissionVariables({ |
159 |
| - id: "42", |
160 |
| - widget: { |
161 |
| - section: { _link: null }, |
162 |
| - }, |
| 160 | + expectUpdateActionSubmissionVariables({ |
| 161 | + id: "42", |
| 162 | + widget: { |
| 163 | + section: { _link: null }, |
| 164 | + }, |
| 165 | + }); |
| 166 | + cy.get('[id="submit"]').click(); |
| 167 | + cy.wait("@updateWidget"); |
163 | 168 | });
|
164 |
| - cy.get('[id="submit"]').click(); |
165 |
| - cy.wait("@updateWidget"); |
166 |
| - }); |
167 |
| -}); |
| 169 | + } |
| 170 | +); |
168 | 171 |
|
169 | 172 | const RealWidgetMetadata = {
|
170 | 173 | data: {
|
|
0 commit comments