diff --git a/app/main/views/organizations.py b/app/main/views/organizations.py index 6b769a91f..6e3496a7f 100644 --- a/app/main/views/organizations.py +++ b/app/main/views/organizations.py @@ -210,9 +210,7 @@ def _handle_delete_service(org_id, service_id): cached_service_user_ids = [user.id for user in service.active_users] service_api_client.archive_service(service_id, cached_service_user_ids) - create_archive_service_event( - service_id=service_id, archived_by_id=current_user.id - ) + create_archive_service_event(service_id=service_id, archived_by_id=current_user.id) cache.redis_client.delete("organizations") diff --git a/tests/javascripts/organizationDashboard.test.js b/tests/javascripts/organizationDashboard.test.js new file mode 100644 index 000000000..4ad3c5a3f --- /dev/null +++ b/tests/javascripts/organizationDashboard.test.js @@ -0,0 +1,165 @@ +/** + * @jest-environment jsdom + */ + +describe('organizationDashboard.js', () => { + let originalLocation; + + beforeEach(() => { + jest.resetModules(); + jest.useFakeTimers(); + + originalLocation = window.location; + Element.prototype.scrollIntoView = jest.fn(); + window.requestAnimationFrame = jest.fn((cb) => setTimeout(cb, 0)); + }); + + afterEach(() => { + jest.useRealTimers(); + document.body.innerHTML = ''; + }); + + + describe('Edit Service Confirmation', () => { + beforeEach(() => { + document.body.innerHTML = ` + +
+ `; + + require('../../app/assets/javascripts/organizationDashboard.js'); + document.dispatchEvent(new Event('DOMContentLoaded')); + }); + + test('submits edit form when confirm button clicked', () => { + const confirmButton = document.getElementById('edit-service-confirm-btn'); + const editForm = document.getElementById('edit-service-form'); + editForm.submit = jest.fn(); + + confirmButton.click(); + + expect(editForm.submit).toHaveBeenCalled(); + }); + }); + + describe('Form Initialization', () => { + test('scrolls to and focuses create service form', () => { + document.body.innerHTML = ` + + `; + + const form = document.getElementById('create-service-form'); + const input = form.querySelector('input[type="text"]'); + + require('../../app/assets/javascripts/organizationDashboard.js'); + document.dispatchEvent(new Event('DOMContentLoaded')); + + jest.runAllTimers(); + + expect(form.scrollIntoView).toHaveBeenCalled(); + expect(document.activeElement).toBe(input); + }); + + test('scrolls to and focuses invite user form', () => { + document.body.innerHTML = ` + + `; + + const form = document.getElementById('invite-user-form'); + const input = form.querySelector('input[type="email"]'); + + require('../../app/assets/javascripts/organizationDashboard.js'); + document.dispatchEvent(new Event('DOMContentLoaded')); + + jest.runAllTimers(); + + expect(form.scrollIntoView).toHaveBeenCalled(); + expect(document.activeElement).toBe(input); + }); + + test('scrolls to and focuses edit service form', () => { + document.body.innerHTML = ` + + `; + + const form = document.getElementById('edit-service-form'); + const input = form.querySelector('input[type="text"]'); + + require('../../app/assets/javascripts/organizationDashboard.js'); + document.dispatchEvent(new Event('DOMContentLoaded')); + + jest.runAllTimers(); + + expect(form.scrollIntoView).toHaveBeenCalled(); + expect(document.activeElement).toBe(input); + }); + + test('does nothing when no relevant forms present', () => { + document.body.innerHTML = '