diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/snippets/components/snippet_title_spec.js | 72 | ||||
-rw-r--r-- | spec/lib/gitlab/git_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 14 |
4 files changed, 93 insertions, 6 deletions
diff --git a/spec/frontend/snippets/components/snippet_title_spec.js b/spec/frontend/snippets/components/snippet_title_spec.js new file mode 100644 index 00000000000..fb2193b26b0 --- /dev/null +++ b/spec/frontend/snippets/components/snippet_title_spec.js @@ -0,0 +1,72 @@ +import SnippetTitle from '~/snippets/components/snippet_title.vue'; +import { GlSprintf } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; + +describe('Snippet header component', () => { + let wrapper; + const title = 'The property of Thor'; + const description = 'Do not touch this hammer'; + const snippet = { + snippet: { + title, + description, + }, + }; + + function createComponent({ props = snippet } = {}) { + const defaultProps = Object.assign({}, props); + + wrapper = shallowMount(SnippetTitle, { + sync: false, + propsData: { + ...defaultProps, + }, + }); + } + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders itself', () => { + createComponent(); + expect(wrapper.find('.snippet-header').exists()).toBe(true); + }); + + it('renders snippets title and description', () => { + createComponent(); + expect(wrapper.text().trim()).toContain(title); + expect(wrapper.text().trim()).toContain(description); + }); + + it('does not render recent changes time stamp if there were no updates', () => { + createComponent(); + expect(wrapper.find(GlSprintf).exists()).toBe(false); + }); + + it('does not render recent changes time stamp if the time for creation and updates match', () => { + const props = Object.assign(snippet, { + snippet: { + ...snippet.snippet, + createdAt: '2019-12-16T21:45:36Z', + updatedAt: '2019-12-16T21:45:36Z', + }, + }); + createComponent({ props }); + + expect(wrapper.find(GlSprintf).exists()).toBe(false); + }); + + it('renders translated string with most recent changes timestamp if changes were made', () => { + const props = Object.assign(snippet, { + snippet: { + ...snippet.snippet, + createdAt: '2019-12-16T21:45:36Z', + updatedAt: '2019-15-16T21:45:36Z', + }, + }); + createComponent({ props }); + + expect(wrapper.find(GlSprintf).exists()).toBe(true); + }); +}); diff --git a/spec/lib/gitlab/git_spec.rb b/spec/lib/gitlab/git_spec.rb index fbc49e05c37..cb07bbdbaaa 100644 --- a/spec/lib/gitlab/git_spec.rb +++ b/spec/lib/gitlab/git_spec.rb @@ -73,7 +73,8 @@ describe Gitlab::Git do [sha, short_sha, true], [sha, sha.reverse, false], [sha, too_short_sha, false], - [sha, nil, false] + [sha, nil, false], + [nil, nil, true] ] end diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb index cb870cc996b..772b0168a2a 100644 --- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb +++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb @@ -4,7 +4,7 @@ require 'fast_spec_helper' describe Gitlab::SidekiqLogging::StructuredLogger do describe '#call' do - let(:timestamp) { Time.iso8601('2018-01-01T12:00:00Z') } + let(:timestamp) { Time.iso8601('2018-01-01T12:00:00.000Z') } let(:created_at) { timestamp - 1.second } let(:scheduling_latency_s) { 1.0 } @@ -30,8 +30,8 @@ describe Gitlab::SidekiqLogging::StructuredLogger do 'message' => 'TestWorker JID-da883554ee4fe414012f5f42: start', 'job_status' => 'start', 'pid' => Process.pid, - 'created_at' => created_at.iso8601(6), - 'enqueued_at' => created_at.iso8601(6), + 'created_at' => created_at.iso8601(3), + 'enqueued_at' => created_at.iso8601(3), 'scheduling_latency_s' => scheduling_latency_s ) end @@ -40,7 +40,7 @@ describe Gitlab::SidekiqLogging::StructuredLogger do 'message' => 'TestWorker JID-da883554ee4fe414012f5f42: done: 0.0 sec', 'job_status' => 'done', 'duration' => 0.0, - "completed_at" => timestamp.iso8601(6), + "completed_at" => timestamp.iso8601(3), "cpu_s" => 1.111112 ) end @@ -145,7 +145,7 @@ describe Gitlab::SidekiqLogging::StructuredLogger do end context 'with latency' do - let(:created_at) { Time.iso8601('2018-01-01T10:00:00Z') } + let(:created_at) { Time.iso8601('2018-01-01T10:00:00.000Z') } let(:scheduling_latency_s) { 7200.0 } it 'logs with scheduling latency' do diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 1c1b550c69b..930ec889206 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -63,6 +63,20 @@ describe Commit do end end + describe '#diff_refs' do + it 'is equal to itself' do + expect(commit.diff_refs).to eq(commit.diff_refs) + end + + context 'from a factory' do + let(:commit) { create(:commit) } + + it 'is equal to itself' do + expect(commit.diff_refs).to eq(commit.diff_refs) + end + end + end + describe '#author', :request_store do it 'looks up the author in a case-insensitive way' do user = create(:user, email: commit.author_email.upcase) |