diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/api/schemas/entities/diff_viewer.json | 8 | ||||
-rw-r--r-- | spec/javascripts/diffs/components/diff_content_spec.js | 5 | ||||
-rw-r--r-- | spec/javascripts/diffs/components/diff_file_spec.js | 5 | ||||
-rw-r--r-- | spec/javascripts/diffs/mock_data/diff_file.js | 3 | ||||
-rw-r--r-- | spec/serializers/diff_file_entity_spec.rb | 5 | ||||
-rw-r--r-- | spec/serializers/diff_viewer_entity_spec.rb | 19 |
6 files changed, 39 insertions, 6 deletions
diff --git a/spec/fixtures/api/schemas/entities/diff_viewer.json b/spec/fixtures/api/schemas/entities/diff_viewer.json new file mode 100644 index 00000000000..19780f49a88 --- /dev/null +++ b/spec/fixtures/api/schemas/entities/diff_viewer.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "required": ["name"], + "properties": { + "name": { "type": ["string"] } + }, + "additionalProperties": false +} diff --git a/spec/javascripts/diffs/components/diff_content_spec.js b/spec/javascripts/diffs/components/diff_content_spec.js index dea600a783a..67f7b569f47 100644 --- a/spec/javascripts/diffs/components/diff_content_spec.js +++ b/spec/javascripts/diffs/components/diff_content_spec.js @@ -8,13 +8,12 @@ import diffFileMockData from '../mock_data/diff_file'; describe('DiffContent', () => { const Component = Vue.extend(DiffContentComponent); let vm; - const getDiffFileMock = () => Object.assign({}, diffFileMockData); beforeEach(() => { vm = mountComponentWithStore(Component, { store, props: { - diffFile: getDiffFileMock(), + diffFile: JSON.parse(JSON.stringify(diffFileMockData)), }, }); }); @@ -43,7 +42,7 @@ describe('DiffContent', () => { describe('Non-Text diffs', () => { beforeEach(() => { - vm.diffFile.text = false; + vm.diffFile.viewer.name = 'image'; }); describe('image diff', () => { diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index 2a52cd2b179..13859f43e98 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -6,11 +6,10 @@ import diffFileMockData from '../mock_data/diff_file'; describe('DiffFile', () => { let vm; - const getDiffFileMock = () => Object.assign({}, diffFileMockData); beforeEach(() => { vm = createComponentWithStore(Vue.extend(DiffFileComponent), store, { - file: getDiffFileMock(), + file: JSON.parse(JSON.stringify(diffFileMockData)), canCurrentUserFork: false, }).$mount(); }); @@ -18,7 +17,7 @@ describe('DiffFile', () => { describe('template', () => { it('should render component with file header, file content components', () => { const el = vm.$el; - const { fileHash, filePath } = diffFileMockData; + const { fileHash, filePath } = vm.file; expect(el.id).toEqual(fileHash); expect(el.classList.contains('diff-file')).toEqual(true); diff --git a/spec/javascripts/diffs/mock_data/diff_file.js b/spec/javascripts/diffs/mock_data/diff_file.js index 2aa2f8f3528..d7bc0dbe431 100644 --- a/spec/javascripts/diffs/mock_data/diff_file.js +++ b/spec/javascripts/diffs/mock_data/diff_file.js @@ -23,6 +23,9 @@ export default { aMode: '100644', bMode: '100644', text: true, + viewer: { + name: 'text', + }, addedLines: 2, removedLines: 0, diffRefs: { diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index 3d90ce44dfb..7497b8f27bd 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -26,6 +26,11 @@ describe DiffFileEntity do ) end + it 'includes viewer' do + expect(subject[:viewer].with_indifferent_access) + .to match_schema('entities/diff_viewer') + end + # Converted diff files from GitHub import does not contain blob file # and content sha. context 'when diff file does not have a blob and content sha' do diff --git a/spec/serializers/diff_viewer_entity_spec.rb b/spec/serializers/diff_viewer_entity_spec.rb new file mode 100644 index 00000000000..66ac6ef2adc --- /dev/null +++ b/spec/serializers/diff_viewer_entity_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe DiffViewerEntity do + include RepoHelpers + + let(:project) { create(:project, :repository) } + let(:repository) { project.repository } + let(:commit) { project.commit(sample_commit.id) } + let(:diff_refs) { commit.diff_refs } + let(:diff) { commit.raw_diffs.first } + let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) } + let(:viewer) { diff_file.simple_viewer } + + subject { described_class.new(viewer).as_json } + + it 'serializes diff file viewer' do + expect(subject.with_indifferent_access).to match_schema('entities/diff_viewer') + end +end |