<commit_before># frozen_string_literal: true

require 'rails_helper'

describe 'interacting with forms/drafts from the index', js: true do
  context 'not staff' do
    it 'does not allow access' do
      login_as(create :user, :not_staff)
      visit '/forms'
      warning = 'You do not have permission to access this page'
      expect(page).to have_css 'h1', text: warning
    end
  end
  context 'staff' do
    before :each do
      @user = create :user, :staff
      @form = create :form, :with_fields
      @draft = create :form_draft, user: @user
      login_as(@user)
      visit '/forms'
    end
    context 'clicking the delete button' do
      it 'destroys drafts' do
        expect(page).to have_text @draft.name
        within('#form_drafts_table') do
          click_link 'Delete'
        end
        page.driver.browser.switch_to.alert.accept
        expect(page).not_to have_text @draft.name
        expect(FormDraft.count).to eql 0
        within('#flash') do
          expect(page).to have_text 'Draft has been discarded'
        end
      end
      it 'destroys forms' do
        expect(page).to have_text @form.name
        within('#forms_table') do
          click_link 'Delete'
        end
        page.driver.browser.switch_to.alert.accept
        expect(page).not_to have_text @form.name
        expect(Form.count).to eql 0
        within('#flash') do
          expect(page).to have_text 'Form successfully deleted'<commit_msg>actually grab the correct dom elements<commit_after># frozen_string_literal: true

require 'rails_helper'

describe 'interacting with forms/drafts from the index', js: true do
  context 'not staff' do
    it 'does not allow access' do
      login_as(create :user, :not_staff)
      visit '/forms'
      warning = 'You do not have permission to access this page'
      expect(page).to have_css 'h1', text: warning
    end
  end
  context 'staff' do
    before :each do
      @user = create :user, :staff
      @form = create :form, :with_fields
      @draft = create :form_draft, user: @user
      login_as(@user)
      visit '/forms'
    end
    context 'clicking the delete button' do
      it 'destroys drafts' do
        expect(page).to have_text @draft.name
        within('#form-drafts-table') do
          click_link 'Delete'
        end
        page.driver.browser.switch_to.alert.accept
        expect(page).not_to have_text @draft.name
        expect(FormDraft.count).to eql 0
        within('#flash') do
          expect(page).to have_text 'Draft has been discarded'
        end
      end
      it 'destroys forms' do
        expect(page).to have_text @form.name
        within('#forms-table') do
          click_link 'Delete'
        end
        page.driver.browser.switch_to.alert.accept
        expect(page).not_to have_text @form.name
        expect(Form.count).to eql 0
        within('#flash') do
          expect(page).to have_text 'Form successfully deleted'
{'fraction_non_alphanumeric': 0.09463614622480356, 'fraction_numerical': 0.0020498804236419544, 'mean_word_length': 2.4325908558030482, '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': '3374545', 'n_tokens_mistral': 883, 'n_tokens_neox': 865, 'n_words': 266}