debian-mirror-gitlab/spec/components/pajamas/toggle_component_spec.rb

108 lines
2.8 KiB
Ruby
Raw Normal View History

2022-05-07 20:08:51 +05:30
# 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
2022-08-13 15:12:31 +05:30
expect(page).to have_selector "[class='js-feature-toggle']"
2022-05-07 20:08:51 +05:30
end
it 'does not set a name' do
2022-08-13 15:12:31 +05:30
expect(page).not_to have_selector('[data-name]')
2022-05-07 20:08:51 +05:30
end
it 'sets default is-checked attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-is-checked="false"]')
2022-05-07 20:08:51 +05:30
end
it 'sets default disabled attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-disabled="false"]')
2022-05-07 20:08:51 +05:30
end
it 'sets default is-loading attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-is-loading="false"]')
2022-05-07 20:08:51 +05:30
end
it 'does not set a label' do
2022-08-13 15:12:31 +05:30
expect(page).not_to have_selector('[data-label]')
2022-05-07 20:08:51 +05:30
end
it 'does not set a label position' do
2022-08-13 15:12:31 +05:30
expect(page).not_to have_selector('[data-label-position]')
2022-05-07 20:08:51 +05:30
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
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('.js-custom-gl-toggle')
2022-05-07 20:08:51 +05:30
end
it 'sets the custom name' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-name="toggle-name"]')
2022-05-07 20:08:51 +05:30
end
it 'sets the custom is-checked attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-is-checked="true"]')
2022-05-07 20:08:51 +05:30
end
it 'sets the custom disabled attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-disabled="true"]')
2022-05-07 20:08:51 +05:30
end
it 'sets the custom is-loading attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-is-loading="true"]')
2022-05-07 20:08:51 +05:30
end
it 'sets the custom label' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-label="Custom label"]')
2022-05-07 20:08:51 +05:30
end
it 'sets the custom label position' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-label-position="top"]')
2022-05-07 20:08:51 +05:30
end
it 'sets custom data attributes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_selector('[data-foo="bar"]')
2022-05-07 20:08:51 +05:30
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
2022-08-13 15:12:31 +05:30
it { expect(page).to have_selector("[data-label-position='#{position}']", count: count) }
2022-05-07 20:08:51 +05:30
end
end
end