diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js deleted file mode 100644 index dfc21a66..00000000 --- a/app/assets/javascripts/application.js +++ /dev/null @@ -1,15 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// compiled file. JavaScript code in this file should be added after the last require_* statement. -// -// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details -// about supported directives. -// -//= require bootstrap -//= require turbolinks -//= require_tree . diff --git a/app/assets/javascripts/dashboard.js b/app/assets/javascripts/dashboard.js deleted file mode 100644 index dbcad599..00000000 --- a/app/assets/javascripts/dashboard.js +++ /dev/null @@ -1,12 +0,0 @@ -document.addEventListener("turbolinks:load", function() { - const schoolDropdown = document.querySelector('#select-school'); - if (schoolDropdown) { - document.querySelector('#select-school').addEventListener('change', (event) => { - window.location = event.target.value; - }); - - document.querySelector('#select-district').addEventListener('change', (event) => { - window.location = event.target.value; - }); - } -}); diff --git a/app/assets/javascripts/jester.js b/app/assets/javascripts/jester.js deleted file mode 100644 index 52a9d9b6..00000000 --- a/app/assets/javascripts/jester.js +++ /dev/null @@ -1,7 +0,0 @@ -export default class Jester { - constructor(){} - - hello(){ - return "Hello" - } -} diff --git a/app/javascript/application.js b/app/javascript/application.js index db91aa88..018d4f16 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1 +1,15 @@ // Entry point for the build script in your package.json + + import Rails from "@rails/ujs"; + import Turbolinks from "turbolinks"; + import * as ActiveStorage from "@rails/activestorage"; + // import "channels"; + + Rails.start(); + Turbolinks.start(); + ActiveStorage.start(); +import { initializeListenersForNavDropdowns } from "./dashboard.js"; +import { initializeListenersForHomeDropdowns } from "./home.js"; + +initializeListenersForNavDropdowns(); +initializeListenersForHomeDropdowns(); diff --git a/app/assets/javascripts/cable.js b/app/javascript/cable.js similarity index 100% rename from app/assets/javascripts/cable.js rename to app/javascript/cable.js diff --git a/app/javascript/channels/.keep b/app/javascript/channels/.keep new file mode 100644 index 00000000..e69de29b diff --git a/app/javascript/dashboard.js b/app/javascript/dashboard.js new file mode 100644 index 00000000..74aad336 --- /dev/null +++ b/app/javascript/dashboard.js @@ -0,0 +1,14 @@ +export function initializeListenersForNavDropdowns(){ + document.addEventListener("turbolinks:load", function() { + const schoolDropdown = document.querySelector('#select-school'); + if (schoolDropdown) { + document.querySelector('#select-school').addEventListener('change', (event) => { + window.location = event.target.value; + }); + + document.querySelector('#select-district').addEventListener('change', (event) => { + window.location = event.target.value; + }); + } + }); +} diff --git a/app/assets/javascripts/home.js b/app/javascript/home.js similarity index 88% rename from app/assets/javascripts/home.js rename to app/javascript/home.js index 47d80f08..bbc1476e 100644 --- a/app/assets/javascripts/home.js +++ b/app/javascript/home.js @@ -1,4 +1,5 @@ -document.addEventListener('DOMContentLoaded', () => { +export function initializeListenersForHomeDropdowns(){ +document.addEventListener('turbolinks:load', () => { const districtDropdown = document.querySelector('#district-dropdown'); if (districtDropdown) { districtDropdown.addEventListener('change', event => { @@ -23,3 +24,5 @@ document.addEventListener('DOMContentLoaded', () => { }); } }); +return true; +} diff --git a/package.json b/package.json index 21b951f2..63bd6f4a 100644 --- a/package.json +++ b/package.json @@ -4,22 +4,26 @@ "dependencies": { "@babel/preset-env": "^7.15.8", "babel-preset-es2015": "^6.24.1", - "esbuild": "^0.13.6" + "esbuild": "^0.13.6", + "@rails/actioncable": "^6.0.0", + "@rails/activestorage": "^6.0.0", + "@rails/ujs": "^6.0.0", + "turbolinks": "^5.2.0" }, "scripts": { "build": "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds", - "test": "jest" + "test": "jest --env=jsdom" }, "devDependencies": { "jest": "^27.2.5" }, "jest": { - "roots": [ - "./spec/javascript" + "roots": [ + "./spec/javascript" ], - "moduleDirectories": [ - "node_modules", - "app/assets/javascripts" + "moduleDirectories": [ + "node_modules", + "app/javascript" ] } } diff --git a/spec/javascript/hello_jest.spec.js b/spec/javascript/hello_jest.spec.js deleted file mode 100644 index ff3d5aab..00000000 --- a/spec/javascript/hello_jest.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -import Jester from "jester" - -describe('this test should pass', () => { - test('very first test', () => { - expect(true).toBe(true) - }) - - test('Jester.hello returns greeting', () =>{ - const jester = new Jester() - expect(jester.hello()).toBe("Hello") - }) -}) diff --git a/spec/javascript/home.spec.js b/spec/javascript/home.spec.js new file mode 100644 index 00000000..dd594f00 --- /dev/null +++ b/spec/javascript/home.spec.js @@ -0,0 +1,12 @@ +import {initializeListenersForHomeDropdowns } from "home" + +it("returns true when called", () =>{ + + document.body.innerHTML = + '