<commit_before># frozen_string_literal: true
require 'rails_helper'

RSpec.feature 'Course: Administration: Components' do
  let!(:instance) do
    create(:instance, :with_video_component_enabled)
  end

  with_tenant(:instance) do
    let(:course) do
      create(:course, :with_video_component_enabled)
    end
    let(:components) { course.disableable_components }
    let(:sample_component_id) do
      "settings_components_enabled_component_ids_#{components.sample.key}"
    end
    before { login_as(user, scope: :user) }

    context 'As a Course Manager' do
      let(:user) { create(:course_manager, course: course).user }

      scenario 'I can view the list of enabled/disabled components' do
        visit course_admin_components_path(course)

        components.each do |component|
          expect(page).to have_selector('th', text: component.display_name)
          enabled = course.enabled_components.include?(component)
          checkbox = find("#settings_components_enabled_component_ids_#{component.key}")
          if enabled
            expect(checkbox).to be_checked
          else
            expect(checkbox).not_to be_checked
          end
        end
      end

      scenario 'I can enable a component' do
        visit course_admin_components_path(course)

        check(sample_component_id)
        click_button I18n.t('course.admin.component_settings.edit.button')
        expect(page).to have_checked_field(sample_component_id)
      end

      scenario 'I can disable a component' do
        visit course_admin_components_path(course)

        uncheck(sample_component_id)
        click_button I18n.t('course.admin.component_settings.edit.button')
        expect(page).to have_unchecked_field(sample_component_id)<commit_msg>test(component_settings): adapt to new ui<commit_after># frozen_string_literal: true
require 'rails_helper'

RSpec.feature 'Course: Administration: Components', js: true do
  let!(:instance) do
    create(:instance, :with_video_component_enabled)
  end

  with_tenant(:instance) do
    let(:course) { create(:course, :with_video_component_enabled) }
    let(:components) { course.disableable_components }
    let(:sample_component) { components.sample }
    before { login_as(user, scope: :user) }

    context 'As a Course Manager' do
      let(:user) { create(:course_manager, course: course).user }

      scenario 'I can view the list of enabled/disabled components' do
        visit course_admin_components_path(course)

        enabled_components = course.enabled_components
        components.each do |component|
          expect(page).to have_selector('label', text: component.display_name)
          option = find('label', text: component.display_name).find('input', visible: false)
          expect(option.checked?).to be(enabled_components.include?(component))
        end
      end

      scenario 'I can disable and enable a component' do
        visit course_admin_components_path(course)

        control = find('label', text: sample_component.display_name)
        control.click
        expect_toastify('Your changes have been saved. Refresh to see the new changes.')

        option = control.find('input', visible: false)
        expect(option).not_to be_checked

        control.click
        expect_toastify('Your changes have been saved. Refresh to see the new changes.')

        expect(option).to be_checked
{'fraction_non_alphanumeric': 0.09002361275088548, 'fraction_numerical': 0.0011806375442739079, 'mean_word_length': 3.44750656167979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1366686', 'n_tokens_mistral': 939, 'n_tokens_neox': 924, 'n_words': 225}