-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy pathapplication_tests.ts
More file actions
69 lines (54 loc) · 2.62 KB
/
application_tests.ts
File metadata and controls
69 lines (54 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { ApplicationTestCase } from "../../cases/application_test_case"
import { LogController } from "../../controllers/log_controller"
class AController extends LogController {}
class BController extends LogController {}
export default class ApplicationTests extends ApplicationTestCase {
fixtureHTML = `<div data-controller="a"><div data-controller="b">`
private definitions = [
{ controllerConstructor: AController, identifier: "a" },
{ controllerConstructor: BController, identifier: "b" },
]
async "test Application#register"() {
this.assert.equal(this.controllers.length, 0)
this.application.register("log", LogController)
await this.renderFixture(`<div data-controller="log">`)
this.assert.equal(this.controllers[0].initializeCount, 1)
this.assert.equal(this.controllers[0].connectCount, 1)
}
"test Application#load"() {
this.assert.equal(this.controllers.length, 0)
this.application.load(this.definitions)
this.assert.equal(this.controllers.length, 2)
this.assert.ok(this.controllers[0] instanceof AController)
this.assert.equal(this.controllers[0].initializeCount, 1)
this.assert.equal(this.controllers[0].connectCount, 1)
this.assert.ok(this.controllers[1] instanceof BController)
this.assert.equal(this.controllers[1].initializeCount, 1)
this.assert.equal(this.controllers[1].connectCount, 1)
}
"test Application#unload"() {
this.application.load(this.definitions)
const originalControllers = this.controllers
this.application.unload("a")
this.assert.equal(originalControllers[0].disconnectCount, 1)
this.assert.equal(this.controllers.length, 1)
this.assert.ok(this.controllers[0] instanceof BController)
}
"test Application#getControllerForElementAndIdentifier logs debug activity when controller not found"() {
this.application.load(this.definitions)
const logCalls: { identifier: string; functionName: string; detail: { element?: Element } }[] = []
this.application.logDebugActivity = (identifier, functionName, detail = {}) => {
logCalls.push({ identifier, functionName, detail })
}
const element = this.fixtureElement.querySelector("[data-controller='a']")!
const result = this.application.getControllerForElementAndIdentifier(element, "nonexistent")
this.assert.equal(result, null)
this.assert.equal(logCalls.length, 1)
this.assert.equal(logCalls[0].identifier, "nonexistent")
this.assert.equal(logCalls[0].functionName, "controller not found")
this.assert.equal(logCalls[0].detail.element, element)
}
get controllers() {
return this.application.controllers as LogController[]
}
}