summaryrefslogtreecommitdiff
path: root/spec/frontend/static_site_editor/services/load_source_content_spec.js
blob: 98d437698c4c9ab4753281692a1971cb51e57341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Api from '~/api';

import loadSourceContent from '~/static_site_editor/services/load_source_content';

import {
  sourceContentYAML as sourceContent,
  sourceContentTitle,
  projectId,
  sourcePath,
} from '../mock_data';

describe('loadSourceContent', () => {
  describe('requesting source content succeeds', () => {
    let result;

    beforeEach(() => {
      jest.spyOn(Api, 'getRawFile').mockResolvedValue({ data: sourceContent });

      return loadSourceContent({ projectId, sourcePath }).then((_result) => {
        result = _result;
      });
    });

    it('calls getRawFile API with project id and source path', () => {
      expect(Api.getRawFile).toHaveBeenCalledWith(projectId, sourcePath);
    });

    it('extracts page title from source content', () => {
      expect(result.title).toBe(sourceContentTitle);
    });

    it('returns raw content', () => {
      expect(result.content).toBe(sourceContent);
    });
  });
});