<commit_before>require 'rails_helper'
include AsyncHelper

feature 'Add Class', js: true do
  include_context "profile"



  before :each do
    vcr_ignores_localhost
    sign_in_user student
    visit('/students_classrooms/add_classroom')
  end

  describe 'the Add Class page'

  it 'provides a field to enter a classcode' do
    eventually { expect(page).to have_selector("input") }
  end

  context 'upon submission' do



    context 'if the code is valid' do

    before :each do
      page.find(".class-input").set(classroom3.code)
      click_button('Join Your Class')
    end

      # it 'it successfully adds a student to a classroom' do
      #   # page.find(".class-input").set(classroom3.code)
      #   # click_button('Join Your Class')
      #   # this works IRL, not sure why it is failing
      #   # eventually { expect(student.students_classrooms).to include(classroom3)}
      # end

      it 'tells the student they succesfully joined a classroom' do
        eventually { expect(page).to have_content("Classroom Added")}
      end

      it 'creates an add student checkbox for the teacher' do
        add_students = Objective.create(name: 'Add Students')
        eventually {expect(classroom3.teacher.checkboxes.last.objective).to eq(add_students)}
      end

    end

    context 'if it the code is not valid' do

      it 'displays an error message' do
        page.find(".class-input").set('not-a-class')
        click_button('Join Your Class')
        eventually {expect(page).to have_content("Invalid Classcode")}
      end

    end

  end






<commit_msg>Added and modified tests for displaying class code errors<commit_after>require 'rails_helper'
include AsyncHelper

feature 'Add Class', js: true do
  include_context "profile"



  before :each do
    vcr_ignores_localhost
    sign_in_user student
    visit('/students_classrooms/add_classroom')
  end

  describe 'the Add Class page'

  it 'provides a field to enter a classcode' do
    eventually { expect(page).to have_selector("input") }
  end

  context 'upon submission' do



    context 'if the code is valid' do

    before :each do
      page.find(".class-input").set(classroom3.code)
      click_button('Join Your Class')
    end

      # it 'it successfully adds a student to a classroom' do
      #   # page.find(".class-input").set(classroom3.code)
      #   # click_button('Join Your Class')
      #   # this works IRL, not sure why it is failing
      #   # eventually { expect(student.students_classrooms).to include(classroom3)}
      # end

      it 'tells the student they succesfully joined a classroom' do
        eventually { expect(page).to have_content("Classroom Added")}
      end

      it 'creates an add student checkbox for the teacher' do
        add_students = Objective.create(name: 'Add Students')
        eventually {expect(classroom3.teacher.checkboxes.last.objective).to eq(add_students)}
      end

    end

    context 'if the code is not valid' do

      it 'displays the standard error message' do
        page.find(".class-input").set('not-a-class')
        click_button('Join Your Class')
        eventually {expect(page).to have_content("Oops! Looks like that isn't a valid class code. Please try again.")}
      end

      it 'displays the archived class error message' do
        c = Classroom.new
        c.code = 'archived-class'
        c.name = 'Archived Class'
        c.visible = false
        c.save
        page.find(".class-input").set('archived-class')
        click_button('Join Your Class')
        eventually {expect(page).to have_content("Oops! That class has been archived. Please try a different class code.")}
      end

    end

  end







{'fraction_non_alphanumeric': 0.09401246274722297, 'fraction_numerical': 0.002167434299647792, 'mean_word_length': 2.8022657054582902, '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': '4139698', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1060, 'n_words': 343}