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
path: root/spec
diff options
context:
space:
mode:
authorVasilii Iakliushin <viakliushin@gitlab.com>2020-11-17 12:33:08 +0300
committerVasilii Iakliushin <viakliushin@gitlab.com>2020-11-17 12:33:08 +0300
commit423a2757cf2317ac8ed0eddc42a1094aa599185f (patch)
treed1a178fdec3527e9391a2f48038d4b54ccd3e7d1 /spec
parentbdc9c108db5af174faca8a7bf3c7023135d1432d (diff)
parent43e56b085a8176c82c39148ba8a2c003742e4b55 (diff)
Merge branch '879_refactor_global_navigation' into 'master'
Extract Navigation class to manage layout variables See merge request gitlab-org/gitlab-docs!1290
Diffstat (limited to 'spec')
-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