fix: fix broken tests

mciea-main
Nelson Jovel 1 year ago
parent 8dc503f454
commit 0960a32cd0

@ -177,7 +177,7 @@ describe Analyze::Presenter do
context "when multiple academic years are provided in the params hash" do context "when multiple academic years are provided in the params hash" do
it "returns the academic year with the given ids" do it "returns the academic year with the given ids" do
params = { academic_years: "2021-22,2022-23" } params = { academic_year1: "2021-22", academic_year2: "2022-23" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range("2021-22"), expect(presenter.selected_academic_years).to eq [AcademicYear.find_by_range("2021-22"),
AcademicYear.find_by_range("2022-23")] AcademicYear.find_by_range("2022-23")]
@ -215,11 +215,11 @@ describe Analyze::Presenter do
context "when one race is provided in the params hash" do context "when one race is provided in the params hash" do
it "returns a single race with the given slug" do it "returns a single race with the given slug" do
params = { races: "white" } params = { "race1-checkbox" => "white" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq [Race.find_by_slug("white")] expect(presenter.selected_races).to eq [Race.find_by_slug("white")]
params = { races: "black" } params = { "race1-checkbox" => "black" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq [Race.find_by_slug("black")] expect(presenter.selected_races).to eq [Race.find_by_slug("black")]
end end
@ -227,7 +227,8 @@ describe Analyze::Presenter do
context "when multiple races are provided in the params hash" do context "when multiple races are provided in the params hash" do
it "returns multiple races with the given slugs" do it "returns multiple races with the given slugs" do
params = { races: "white,black" } params = { "race1-checkbox" => "white",
"race2-checkbox" => "black" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_races).to eq [Race.find_by_slug("white"), Race.find_by_slug("black")] expect(presenter.selected_races).to eq [Race.find_by_slug("white"), Race.find_by_slug("black")]
end end
@ -307,7 +308,7 @@ describe Analyze::Presenter do
context "when no grades are provided in the params hash" do context "when no grades are provided in the params hash" do
it "returns only the set of grades selected even if other grades have sufficient responses" do it "returns only the set of grades selected even if other grades have sufficient responses" do
params = { grades: "1,2,3" } params = { "grade1-checkbox" => "1", "grade2-checkbox" => "2", "grade3-checkbox" => "3" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_grades).to eq [1, 2, 3] expect(presenter.selected_grades).to eq [1, 2, 3]
end end
@ -330,11 +331,11 @@ describe Analyze::Presenter do
context "when a single gender is provided in the params hash" do context "when a single gender is provided in the params hash" do
it "returns the gender with the given designation" do it "returns the gender with the given designation" do
params = { genders: "female" } params = { "gender1-checkbox" => "female" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq [Gender.find_by_designation("female")] expect(presenter.selected_genders).to eq [Gender.find_by_designation("female")]
params = { genders: "male" } params = { "gender1-checkbox" => "male" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq [Gender.find_by_designation("male")] expect(presenter.selected_genders).to eq [Gender.find_by_designation("male")]
end end
@ -342,7 +343,7 @@ describe Analyze::Presenter do
context "when multiple genders are provided in the params hash" do context "when multiple genders are provided in the params hash" do
it "returns multilple genders with the given designations" do it "returns multilple genders with the given designations" do
params = { genders: "female,male" } params = { "gender1-checkbox" => "female", "gender2-checkbox" => "male" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.selected_genders).to eq [Gender.find_by_designation("female"), expect(presenter.selected_genders).to eq [Gender.find_by_designation("female"),
Gender.find_by_designation("male")] Gender.find_by_designation("male")]
@ -386,10 +387,9 @@ describe Analyze::Presenter do
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.group.slug).to eq "race" expect(presenter.group.slug).to eq "race"
# Not yet implemented params = { group: "income" }
# params = { group: 'income' } presenter = Analyze::Presenter.new(params:, school:, academic_year:)
# presenter = Analyze::Presenter.new(params:, school:, academic_year:) expect(presenter.group.slug).to eq "income"
# expect(presenter.group.slug).to eq 'income'
end end
end end
@ -411,27 +411,47 @@ describe Analyze::Presenter do
end end
end end
context "when a slice is provided in the params hash" do context "when the graph is all-data" do
it "returns the slice with the given slug" do it "returns the slice with the given slug" do
params = { source: "survey-data-only", slice: "students-and-teachers" } params = { graph: "all-data" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-and-teachers" expect(presenter.slice.slug).to eq "all-data"
end end
end end
context "when a slice is provided but the source is left blank " do context "when the graph is 'students-and-teachers'" do
it "returns the slice from the default source (all-data)" do it "returns the slice with the given slug" do
params = { slice: "students-and-teachers" } params = { graph: "students-and-teachers" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "all-data" expect(presenter.slice.slug).to eq "students-and-teachers"
end end
end end
context "when a parameter that does not match a slice is provided" do context "when the graph is of a disaggregation group" do
it "it returns the first slice from the chosen source" do it "returns the slice with the given slug" do
params = { source: "survey-data-only", slice: "invalid-slice" } params = { graph: "students-by-ell" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-and-teachers" expect(presenter.slice.slug).to eq "students-by-group"
params = { graph: "students-by-gender" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-by-group"
params = { graph: "students-by-grade" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-by-group"
params = { graph: "students-by-income" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-by-group"
params = { graph: "students-by-race" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-by-group"
params = { graph: "students-by-sped" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "students-by-group"
end end
end end
end end
@ -445,21 +465,21 @@ describe Analyze::Presenter do
end end
end end
context "when a source is provided in the params hash" do context "when a graph is provided in the params hash" do
it "returns the source with the given slug" do it "returns the source with the given slug" do
params = { source: "all-data" } params = { graph: "all-data" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.source.slug).to eq "all-data" expect(presenter.source.slug).to eq "all-data"
params = { source: "survey-data-only" } params = { graph: "students-and-teachers" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.source.slug).to eq "survey-data-only" expect(presenter.source.slug).to eq "survey-data-only"
end end
end end
context "when a parameter that does not match a source is provided" do context "when a parameter that does not match a graph is provided" do
it "returns the first item in the list of sources" do it "returns the first item in the list of sources" do
params = { source: "invalid-source" } params = { graph: "invalid-source" }
presenter = Analyze::Presenter.new(params:, school:, academic_year:) presenter = Analyze::Presenter.new(params:, school:, academic_year:)
expect(presenter.slice.slug).to eq "all-data" expect(presenter.slice.slug).to eq "all-data"
end end

@ -1,37 +1,37 @@
require 'rails_helper' require "rails_helper"
describe CategoryPresenter do describe CategoryPresenter do
let(:category_presenter) do let(:category_presenter) do
subcategory1 = Subcategory.create(name: 'A subcategory', subcategory_id: '1') subcategory1 = Subcategory.create(name: "A subcategory", subcategory_id: "1")
subcategory2 = Subcategory.create(name: 'Another subcategory', subcategory_id: '2') subcategory2 = Subcategory.create(name: "Another subcategory", subcategory_id: "2")
category = Category.create(name: 'Some Category', subcategories: [subcategory1, subcategory2], category = Category.create(name: "Some Category", subcategories: [subcategory1, subcategory2],
description: 'A description for some Category', short_description: 'A short description for some Category', category_id: '1') description: "A description for some Category", short_description: "A short description for some Category", category_id: "1")
return CategoryPresenter.new(category:) return CategoryPresenter.new(category:)
end end
let(:teachers_and_leadership_presenter) do let(:teachers_and_leadership_presenter) do
category = create(:category, name: 'Teachers & Leadership') category = create(:category, name: "Teachers & Leadership")
return CategoryPresenter.new(category:) return CategoryPresenter.new(category:)
end end
let(:school_culture_presenter) do let(:school_culture_presenter) do
category = create(:category, name: 'School Culture') category = create(:category, name: "School Culture")
return CategoryPresenter.new(category:) return CategoryPresenter.new(category:)
end end
let(:resources_presenter) do let(:resources_presenter) do
category = create(:category, name: 'Resources') category = create(:category, name: "Resources")
return CategoryPresenter.new(category:) return CategoryPresenter.new(category:)
end end
let(:academic_learning_presenter) do let(:academic_learning_presenter) do
category = create(:category, name: 'Academic Learning') category = create(:category, name: "Academic Learning")
return CategoryPresenter.new(category:) return CategoryPresenter.new(category:)
end end
let(:community_and_wellbeing_presenter) do let(:community_and_wellbeing_presenter) do
category = create(:category, name: 'Community & Wellbeing') category = create(:category, name: "Community & Wellbeing")
return CategoryPresenter.new(category:) return CategoryPresenter.new(category:)
end end
@ -39,33 +39,33 @@ describe CategoryPresenter do
DatabaseCleaner.clean DatabaseCleaner.clean
end end
it 'returns the name, id and description of the category' do it "returns the name, id and description of the category" do
expect(category_presenter.name).to eq 'Some Category' expect(category_presenter.name).to eq "Some Category"
expect(category_presenter.description).to eq 'A description for some Category' expect(category_presenter.description).to eq "A description for some Category"
expect(category_presenter.short_description).to eq 'A short description for some Category' expect(category_presenter.short_description).to eq "A short description for some Category"
expect(category_presenter.id).to eq '1' expect(category_presenter.id).to eq "1"
end end
it 'maps subcategories to subcategory presenters' do it "maps subcategories to subcategory presenters" do
expect(category_presenter.subcategories(academic_year: AcademicYear.new, expect(category_presenter.subcategories(academic_year: AcademicYear.new,
school: School.new).map(&:name)).to eq [ school: School.new).map(&:name)).to eq [
'A subcategory', 'Another subcategory' "A subcategory", "Another subcategory"
] ]
end end
it 'returns the correct icon for the given category' do it "returns the correct icon for the given category" do
expect(teachers_and_leadership_presenter.icon_class).to eq 'fas fa-apple-alt' expect(teachers_and_leadership_presenter.icon_class).to eq "fas fa-apple-alt"
expect(school_culture_presenter.icon_class).to eq 'fas fa-school' expect(school_culture_presenter.icon_class).to eq "fas fa-school"
expect(resources_presenter.icon_class).to eq 'fas fa-users-cog' expect(resources_presenter.icon_class).to eq "fas fa-users-cog"
expect(academic_learning_presenter.icon_class).to eq 'fas fa-graduation-cap' expect(academic_learning_presenter.icon_class).to eq "fas fa-graduation-cap"
expect(community_and_wellbeing_presenter.icon_class).to eq 'fas fa-heart' expect(community_and_wellbeing_presenter.icon_class).to eq "fas fa-heart"
end end
it 'returns the correct color for the given category' do it "returns the correct color for the given category" do
expect(teachers_and_leadership_presenter.icon_color_class).to eq 'color-blue' expect(teachers_and_leadership_presenter.icon_color_class).to eq "color-blue"
expect(school_culture_presenter.icon_color_class).to eq 'color-red' expect(school_culture_presenter.icon_color_class).to eq "color-red"
expect(resources_presenter.icon_color_class).to eq 'color-black' expect(resources_presenter.icon_color_class).to eq "color-black"
expect(academic_learning_presenter.icon_color_class).to eq 'color-lime' expect(academic_learning_presenter.icon_color_class).to eq "color-lime"
expect(community_and_wellbeing_presenter.icon_color_class).to eq 'color-teal' expect(community_and_wellbeing_presenter.icon_color_class).to eq "color-teal"
end end
end end

@ -40,39 +40,6 @@ describe AdminDataPresenter do
admin_data_item_5 admin_data_item_5
end end
describe '#item_description' do
context 'When the presenter is based on measure 1A-1' do
it 'returns a list of survey prompts for teacher survey items' do
expect(AdminDataPresenter.new(measure_id: measure_1A_i.measure_id, admin_data_items: measure_1A_i.admin_data_items,
has_sufficient_data: true, school:, academic_year:).item_descriptions).to eq [
'Percentage teachers with 5+ years of experience', 'Percentage teachers National Board certified', 'Percentage teachers teaching in area of licensure'
]
end
context 'When the measure is missing all admin data values' do
it 'if it lacks sufficient data, it shows a warning ' do
expect(AdminDataPresenter.new(measure_id: measure_1A_i.measure_id, admin_data_items: measure_1A_i.admin_data_items,
has_sufficient_data: false, school:, academic_year:).sufficient_data?).to eq false
end
end
context 'When the measure has at least one admin data value' do
it 'if it lacks sufficient data, it doesnt show a warning ' do
expect(AdminDataPresenter.new(measure_id: measure_1A_i.measure_id, admin_data_items: measure_1A_i.admin_data_items,
has_sufficient_data: true, school:, academic_year:).sufficient_data?).to eq true
end
end
end
context 'When the presenter is based on measure 1A-iii' do
it 'returns a message hiding the actual prompts. Instead it presents a message telling the user they can ask for more information' do
expect(AdminDataPresenter.new(measure_id: measure_1A_iii.measure_id, admin_data_items: measure_1A_iii.admin_data_items,
has_sufficient_data: true, school:, academic_year:).item_descriptions).to eq [
'Percent teacher returning (excluding retirement)', 'Percent teachers with 10+ days absent'
]
end
end
end
describe '#descriptions_and_availibility' do describe '#descriptions_and_availibility' do
context 'when there are any matching values for admin data items' do context 'when there are any matching values for admin data items' do
before do before do

@ -1,27 +1,27 @@
require 'rails_helper' require "rails_helper"
describe TeacherSurveyPresenter do describe TeacherSurveyPresenter do
let(:school) { nil } let(:school) { nil }
let(:academic_year) { nil } let(:academic_year) { nil }
let(:measure_1A_i) { create(:measure, measure_id: '1A-i') } let(:measure_1A_i) { create(:measure, measure_id: "1A-i") }
let(:scale_1) { create(:teacher_scale, measure: measure_1A_i) } let(:scale_1) { create(:teacher_scale, measure: measure_1A_i) }
let(:survey_item_1) do let(:survey_item_1) do
create(:teacher_survey_item, survey_item_id: 't-1', scale: scale_1, create(:teacher_survey_item, survey_item_id: "t-1", scale: scale_1,
prompt: 'Given your preparation for teaching how comfortable are you teaching at the grade-level you have been assigned?') prompt: "Given your preparation for teaching how comfortable are you teaching at the grade-level you have been assigned?")
end end
let(:survey_item_2) do let(:survey_item_2) do
create(:teacher_survey_item, survey_item_id: 't-2', scale: scale_1, create(:teacher_survey_item, survey_item_id: "t-2", scale: scale_1,
prompt: 'How prepared are you for teaching the topics that you are expected to teach in your assignment?') prompt: "How prepared are you for teaching the topics that you are expected to teach in your assignment?")
end end
let(:survey_item_3) do let(:survey_item_3) do
create(:teacher_survey_item, survey_item_id: 't-3', scale: scale_1, create(:teacher_survey_item, survey_item_id: "t-3", scale: scale_1,
prompt: 'How confident are you in working with the student body at your school?') prompt: "How confident are you in working with the student body at your school?")
end end
let(:measure_1B_i) { create(:measure, measure_id: '1B-i') } let(:measure_1B_i) { create(:measure, measure_id: "1B-i") }
let(:scale_2) { create(:teacher_scale, measure: measure_1B_i) } let(:scale_2) { create(:teacher_scale, measure: measure_1B_i) }
let(:survey_item_4) do let(:survey_item_4) do
create(:teacher_survey_item, scale: scale_2, create(:teacher_survey_item, scale: scale_2,
prompt: 'Some prompt that will not be shown. Instead it will say items will be available upon request to MCIEA') prompt: "Some prompt that will not be shown. Instead it will say items will be available upon request to MCIEA")
end end
before do before do
scale_1 scale_1
@ -32,31 +32,31 @@ describe TeacherSurveyPresenter do
survey_item_4 survey_item_4
end end
describe '#item_description' do describe "#item_description" do
context 'When the presenter is based on measure 1A-1' do context "When the presenter is based on measure 1A-1" do
it 'returns a list of survey prompts for teacher survey items' do it "returns a list of survey prompts for teacher survey items" do
expect(TeacherSurveyPresenter.new(measure_id: measure_1A_i.measure_id, survey_items: measure_1A_i.teacher_survey_items, expect(TeacherSurveyPresenter.new(measure_id: measure_1A_i.measure_id, survey_items: measure_1A_i.teacher_survey_items,
has_sufficient_data: true, school:, academic_year:).item_descriptions).to eq [ has_sufficient_data: true, school:, academic_year:).item_descriptions).to eq [
'Given your preparation for teaching how comfortable are you teaching at the grade-level you have been assigned?', "Given your preparation for teaching how comfortable are you teaching at the grade-level you have been assigned?",
'How prepared are you for teaching the topics that you are expected to teach in your assignment?', "How prepared are you for teaching the topics that you are expected to teach in your assignment?",
'How confident are you in working with the student body at your school?' "How confident are you in working with the student body at your school?"
] ]
end end
end end
context 'When the presenter is based on measure 1B-i' do context "When the presenter is based on measure 1B-i" do
it 'returns a message hiding the actual prompts. Instead it presents a message telling the user they can ask for more information' do it "returns a message hiding the actual prompts. Instead it presents a message telling the user they can ask for more information" do
expect(TeacherSurveyPresenter.new(measure_id: measure_1B_i.measure_id, survey_items: measure_1B_i.teacher_survey_items, expect(TeacherSurveyPresenter.new(measure_id: measure_1B_i.measure_id, survey_items: measure_1B_i.teacher_survey_items,
has_sufficient_data: true, school:, academic_year:).item_descriptions).to eq [ has_sufficient_data: true, school:, academic_year:).item_descriptions).to eq [
'Items available upon request to MCIEA.' "Items available upon request to MCIEA."
] ]
end end
end end
end end
describe '#descriptions_and_availability' do describe "#descriptions_and_availability" do
context 'When the presenter is NOT based on measure 1B-i' do context "When the presenter is NOT based on measure 1B-i" do
it 'returns a list containing the survey item properties' do it "returns a list containing the survey item properties" do
expect( expect(
TeacherSurveyPresenter.new( TeacherSurveyPresenter.new(
measure_id: measure_1A_i.measure_id, measure_id: measure_1A_i.measure_id,
@ -66,17 +66,17 @@ describe TeacherSurveyPresenter do
academic_year: academic_year:
).descriptions_and_availability ).descriptions_and_availability
).to eq [ ).to eq [
Summary.new('t-1', Summary.new("t-1",
'Given your preparation for teaching how comfortable are you teaching at the grade-level you have been assigned?', true), "Given your preparation for teaching how comfortable are you teaching at the grade-level you have been assigned?", true),
Summary.new('t-2', Summary.new("t-2",
'How prepared are you for teaching the topics that you are expected to teach in your assignment?', true), "How prepared are you for teaching the topics that you are expected to teach in your assignment?", true),
Summary.new('t-3', Summary.new("t-3",
'How confident are you in working with the student body at your school?', true) "How confident are you in working with the student body at your school?", true)
] ]
end end
end end
context 'When the presenter is based on measure 1B-i' do context "When the presenter is based on measure 1B-i" do
it 'returns a message hiding the actual prompts. Instead it presents a message telling the user they can ask for more information' do it "returns a message hiding the actual prompts. Instead it presents a message telling the user they can ask for more information" do
expect( expect(
TeacherSurveyPresenter.new( TeacherSurveyPresenter.new(
measure_id: measure_1B_i.measure_id, measure_id: measure_1B_i.measure_id,
@ -86,7 +86,7 @@ describe TeacherSurveyPresenter do
academic_year: academic_year:
).descriptions_and_availability ).descriptions_and_availability
).to eq [ ).to eq [
Summary.new('1B-i', 'Items available upon request to MCIEA', true) Summary.new("1B-i", "Items available upon request to MCIEA", true)
] ]
end end
end end

Loading…
Cancel
Save