Commit 6cf8987a authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '241199-fix-snippet-loading-json-content' into 'master'

Fix axios automatically parsing snippet content

Closes #241199

See merge request gitlab-org/gitlab!40417
parents d7bbde82 d2b362b9
...@@ -53,7 +53,10 @@ export default { ...@@ -53,7 +53,10 @@ export default {
const url = joinPaths(baseUrl, this.blob.rawPath); const url = joinPaths(baseUrl, this.blob.rawPath);
axios axios
.get(url) .get(url, {
// This prevents axios from automatically JSON.parse response
transformResponse: [f => f],
})
.then(res => { .then(res => {
this.notifyAboutUpdates({ content: res.data }); this.notifyAboutUpdates({ content: res.data });
}) })
......
---
title: Fix snippets edit not loading JSON values
merge_request: 40417
author:
type: fixed
...@@ -17,6 +17,7 @@ const TEST_PATH = 'foo/bar/test.md'; ...@@ -17,6 +17,7 @@ const TEST_PATH = 'foo/bar/test.md';
const TEST_RAW_PATH = '/gitlab/raw/path/to/blob/7'; const TEST_RAW_PATH = '/gitlab/raw/path/to/blob/7';
const TEST_FULL_PATH = joinPaths(TEST_HOST, TEST_RAW_PATH); const TEST_FULL_PATH = joinPaths(TEST_HOST, TEST_RAW_PATH);
const TEST_CONTENT = 'Lorem ipsum dolar sit amet,\nconsectetur adipiscing elit.'; const TEST_CONTENT = 'Lorem ipsum dolar sit amet,\nconsectetur adipiscing elit.';
const TEST_JSON_CONTENT = '{"abc":"lorem ipsum"}';
const TEST_BLOB = { const TEST_BLOB = {
id: TEST_ID, id: TEST_ID,
...@@ -66,7 +67,7 @@ describe('Snippet Blob Edit component', () => { ...@@ -66,7 +67,7 @@ describe('Snippet Blob Edit component', () => {
}); });
describe('with not loaded blob', () => { describe('with not loaded blob', () => {
beforeEach(async () => { beforeEach(() => {
createComponent(); createComponent();
}); });
...@@ -100,6 +101,20 @@ describe('Snippet Blob Edit component', () => { ...@@ -100,6 +101,20 @@ describe('Snippet Blob Edit component', () => {
}); });
}); });
describe('with unloaded blob and JSON content', () => {
beforeEach(() => {
axiosMock.onGet(TEST_FULL_PATH).reply(200, TEST_JSON_CONTENT);
createComponent();
});
// This checks against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/241199
it('emits raw content', async () => {
await waitForPromises();
expect(getLastUpdatedArgs()).toEqual({ content: TEST_JSON_CONTENT });
});
});
describe('with error', () => { describe('with error', () => {
beforeEach(() => { beforeEach(() => {
axiosMock.reset(); axiosMock.reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment