diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/snippets/test_utils.js | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/snippets/test_utils.js')
-rw-r--r-- | spec/frontend/snippets/test_utils.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/frontend/snippets/test_utils.js b/spec/frontend/snippets/test_utils.js new file mode 100644 index 00000000000..86262723157 --- /dev/null +++ b/spec/frontend/snippets/test_utils.js @@ -0,0 +1,76 @@ +import { + SNIPPET_BLOB_ACTION_CREATE, + SNIPPET_BLOB_ACTION_UPDATE, + SNIPPET_BLOB_ACTION_MOVE, + SNIPPET_BLOB_ACTION_DELETE, +} from '~/snippets/constants'; + +const CONTENT_1 = 'Lorem ipsum dolar\nSit amit\n\nGoodbye!\n'; +const CONTENT_2 = 'Lorem ipsum dolar sit amit.\n\nGoodbye!\n'; + +export const testEntries = { + created: { + id: 'blob_1', + diff: { + action: SNIPPET_BLOB_ACTION_CREATE, + filePath: '/new/file', + previousPath: '/new/file', + content: CONTENT_1, + }, + }, + deleted: { + id: 'blob_2', + diff: { + action: SNIPPET_BLOB_ACTION_DELETE, + filePath: '/src/delete/me', + previousPath: '/src/delete/me', + content: CONTENT_1, + }, + }, + updated: { + id: 'blob_3', + origContent: CONTENT_1, + diff: { + action: SNIPPET_BLOB_ACTION_UPDATE, + filePath: '/lorem.md', + previousPath: '/lorem.md', + content: CONTENT_2, + }, + }, + renamed: { + id: 'blob_4', + diff: { + action: SNIPPET_BLOB_ACTION_MOVE, + filePath: '/dolar.md', + previousPath: '/ipsum.md', + content: CONTENT_1, + }, + }, + renamedAndUpdated: { + id: 'blob_5', + origContent: CONTENT_1, + diff: { + action: SNIPPET_BLOB_ACTION_MOVE, + filePath: '/sit.md', + previousPath: '/sit/amit.md', + content: CONTENT_2, + }, + }, +}; + +export const createBlobFromTestEntry = ({ diff, origContent }, isOrig = false) => ({ + content: isOrig && origContent ? origContent : diff.content, + path: isOrig ? diff.previousPath : diff.filePath, +}); + +export const createBlobsFromTestEntries = (entries, isOrig = false) => + entries.reduce( + (acc, entry) => + Object.assign(acc, { + [entry.id]: { + id: entry.id, + ...createBlobFromTestEntry(entry, isOrig), + }, + }), + {}, + ); |