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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-03-16 03:07:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-03-16 03:07:19 +0300
commit3d7409c5d5c471fb95990200f7f78965dd2f42cf (patch)
tree9ee3fdd8af7e6b88a2a076f6d71851dec4938d30 /spec
parent512177dcc7369c6c3f4ae54cc8a0abcb73828f71 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/components/pajamas/component_spec.rb26
-rw-r--r--spec/components/pajamas/toggle_component_spec.rb107
-rw-r--r--spec/frontend/sidebar/components/incidents/sidebar_escalation_status_spec.js13
-rw-r--r--spec/support/view_component.rb7
-rw-r--r--spec/tooling/quality/test_level_spec.rb4
-rw-r--r--spec/views/shared/_gl_toggle.haml_spec.rb85
6 files changed, 151 insertions, 91 deletions
diff --git a/spec/components/pajamas/component_spec.rb b/spec/components/pajamas/component_spec.rb
new file mode 100644
index 00000000000..96f6b43bac1
--- /dev/null
+++ b/spec/components/pajamas/component_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe Pajamas::Component do
+ describe '#filter_attribute' do
+ let(:allowed) { %w[default something] }
+
+ it 'returns default value when no value is given' do
+ value = subject.send(:filter_attribute, nil, allowed, default: 'default')
+
+ expect(value).to eq('default')
+ end
+
+ it 'returns default value when invalid value is given' do
+ value = subject.send(:filter_attribute, 'invalid', allowed, default: 'default')
+
+ expect(value).to eq('default')
+ end
+
+ it 'returns given value when it is part of allowed list' do
+ value = subject.send(:filter_attribute, 'something', allowed, default: 'default')
+
+ expect(value).to eq('something')
+ end
+ end
+end
diff --git a/spec/components/pajamas/toggle_component_spec.rb b/spec/components/pajamas/toggle_component_spec.rb
new file mode 100644
index 00000000000..b2727dec318
--- /dev/null
+++ b/spec/components/pajamas/toggle_component_spec.rb
@@ -0,0 +1,107 @@
+# frozen_string_literal: true
+require "spec_helper"
+
+RSpec.describe Pajamas::ToggleComponent, type: :component do
+ context 'with defaults' do
+ before do
+ render_inline described_class.new(classes: 'js-feature-toggle')
+ end
+
+ it 'renders a toggle container with provided class' do
+ expect(rendered_component).to have_selector "[class='js-feature-toggle']"
+ end
+
+ it 'does not set a name' do
+ expect(rendered_component).not_to have_selector('[data-name]')
+ end
+
+ it 'sets default is-checked attributes' do
+ expect(rendered_component).to have_selector('[data-is-checked="false"]')
+ end
+
+ it 'sets default disabled attributes' do
+ expect(rendered_component).to have_selector('[data-disabled="false"]')
+ end
+
+ it 'sets default is-loading attributes' do
+ expect(rendered_component).to have_selector('[data-is-loading="false"]')
+ end
+
+ it 'does not set a label' do
+ expect(rendered_component).not_to have_selector('[data-label]')
+ end
+
+ it 'does not set a label position' do
+ expect(rendered_component).not_to have_selector('[data-label-position]')
+ end
+ end
+
+ context 'with custom options' do
+ before do
+ render_inline described_class.new(
+ classes: 'js-custom-gl-toggle',
+ name: 'toggle-name',
+ is_checked: true,
+ is_disabled: true,
+ is_loading: true,
+ label: 'Custom label',
+ label_position: :top,
+ data: {
+ foo: 'bar'
+ })
+ end
+
+ it 'sets the custom class' do
+ expect(rendered_component).to have_selector('.js-custom-gl-toggle')
+ end
+
+ it 'sets the custom name' do
+ expect(rendered_component).to have_selector('[data-name="toggle-name"]')
+ end
+
+ it 'sets the custom is-checked attributes' do
+ expect(rendered_component).to have_selector('[data-is-checked="true"]')
+ end
+
+ it 'sets the custom disabled attributes' do
+ expect(rendered_component).to have_selector('[data-disabled="true"]')
+ end
+
+ it 'sets the custom is-loading attributes' do
+ expect(rendered_component).to have_selector('[data-is-loading="true"]')
+ end
+
+ it 'sets the custom label' do
+ expect(rendered_component).to have_selector('[data-label="Custom label"]')
+ end
+
+ it 'sets the custom label position' do
+ expect(rendered_component).to have_selector('[data-label-position="top"]')
+ end
+
+ it 'sets custom data attributes' do
+ expect(rendered_component).to have_selector('[data-foo="bar"]')
+ end
+ end
+
+ context 'with setting label_position' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:position, :count) do
+ :top | 1
+ :left | 1
+ :hidden | 1
+ :bogus | 0
+ 'bogus' | 0
+ nil | 0
+ end
+
+ before do
+ render_inline described_class.new(classes: '_class_', label_position: position)
+ end
+
+ with_them do
+ it { expect(rendered_component).to have_selector("[data-label-position='#{position}']", count: count) }
+ end
+ end
+end
diff --git a/spec/frontend/sidebar/components/incidents/sidebar_escalation_status_spec.js b/spec/frontend/sidebar/components/incidents/sidebar_escalation_status_spec.js
index 6173088b247..a8dc610672c 100644
--- a/spec/frontend/sidebar/components/incidents/sidebar_escalation_status_spec.js
+++ b/spec/frontend/sidebar/components/incidents/sidebar_escalation_status_spec.js
@@ -153,7 +153,7 @@ describe('SidebarEscalationStatus', () => {
await selectAcknowledgedStatus();
});
- it('calls the mutation', async () => {
+ it('calls the mutation', () => {
const mutationVariables = {
iid: '1',
projectPath: 'gitlab-org/gitlab',
@@ -163,12 +163,17 @@ describe('SidebarEscalationStatus', () => {
expect(mutationResolverMock).toHaveBeenCalledWith(mutationVariables);
});
- it('closes the dropdown', async () => {
+ it('closes the dropdown', () => {
expect(findStatusComponent().isVisible()).toBe(false);
});
- it('updates the status', async () => {
- expect(findStatusComponent().attributes('value')).toBe(STATUS_ACKNOWLEDGED);
+ it('updates the status', () => {
+ // Sometimes status has a intermediate wrapping component. A quirk of vue-test-utils
+ // means that in that case 'value' is exposed as a prop. If no wrapping component
+ // exists it is exposed as an attribute.
+ const statusValue =
+ findStatusComponent().props('value') || findStatusComponent().attributes('value');
+ expect(statusValue).toBe(STATUS_ACKNOWLEDGED);
});
});
diff --git a/spec/support/view_component.rb b/spec/support/view_component.rb
new file mode 100644
index 00000000000..9166a06fc8c
--- /dev/null
+++ b/spec/support/view_component.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+require 'view_component/test_helpers'
+
+RSpec.configure do |config|
+ config.include ViewComponent::TestHelpers, type: :component
+ config.include Capybara::RSpecMatchers, type: :component
+end
diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb
index 33d3a5b49b3..c72e90dc713 100644
--- a/spec/tooling/quality/test_level_spec.rb
+++ b/spec/tooling/quality/test_level_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Quality::TestLevel do
context 'when level is unit' do
it 'returns a pattern' do
expect(subject.pattern(:unit))
- .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,events,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling}{,/**/}*_spec.rb")
+ .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,events,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,component}{,/**/}*_spec.rb")
end
end
@@ -110,7 +110,7 @@ RSpec.describe Quality::TestLevel do
context 'when level is unit' do
it 'returns a regexp' do
expect(subject.regexp(:unit))
- .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|events|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling)})
+ .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|events|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|component)})
end
end
diff --git a/spec/views/shared/_gl_toggle.haml_spec.rb b/spec/views/shared/_gl_toggle.haml_spec.rb
deleted file mode 100644
index 3ac1ef30c84..00000000000
--- a/spec/views/shared/_gl_toggle.haml_spec.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-# frozen_string_literal: true
-require 'spec_helper'
-
-RSpec.describe 'shared/_gl_toggle.html.haml' do
- context 'defaults' do
- before do
- render partial: 'shared/gl_toggle', locals: {
- classes: '.js-gl-toggle'
- }
- end
-
- it 'does not set a name' do
- expect(rendered).not_to have_selector('[data-name]')
- end
-
- it 'sets default is-checked attributes' do
- expect(rendered).to have_selector('[data-is-checked="false"]')
- end
-
- it 'sets default disabled attributes' do
- expect(rendered).to have_selector('[data-disabled="false"]')
- end
-
- it 'sets default is-loading attributes' do
- expect(rendered).to have_selector('[data-is-loading="false"]')
- end
-
- it 'does not set a label' do
- expect(rendered).not_to have_selector('[data-label]')
- end
-
- it 'does not set a label position' do
- expect(rendered).not_to have_selector('[data-label-position]')
- end
- end
-
- context 'with custom options' do
- before do
- render partial: 'shared/gl_toggle', locals: {
- classes: 'js-custom-gl-toggle',
- name: 'toggle-name',
- is_checked: true,
- disabled: true,
- is_loading: true,
- label: 'Custom label',
- label_position: 'top',
- data: {
- foo: 'bar'
- }
- }
- end
-
- it 'sets the custom class' do
- expect(rendered).to have_selector('.js-custom-gl-toggle')
- end
-
- it 'sets the custom name' do
- expect(rendered).to have_selector('[data-name="toggle-name"]')
- end
-
- it 'sets the custom is-checked attributes' do
- expect(rendered).to have_selector('[data-is-checked="true"]')
- end
-
- it 'sets the custom disabled attributes' do
- expect(rendered).to have_selector('[data-disabled="true"]')
- end
-
- it 'sets the custom is-loading attributes' do
- expect(rendered).to have_selector('[data-is-loading="true"]')
- end
-
- it 'sets the custom label' do
- expect(rendered).to have_selector('[data-label="Custom label"]')
- end
-
- it 'sets the cutom label position' do
- expect(rendered).to have_selector('[data-label-position="top"]')
- end
-
- it 'sets cutom data attributes' do
- expect(rendered).to have_selector('[data-foo="bar"]')
- end
- end
-end