AAfghahi commented on a change in pull request #18131:
URL: https://github.com/apache/superset/pull/18131#discussion_r803129551



##########
File path: superset-frontend/src/components/ReportModal/index.test.tsx
##########
@@ -107,4 +110,105 @@ describe('Email Report Modal', () => {
     expect(reportNameTextbox).toHaveDisplayValue('');
     expect(addButton).toBeDisabled();
   });
+
+  describe('Email Report Modal', () => {
+    let isFeatureEnabledMock: any;
+    let dispatch: any;
+
+    beforeEach(async () => {
+      isFeatureEnabledMock = jest
+        .spyOn(featureFlags, 'isFeatureEnabled')
+        .mockImplementation(() => true);
+      dispatch = sinon.spy();
+    });
+
+    afterAll(() => {
+      isFeatureEnabledMock.mockRestore();
+    });
+
+    it('creates a new email report', async () => {
+      // ---------- Render/value setup ----------
+      const reportValues = {
+        id: 1,
+        result: {
+          active: true,
+          creation_method: 'dashboards',
+          crontab: '0 12 * * 1',
+          dashboard: 1,
+          name: 'Weekly Report',
+          owners: [1],
+          recipients: [
+            {
+              recipient_config_json: {
+                target: '[email protected]',
+              },
+              type: 'Email',
+            },
+          ],
+          type: 'Report',
+        },
+      };
+      // This is needed to structure the reportValues to match the fetchMock 
return
+      const stringyReportValues = 
`{"id":1,"result":{"active":true,"creation_method":"dashboards","crontab":"0 12 
* * 1","dashboard":${1},"name":"Weekly 
Report","owners":[${1}],"recipients":[{"recipient_config_json":{"target":"[email protected]"},"type":"Email"}],"type":"Report"}}`;
+      // Watch for report POST
+      fetchMock.post(REPORT_ENDPOINT, reportValues);
+
+      // Click "Add" button to create a new email report
+      const addButton = screen.getByRole('button', { name: /add/i });
+      userEvent.click(addButton);
+
+      // Mock addReport from Redux
+      const makeRequest = () => {
+        const request = actions.addReport(reportValues);
+        return request(dispatch);
+      };
+
+      return makeRequest().then(() => {
+        // 🐞 ----- There are 2 POST calls at this point ----- 🐞
+
+        // addReport's mocked POST return should match the mocked values
+        expect(fetchMock.lastOptions()?.body).toEqual(stringyReportValues);
+        // Dispatch should be called once for addReport
+        expect(dispatch.callCount).toBe(2);
+        const reportCalls = fetchMock.calls(REPORT_ENDPOINT);
+        expect(reportCalls).toHaveLength(2);
+      });
+    });
+
+    // it('edits an existing email report', async () => {

Review comment:
       I think this a todo for the future though.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to