Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilii Iakliushin <viakliushin@gitlab.com>2020-11-11 16:41:37 +0300
committerVasilii Iakliushin <viakliushin@gitlab.com>2020-11-11 17:10:34 +0300
commitcc8137e80c00b4dc3584a73b8e17d48e06e687e0 (patch)
tree8a347be20ba3fab29075c6331f390be634f356b8
parent3aa6e6e9e618cb68eb8557df744722b188f795bd (diff)
Cover Navigation classes with tests
-rw-r--r--spec/gitlab/navigation/category_spec.rb81
-rw-r--r--spec/gitlab/navigation/doc_spec.rb56
-rw-r--r--spec/gitlab/navigation/section_spec.rb73
-rw-r--r--spec/gitlab/navigation_spec.rb86
4 files changed, 296 insertions, 0 deletions
diff --git a/spec/gitlab/navigation/category_spec.rb b/spec/gitlab/navigation/category_spec.rb
new file mode 100644
index 00000000..67d28482
--- /dev/null
+++ b/spec/gitlab/navigation/category_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+require 'gitlab/navigation/category'
+require 'gitlab/navigation/doc'
+
+describe Gitlab::Navigation::Category do
+ subject(:category) { described_class.new(element) }
+ let(:element) do
+ {
+ category_title: title,
+ external_url: external_url,
+ category_url: url,
+ ee_only: ee_only,
+ ee_tier: ee_tier,
+ docs: docs
+ }
+ end
+ let(:title) { 'Title' }
+ let(:external_url) { 'http://example.com' }
+ let(:url) { 'README.html' }
+ let(:ee_only) { true }
+ let(:ee_tier) { 'GitLab Premium' }
+ let(:docs) { [ { doc_title: 'Doc Title' } ] }
+
+ describe '#title' do
+ subject { category.title }
+
+ it { is_expected.to eq(title) }
+ end
+
+ describe '#external_url' do
+ subject { category.external_url }
+
+ it { is_expected.to eq(external_url) }
+ end
+
+ describe '#url' do
+ subject { category.url }
+
+ it { is_expected.to eq(url) }
+ end
+
+ describe '#ee_only?' do
+ subject { category.ee_only? }
+
+ it { is_expected.to eq(ee_only) }
+ end
+
+ describe '#ee_tier' do
+ subject { category.ee_tier }
+
+ it { is_expected.to eq(ee_tier) }
+ end
+
+ describe '#has_children?' do
+ subject { category.has_children? }
+
+ it { is_expected.to be_truthy }
+
+ context 'when docs are empty' do
+ let(:docs) { [] }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#children' do
+ subject { category.children }
+
+ it 'returns a list of children' do
+ children = subject
+
+ expect(children.first.title).to eq('Doc Title')
+ end
+
+ context 'when docs are empty' do
+ let(:docs) { [] }
+
+ it { is_expected.to eq([]) }
+ end
+ end
+end
diff --git a/spec/gitlab/navigation/doc_spec.rb b/spec/gitlab/navigation/doc_spec.rb
new file mode 100644
index 00000000..f823a73b
--- /dev/null
+++ b/spec/gitlab/navigation/doc_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+require 'gitlab/navigation/doc'
+
+describe Gitlab::Navigation::Doc do
+ subject(:doc) { described_class.new(element) }
+ let(:element) do
+ {
+ doc_title: title,
+ external_url: external_url,
+ doc_url: url,
+ ee_only: ee_only,
+ ee_tier: ee_tier
+ }
+ end
+ let(:title) { 'Title' }
+ let(:external_url) { 'http://example.com' }
+ let(:url) { 'README.html' }
+ let(:ee_only) { true }
+ let(:ee_tier) { 'GitLab Premium' }
+
+ describe '#title' do
+ subject { doc.title }
+
+ it { is_expected.to eq(title) }
+ end
+
+ describe '#external_url' do
+ subject { doc.external_url }
+
+ it { is_expected.to eq(external_url) }
+ end
+
+ describe '#url' do
+ subject { doc.url }
+
+ it { is_expected.to eq(url) }
+ end
+
+ describe '#ee_only?' do
+ subject { doc.ee_only? }
+
+ it { is_expected.to eq(ee_only) }
+ end
+
+ describe '#ee_tier' do
+ subject { doc.ee_tier }
+
+ it { is_expected.to eq(ee_tier) }
+ end
+
+ describe '#children' do
+ subject { doc.children }
+
+ it { is_expected.to eq([]) }
+ end
+end
diff --git a/spec/gitlab/navigation/section_spec.rb b/spec/gitlab/navigation/section_spec.rb
new file mode 100644
index 00000000..328793e9
--- /dev/null
+++ b/spec/gitlab/navigation/section_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+require 'gitlab/navigation/section'
+require 'gitlab/navigation/category'
+
+describe Gitlab::Navigation::Section do
+ subject(:section) { described_class.new(element) }
+ let(:element) do
+ {
+ section_title: title,
+ section_url: url,
+ ee_only: ee_only,
+ ee_tier: ee_tier,
+ section_categories: categories
+ }
+ end
+ let(:title) { 'Title' }
+ let(:url) { 'README.html' }
+ let(:ee_only) { true }
+ let(:ee_tier) { 'GitLab Premium' }
+ let(:categories) { [ { category_title: 'Category Title' } ] }
+
+ describe '#title' do
+ subject { section.title }
+
+ it { is_expected.to eq(title) }
+ end
+
+ describe '#url' do
+ subject { section.url }
+
+ it { is_expected.to eq(url) }
+ end
+
+ describe '#ee_only?' do
+ subject { section.ee_only? }
+
+ it { is_expected.to eq(ee_only) }
+ end
+
+ describe '#ee_tier' do
+ subject { section.ee_tier }
+
+ it { is_expected.to eq(ee_tier) }
+ end
+
+ describe '#has_children?' do
+ subject { section.has_children? }
+
+ it { is_expected.to be_truthy }
+
+ context 'when categories are empty' do
+ let(:categories) { [] }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#children' do
+ subject { section.children }
+
+ it 'returns a list of children' do
+ children = subject
+
+ expect(children.first.title).to eq('Category Title')
+ end
+
+ context 'when categories are empty' do
+ let(:categories) { [] }
+
+ it { is_expected.to eq([]) }
+ end
+ end
+end
diff --git a/spec/gitlab/navigation_spec.rb b/spec/gitlab/navigation_spec.rb
new file mode 100644
index 00000000..a2d2bda7
--- /dev/null
+++ b/spec/gitlab/navigation_spec.rb
@@ -0,0 +1,86 @@
+require 'spec_helper'
+require 'gitlab/navigation'
+require 'gitlab/navigation/section'
+
+describe Gitlab::Navigation do
+ subject(:navigation) { described_class.new(items, item) }
+ let(:item) { double(path: '/omnibus/user/README.html', identifier: double(to_s: '/omnibus/user/README.md')) }
+ let(:items) do
+ {
+ '/_data/omnibus-nav.yaml' => { sections: [Gitlab::Navigation::Section.new(section_title: 'Omnibus Section')] },
+ '/_data/default-nav.yaml' => { sections: [Gitlab::Navigation::Section.new(section_title: 'Default Section')] }
+ }
+ end
+
+ describe '#nav_items' do
+ subject { navigation.nav_items }
+
+ it 'returns project specific sections' do
+ sections = subject[:sections]
+ section = sections.first
+
+ expect(section.title).to eq('Omnibus Section')
+ end
+
+ context 'when yaml configuration for project does not exist' do
+ let(:item) { double(path: '/ee/user/README.html', identifier: double(to_s: '/ee/user/README.md')) }
+
+ it 'returns default sections' do
+ sections = subject[:sections]
+ section = sections.first
+
+ expect(section.title).to eq('Default Section')
+ end
+ end
+ end
+
+ describe '#element_href' do
+ subject { navigation.element_href(element) }
+ let(:element) { Gitlab::Navigation::Section.new(section_url: url) }
+ let(:url) { 'user/README.html' }
+
+ it { is_expected.to eq('/omnibus/user/README.html') }
+
+ context 'when yaml configuration for project does not exist' do
+ let(:item) { double(path: '/ee/user/README.html', identifier: double(to_s: '/ee/user/README.md')) }
+
+ it { is_expected.to eq('/ee/user/README.html') }
+ end
+ end
+
+ describe '#show_element?' do
+ subject { navigation.show_element?(element) }
+ let(:element) { Gitlab::Navigation::Section.new(section_url: url) }
+ let(:url) { 'user/README.html' }
+
+ it { is_expected.to be_truthy }
+
+ context 'when url does not match item path' do
+ let(:url) { 'project/README.html' }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#id_for' do
+ subject { navigation.id_for(element) }
+ let(:element) { Gitlab::Navigation::Section.new(section_title: 'Section Example') }
+
+ it { is_expected.to eq 'SectionExample' }
+ end
+
+ describe '#optional_ee_badge' do
+ subject { navigation.optional_ee_badge(element) }
+ let(:element) { Gitlab::Navigation::Section.new(ee_only: ee_only, ee_tier: ee_tier) }
+ let(:ee_tier) { 'GitLab Starter' }
+ let(:ee_only) { true }
+
+ it { is_expected.to include('span').and include(ee_tier) }
+
+ context 'when ee_only -> false' do
+ let(:ee_only) { false }
+
+ it { is_expected.to be_nil }
+ end
+ end
+end