diff options
Diffstat (limited to 'spec/frontend/static_site_editor/graphql')
-rw-r--r-- | spec/frontend/static_site_editor/graphql/resolvers/file_spec.js | 25 | ||||
-rw-r--r-- | spec/frontend/static_site_editor/graphql/resolvers/submit_content_changes_spec.js | 37 |
2 files changed, 62 insertions, 0 deletions
diff --git a/spec/frontend/static_site_editor/graphql/resolvers/file_spec.js b/spec/frontend/static_site_editor/graphql/resolvers/file_spec.js new file mode 100644 index 00000000000..8504d09e0f1 --- /dev/null +++ b/spec/frontend/static_site_editor/graphql/resolvers/file_spec.js @@ -0,0 +1,25 @@ +import fileResolver from '~/static_site_editor/graphql/resolvers/file'; +import loadSourceContent from '~/static_site_editor/services/load_source_content'; + +import { + projectId, + sourcePath, + sourceContentTitle as title, + sourceContent as content, +} from '../../mock_data'; + +jest.mock('~/static_site_editor/services/load_source_content', () => jest.fn()); + +describe('static_site_editor/graphql/resolvers/file', () => { + it('returns file content and title when fetching file successfully', () => { + loadSourceContent.mockResolvedValueOnce({ title, content }); + + return fileResolver({ fullPath: projectId }, { path: sourcePath }).then(file => { + expect(file).toEqual({ + __typename: 'File', + title, + content, + }); + }); + }); +}); diff --git a/spec/frontend/static_site_editor/graphql/resolvers/submit_content_changes_spec.js b/spec/frontend/static_site_editor/graphql/resolvers/submit_content_changes_spec.js new file mode 100644 index 00000000000..515b5394594 --- /dev/null +++ b/spec/frontend/static_site_editor/graphql/resolvers/submit_content_changes_spec.js @@ -0,0 +1,37 @@ +import savedContentMetaQuery from '~/static_site_editor/graphql/queries/saved_content_meta.query.graphql'; +import submitContentChanges from '~/static_site_editor/services/submit_content_changes'; +import submitContentChangesResolver from '~/static_site_editor/graphql/resolvers/submit_content_changes'; + +import { + projectId as project, + sourcePath, + username, + sourceContent as content, + savedContentMeta, +} from '../../mock_data'; + +jest.mock('~/static_site_editor/services/submit_content_changes', () => jest.fn()); + +describe('static_site_editor/graphql/resolvers/submit_content_changes', () => { + it('writes savedContentMeta query with the data returned by the submitContentChanges service', () => { + const cache = { writeQuery: jest.fn() }; + + submitContentChanges.mockResolvedValueOnce(savedContentMeta); + + return submitContentChangesResolver( + {}, + { input: { path: sourcePath, project, sourcePath, content, username } }, + { cache }, + ).then(() => { + expect(cache.writeQuery).toHaveBeenCalledWith({ + query: savedContentMetaQuery, + data: { + savedContentMeta: { + __typename: 'SavedContentMeta', + ...savedContentMeta, + }, + }, + }); + }); + }); +}); |