You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/06/16 23:57:57 UTC
[GitHub] [superset] suddjian commented on a diff in pull request #20261: fix(embedded): CSV download for chart
suddjian commented on code in PR #20261:
URL: https://github.com/apache/superset/pull/20261#discussion_r899649934
##########
superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts:
##########
@@ -605,4 +605,114 @@ describe('SupersetClientClass', () => {
}
});
});
+
+ describe('.postForm()', () => {
+ const protocol = 'https:';
+ const host = 'host';
+ const mockPostFormEndpoint = '/post_form/url';
+ const mockPostFormUrl = `${protocol}//${host}${mockPostFormEndpoint}`;
+ const guestToken = 'test-guest-token';
+ const postFormPayload = { number: 123, array: [1, 2, 3] };
+
+ it('makes postForm request', async () => {
+ const client = new SupersetClientClass({ protocol, host });
+ await client.init();
+
+ const createElement = jest.fn(() => ({
+ appendChild: jest.fn(),
+ submit: jest.fn(),
+ }));
+
+ document.createElement = createElement as any;
+ const appendChild = jest.fn();
+ const removeChild = jest.fn();
+ document.body.appendChild = appendChild;
+ document.body.removeChild = removeChild;
+
+ await client.postForm(mockPostFormUrl, {});
+
+ const hiddenForm = createElement.mock.results[0].value;
+ const csrfTokenInput = createElement.mock.results[1].value;
+
+ expect(createElement.mock.calls).toHaveLength(2);
+
+ expect(hiddenForm.action).toBe(mockPostFormUrl);
+ expect(hiddenForm.method).toBe('POST');
+ expect(hiddenForm.target).toBe('_blank');
+
+ expect(csrfTokenInput.type).toBe('hidden');
+ expect(csrfTokenInput.name).toBe('csrf_token');
+ expect(csrfTokenInput.value).toBe(1234);
+
+ expect(appendChild.mock.calls).toHaveLength(1);
+ expect(removeChild.mock.calls).toHaveLength(1);
+ });
+
+ it('makes postForm request with guesr token', async () => {
Review Comment:
```suggestion
it('makes postForm request with guest token', async () => {
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org