parent
edeb3f4e59
commit
cf6e80ce6b
@ -0,0 +1,8 @@
|
||||
import { Modal } from "bootstrap";
|
||||
|
||||
export function showEmptyDatasetModal() {
|
||||
const modal = document.querySelector('.modal');
|
||||
if(modal){
|
||||
new Modal(modal).show();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 43 KiB |
@ -0,0 +1,49 @@
|
||||
import { showEmptyDatasetModal } from "modal";
|
||||
|
||||
describe("Empty data set modal", () => {
|
||||
describe("When a modal element exists on the page", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `<html><body>
|
||||
<div class="modal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Modal title</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Modal body text goes here.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body> </html> `;
|
||||
});
|
||||
|
||||
it("Adds a class to make the modal visible", () => {
|
||||
showEmptyDatasetModal();
|
||||
const modal = document.querySelector(".modal");
|
||||
expect(modal.classList.contains('show')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When a modal doesn't exist on the page", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `
|
||||
<html>
|
||||
<body></body>
|
||||
</html>
|
||||
`
|
||||
})
|
||||
|
||||
it("ignores the content", () =>{
|
||||
showEmptyDatasetModal();
|
||||
const modal = document.querySelector(".modal");
|
||||
expect(modal).toBe(null);
|
||||
})
|
||||
})
|
||||
});
|
||||
@ -0,0 +1,43 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'authentication' do
|
||||
let(:district) { create(:district) }
|
||||
let(:school) { create(:school, district: district) }
|
||||
let(:academic_year) { create(:academic_year) }
|
||||
|
||||
context 'when using the wrong credentials' do
|
||||
before :each do
|
||||
page.driver.browser.basic_authorize('wrong username', 'wrong password')
|
||||
end
|
||||
it 'does not show any information' do
|
||||
visit dashboard_path
|
||||
|
||||
expect(page).not_to have_text(school.name)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using the right credentials' do
|
||||
before :each do
|
||||
page.driver.browser.basic_authorize(username, password)
|
||||
end
|
||||
it 'does show information' do
|
||||
visit dashboard_path
|
||||
|
||||
expect(page).to have_text(school.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def username
|
||||
district.name.downcase
|
||||
end
|
||||
def password
|
||||
"#{username}!"
|
||||
end
|
||||
|
||||
def dashboard_path
|
||||
district_school_dashboard_index_path(district, school, year: academic_year.range)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,56 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'SQM Application' do
|
||||
let(:district) { create(:district) }
|
||||
let(:school) { create(:school, district: district) }
|
||||
let(:academic_year) { create(:academic_year) }
|
||||
let(:category) { create(:sqm_category) }
|
||||
let(:measure) { create(:measure) }
|
||||
|
||||
before :each do
|
||||
driven_by :rack_test
|
||||
page.driver.browser.basic_authorize(username, password)
|
||||
end
|
||||
|
||||
context 'when no measures meet their threshold' do
|
||||
it 'shows a modal on all pages' do
|
||||
[dashboard_path, browse_path].each do |path|
|
||||
visit path
|
||||
expect(page).to have_css '.modal'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'at least one measure meets its threshold' do
|
||||
before :each do
|
||||
teacher_survey_item = create(:teacher_survey_item, measure: measure)
|
||||
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
|
||||
survey_item: teacher_survey_item, academic_year: academic_year, school: school)
|
||||
end
|
||||
|
||||
it 'does not show a modal on any page' do
|
||||
[dashboard_path, browse_path].each do |path|
|
||||
visit path
|
||||
expect(page).not_to have_css '.modal'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def username
|
||||
district.name.downcase
|
||||
end
|
||||
|
||||
def password
|
||||
"#{username}!"
|
||||
end
|
||||
|
||||
def dashboard_path
|
||||
district_school_dashboard_index_path(district, school, year: academic_year.range)
|
||||
end
|
||||
|
||||
def browse_path
|
||||
district_school_sqm_category_path(district, school, category, year: academic_year.range)
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue