aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/javascript/src/unit/action_cable_test.js
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/test/javascript/src/unit/action_cable_test.js')
-rw-r--r--actioncable/test/javascript/src/unit/action_cable_test.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/actioncable/test/javascript/src/unit/action_cable_test.js b/actioncable/test/javascript/src/unit/action_cable_test.js
new file mode 100644
index 0000000000..c46f9878d2
--- /dev/null
+++ b/actioncable/test/javascript/src/unit/action_cable_test.js
@@ -0,0 +1,57 @@
+import * as ActionCable from "../../../../app/javascript/action_cable/index"
+import {testURL} from "../test_helpers/index"
+
+const {module, test} = QUnit
+
+module("ActionCable", () => {
+ module("Adapters", () => {
+ module("WebSocket", () => {
+ test("default is self.WebSocket", assert => {
+ assert.equal(ActionCable.adapters.WebSocket, self.WebSocket)
+ })
+ })
+
+ module("logger", () => {
+ test("default is self.console", assert => {
+ assert.equal(ActionCable.adapters.logger, self.console)
+ })
+ })
+ })
+
+ module("#createConsumer", () => {
+ test("uses specified URL", assert => {
+ const consumer = ActionCable.createConsumer(testURL)
+ assert.equal(consumer.url, testURL)
+ })
+
+ test("uses default URL", assert => {
+ const pattern = new RegExp(`${ActionCable.INTERNAL.default_mount_path}$`)
+ const consumer = ActionCable.createConsumer()
+ assert.ok(pattern.test(consumer.url), `Expected ${consumer.url} to match ${pattern}`)
+ })
+
+ test("uses URL from meta tag", assert => {
+ const element = document.createElement("meta")
+ element.setAttribute("name", "action-cable-url")
+ element.setAttribute("content", testURL)
+
+ document.head.appendChild(element)
+ const consumer = ActionCable.createConsumer()
+ document.head.removeChild(element)
+
+ assert.equal(consumer.url, testURL)
+ })
+
+ test("dynamically computes URL from function", assert => {
+ let dynamicURL = testURL
+ const generateURL = () => {
+ return dynamicURL
+ }
+ const consumer = ActionCable.createConsumer(generateURL)
+ assert.equal(consumer.url, testURL)
+
+ dynamicURL = `${testURL}foo`
+ assert.equal(consumer.url, `${testURL}foo`)
+ })
+ })
+})