<commit_before>require 'rails_helper'

describe 'dashboard', type: :feature, js: true do
  let(:user) { create(:user, onboarded: true, real_name: 'test', email: '<EMAIL>', permissions: permissions) }

  before do
    create(:cohort)
  end

  describe 'empty state' do

    describe 'for students' do
      let(:permissions) { User::Permissions::NONE }

      before :each do
        login_as(user, scope: :user)
      end

      it 'should describe joining a course' do
        visit root_path
        expect(page).to have_content 'Once you receive a passcode'
      end
    end

    describe 'for instructors' do
      let(:permissions) { User::Permissions::INSTRUCTOR }

      before :each do
        login_as(user, scope: :user)
      end

      it 'should link to orientation' do
        visit root_path
        expect(page).to have_content 'Before you create a course, let\'s go through orientation'
      end

      it 'should allow creating a course if they\'ve completed orientation' do
        tmu = create(:training_modules_users, user_id: user.id, training_module_id: 3, completed_at: Time.now)
        visit root_path
        expect(page).to have_content 'Click on Create Course to create your first course'
      end

    end

  end

  describe 'populated' do

    describe 'for instructors' do

      let(:permissions) { User::Permissions::INSTRUCTOR }

      before :each do
        login_as(user, scope: :user)
      end

      it 'should allow creating a course if they haven\'t completed orientation but they already have a course' do
        create(:course,
             id: 10001,
             title: 'Course',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: 0,
             listed: true,
             passcode: '<PASSWORD>',
             start: '2015-08-24'.to_date,
             end: '2015-12-15'.to_date,
             timeline_start: '2015-08-31'.to_date,
             timeline_end: '2015-12-15'.to_date)
        create(:courses_user,
             user_id: user.id,
             course_id: 10001,
             role: 1)
        visit root_path
        expect(page).to have_content 'Create Course'
      end

    end

  end

  describe 'archived course' do
    let(:permissions) { User::Permissions::INSTRUCTOR }

    before :each do
      login_as(user, scope: :user)
    end

    it 'should initially not show archived' do
      visit root_path
      expect(page).not_to have_content 'Archived Courses'
    end

    it 'should show archived' do
      create(:course,
             id: 10001,
             title: 'Archived Title',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: 0,
             listed: true,
             passcode: 'passcode',
             start: '2010-08-24'.to_date,
             end: '2011-12-15'.to_date,
             timeline_start: '2010-08-31'.to_date,
             timeline_end: '2011-12-15'.to_date)
      create(:courses_user,
             user_id: user.id,
             course_id: 10001,
             role: 1)
      visit root_path
      expect(page).to have_content 'Archived Courses'
      expect(page).to have_content 'Archived Title'
    end

    it 'should show both archived and non-archived' do<commit_msg>Improve test names<commit_after>require 'rails_helper'

describe 'dashboard', type: :feature, js: true do
  let(:user) { create(:user, onboarded: true, real_name: 'test', email: '<EMAIL>', permissions: permissions) }

  before do
    create(:cohort)
  end

  describe 'empty state' do

    describe 'for students' do
      let(:permissions) { User::Permissions::NONE }

      before :each do
        login_as(user, scope: :user)
      end

      it 'should describe joining a course' do
        visit root_path
        expect(page).to have_content 'Once you receive a passcode'
      end
    end

    describe 'for instructors' do
      let(:permissions) { User::Permissions::INSTRUCTOR }

      before :each do
        login_as(user, scope: :user)
      end

      it 'should link to orientation' do
        visit root_path
        expect(page).to have_content 'Before you create a course, let\'s go through orientation'
      end

      it 'should allow creating a course if they\'ve completed orientation' do
        tmu = create(:training_modules_users, user_id: user.id, training_module_id: 3, completed_at: Time.now)
        visit root_path
        expect(page).to have_content 'Click on Create Course to create your first course'
      end

    end

  end

  describe 'populated' do

    describe 'for instructors' do

      let(:permissions) { User::Permissions::INSTRUCTOR }

      before :each do
        login_as(user, scope: :user)
      end

      it 'should allow creating a course if they haven\'t completed orientation but they already have a course' do
        create(:course,
             id: 10001,
             title: 'Course',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: 0,
             listed: true,
             passcode: '<PASSWORD>',
             start: '2015-08-24'.to_date,
             end: '2015-12-15'.to_date,
             timeline_start: '2015-08-31'.to_date,
             timeline_end: '2015-12-15'.to_date)
        create(:courses_user,
             user_id: user.id,
             course_id: 10001,
             role: 1)
        visit root_path
        expect(page).to have_content 'Create Course'
      end

    end

  end

  describe 'archived course' do
    let(:permissions) { User::Permissions::INSTRUCTOR }

    before :each do
      login_as(user, scope: :user)
    end

    it 'should not initially show archived' do
      visit root_path
      expect(page).not_to have_content 'Archived Courses'
    end

    it 'should show archived courses when there are archived courses' do
      create(:course,
             id: 10001,
             title: 'Archived Title',
             school: 'University',
             term: 'Term',
             slug: 'University/Course_(Term)',
             submitted: 0,
             listed: true,
             passcode: '<PASSWORD>',
             start: '2010-08-24'.to_date,
             end: '2011-12-15'.to_date,
             timeline_start: '2010-08-31'.to_date,
             timeline_end: '2011-12-15'.to_date)
      create(:courses_user,
             user_id: user.id,
             course_id: 10001,
             role: 1)
      visit root_path
      expect(page).to have_content 'Archived Courses'
      expect(page).to have_content 'Archived Title'
    end

    it 'should show both archived and non-archived' do
{'fraction_non_alphanumeric': 0.09566383549396514, 'fraction_numerical': 0.026523617940694383, 'mean_word_length': 2.0718535469107553, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '3080319', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1917, 'n_words': 577}