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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-31 18:08:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-31 18:08:32 +0300
commit85ea3dd4f4855e99d9a69c8e609095199597195a (patch)
tree46e74d30d0ef5cced04005b4a76c66ec18f6a749 /spec/components
parent5820d448c17f93606afb52d878c00d84681764e0 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/components')
-rw-r--r--spec/components/diffs/stats_component_spec.rb67
-rw-r--r--spec/components/pajamas/alert_component_spec.rb104
2 files changed, 171 insertions, 0 deletions
diff --git a/spec/components/diffs/stats_component_spec.rb b/spec/components/diffs/stats_component_spec.rb
new file mode 100644
index 00000000000..2e5a5f2ca26
--- /dev/null
+++ b/spec/components/diffs/stats_component_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Diffs::StatsComponent, type: :component do
+ include RepoHelpers
+
+ subject(:component) do
+ described_class.new(diff_files: diff_files)
+ end
+
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:repository) { project.repository }
+ let_it_be(:commit) { project.commit(sample_commit.id) }
+ let_it_be(:diffs) { commit.raw_diffs }
+ let_it_be(:diff) { diffs.first }
+ let_it_be(:diff_refs) { commit.diff_refs }
+ let_it_be(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) }
+ let_it_be(:diff_files) { [diff_file] }
+
+ describe "rendered component" do
+ subject { rendered_component }
+
+ let(:element) { page.find(".js-diff-stats-dropdown") }
+
+ before do
+ render_inline component
+ end
+
+ it { is_expected.to have_selector(".js-diff-stats-dropdown") }
+
+ it "renders the data attributes" do
+ expect(element["data-changed"]).to eq("1")
+ expect(element["data-added"]).to eq("10")
+ expect(element["data-deleted"]).to eq("3")
+
+ expect(Gitlab::Json.parse(element["data-files"])).to eq([{
+ "href" => "##{Digest::SHA1.hexdigest(diff_file.file_path)}",
+ "title" => diff_file.new_path,
+ "name" => diff_file.file_path,
+ "path" => diff_file.file_path,
+ "icon" => "file-modified",
+ "iconColor" => "",
+ "added" => diff_file.added_lines,
+ "removed" => diff_file.removed_lines
+ }])
+ end
+ end
+
+ describe "#diff_file_path_text" do
+ it "returns full path by default" do
+ expect(subject.diff_file_path_text(diff_file)).to eq(diff_file.new_path)
+ end
+
+ it "returns truncated path" do
+ expect(subject.diff_file_path_text(diff_file, max: 10)).to eq("...open.rb")
+ end
+
+ it "returns the path if max is oddly small" do
+ expect(subject.diff_file_path_text(diff_file, max: 3)).to eq(diff_file.new_path)
+ end
+
+ it "returns the path if max is oddly large" do
+ expect(subject.diff_file_path_text(diff_file, max: 100)).to eq(diff_file.new_path)
+ end
+ end
+end
diff --git a/spec/components/pajamas/alert_component_spec.rb b/spec/components/pajamas/alert_component_spec.rb
new file mode 100644
index 00000000000..628d715ff64
--- /dev/null
+++ b/spec/components/pajamas/alert_component_spec.rb
@@ -0,0 +1,104 @@
+# frozen_string_literal: true
+require "spec_helper"
+
+RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
+ context 'with content' do
+ before do
+ render_inline(described_class.new) { '_content_' }
+ end
+
+ it 'has content' do
+ expect(rendered_component).to have_text('_content_')
+ end
+ end
+
+ context 'with defaults' do
+ before do
+ render_inline described_class.new
+ end
+
+ it 'does not set a title' do
+ expect(rendered_component).not_to have_selector('.gl-alert-title')
+ expect(rendered_component).to have_selector('.gl-alert-icon-no-title')
+ end
+
+ it 'renders the default variant' do
+ expect(rendered_component).to have_selector('.gl-alert-info')
+ expect(rendered_component).to have_selector("[data-testid='information-o-icon']")
+ end
+
+ it 'renders a dismiss button' do
+ expect(rendered_component).to have_selector('.gl-dismiss-btn.js-close')
+ expect(rendered_component).to have_selector("[data-testid='close-icon']")
+ end
+ end
+
+ context 'with custom options' do
+ context 'with simple options' do
+ context 'without dismissible content' do
+ before do
+ render_inline described_class.new(
+ title: '_title_',
+ dismissible: false,
+ alert_class: '_alert_class_',
+ alert_data: {
+ feature_id: '_feature_id_',
+ dismiss_endpoint: '_dismiss_endpoint_'
+ }
+ )
+ end
+
+ it 'sets the title' do
+ expect(rendered_component).to have_selector('.gl-alert-title')
+ expect(rendered_component).to have_content('_title_')
+ expect(rendered_component).not_to have_selector('.gl-alert-icon-no-title')
+ end
+
+ it 'sets to not be dismissible' do
+ expect(rendered_component).not_to have_selector('.gl-dismiss-btn.js-close')
+ expect(rendered_component).not_to have_selector("[data-testid='close-icon']")
+ end
+
+ it 'sets the alert_class' do
+ expect(rendered_component).to have_selector('._alert_class_')
+ end
+
+ it 'sets the alert_data' do
+ expect(rendered_component).to have_selector('[data-feature-id="_feature_id_"][data-dismiss-endpoint="_dismiss_endpoint_"]')
+ end
+ end
+ end
+
+ context 'with dismissible content' do
+ before do
+ render_inline described_class.new(
+ close_button_class: '_close_button_class_',
+ close_button_data: {
+ testid: '_close_button_testid_'
+ }
+ )
+ end
+
+ it 'renders a dismiss button and data' do
+ expect(rendered_component).to have_selector('.gl-dismiss-btn.js-close._close_button_class_')
+ expect(rendered_component).to have_selector("[data-testid='close-icon']")
+ expect(rendered_component).to have_selector('[data-testid="_close_button_testid_"]')
+ end
+ end
+
+ context 'with setting variant type' do
+ where(:variant) { [:warning, :success, :danger, :tip] }
+
+ before do
+ render_inline described_class.new(variant: variant)
+ end
+
+ with_them do
+ it 'renders the variant' do
+ expect(rendered_component).to have_selector(".gl-alert-#{variant}")
+ expect(rendered_component).to have_selector("[data-testid='#{described_class::ICONS[variant]}-icon']")
+ end
+ end
+ end
+ end
+end