<commit_before>require 'rails_helper'

feature 'Admin legislation draft versions' do

  background do
    admin = create(:administrator)
    login_as(admin.user)
  end

  context "Feature flag" do

    scenario 'Disabled with a feature flag' do
      Setting['feature.legislation'] = nil
      process = create(:legislation_process)
      expect{ visit admin_legislation_process_draft_versions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled)
    end

  end

  context "Index" do

    scenario 'Displaying legislation process draft versions' do
      process = create(:legislation_process, title: 'An example legislation process')
      draft_version = create(:legislation_draft_version, process: process, title: 'Version 1')

      visit admin_legislation_processes_path(filter: 'all')

      click_link 'An example legislation process'
      click_link 'Text'
      click_link 'Version 1'

      expect(page).to have_content(draft_version.title)
      expect(page).to have_content(draft_version.changelog)
    end
  end

  context 'Create' do
    scenario 'Valid legislation draft version' do
      process = create(:legislation_process, title: 'An example legislation process')

      visit admin_root_path

      within('#side_menu') do
        click_link "Collaborative Legislation"
      end

      click_link "All"

      expect(page).to have_content 'An example legislation process'

      click_link 'An example legislation process'
      click_link 'Text'

      click_link 'Create version'

      fill_in 'legislation_draft_version_title', with: 'Version 3'
      fill_in 'legislation_draft_version_changelog', with: 'Version 3 changes'
      fill_in 'legislation_draft_version_body', with: 'Version 3 body'

      within('.primary-buttons') do
        click_button 'Create version'
      end

      expect(page).to have_content 'An example legislation process'
      expect(page).to have_content 'Version 3'
    end
  end

  context 'Update' do
    scenario 'Valid legislation draft version', :js do
      process = create(:legislation_process, title: 'An example legislation process')
      draft_version = create(:legislation_draft_version, title: 'Version 1', process: process)

      visit admin_root_path

      within('#side_menu') do
        click_link "Collaborative Legislation"
      end

      click_link "All"

      expect(page).to have_content 'An example legislation process'

      click_link 'An example legislation process'
      click_link 'Text'

      click_link 'Version 1'

      fill_in 'legislation_draft_version_title', with: 'Version 1b'

      click_link 'Launch text editor'

      fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote'

      within('.fullscreen') do
        click_link 'Close text editor'
      end

      click_button 'Save changes'<commit_msg>Updates texts on admin legislation specs<commit_after>require 'rails_helper'

feature 'Admin legislation draft versions' do

  background do
    admin = create(:administrator)
    login_as(admin.user)
  end

  context "Feature flag" do

    scenario 'Disabled with a feature flag' do
      Setting['feature.legislation'] = nil
      process = create(:legislation_process)
      expect{ visit admin_legislation_process_draft_versions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled)
    end

  end

  context "Index" do

    scenario 'Displaying legislation process draft versions' do
      process = create(:legislation_process, title: 'An example legislation process')
      draft_version = create(:legislation_draft_version, process: process, title: 'Version 1')

      visit admin_legislation_processes_path(filter: 'all')

      click_link 'An example legislation process'
      click_link 'Drafting'
      click_link 'Version 1'

      expect(page).to have_content(draft_version.title)
      expect(page).to have_content(draft_version.changelog)
    end
  end

  context 'Create' do
    scenario 'Valid legislation draft version' do
      process = create(:legislation_process, title: 'An example legislation process')

      visit admin_root_path

      within('#side_menu') do
        click_link "Collaborative Legislation"
      end

      click_link "All"

      expect(page).to have_content 'An example legislation process'

      click_link 'An example legislation process'
      click_link 'Drafting'

      click_link 'Create version'

      fill_in 'legislation_draft_version_title', with: 'Version 3'
      fill_in 'legislation_draft_version_changelog', with: 'Version 3 changes'
      fill_in 'legislation_draft_version_body', with: 'Version 3 body'

      within('.primary-buttons') do
        click_button 'Create version'
      end

      expect(page).to have_content 'An example legislation process'
      expect(page).to have_content 'Version 3'
    end
  end

  context 'Update' do
    scenario 'Valid legislation draft version', :js do
      process = create(:legislation_process, title: 'An example legislation process')
      draft_version = create(:legislation_draft_version, title: 'Version 1', process: process)

      visit admin_root_path

      within('#side_menu') do
        click_link "Collaborative Legislation"
      end

      click_link "All"

      expect(page).to have_content 'An example legislation process'

      click_link 'An example legislation process'
      click_link 'Drafting'

      click_link 'Version 1'

      fill_in 'legislation_draft_version_title', with: 'Version 1b'

      click_link 'Launch text editor'

      fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote'

      within('.fullscreen') do
        click_link 'Close text editor'
      end

      click_button 'Save changes'
{'fraction_non_alphanumeric': 0.07869648119258103, 'fraction_numerical': 0.003466805338880222, 'mean_word_length': 3.5078125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6536885', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1604, 'n_words': 466}