Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { ControllerTestCase } from "../../cases/controller_test_case" | ||
import { OutletController } from "../../controllers/outlet_controller" | ||
|
||
export default class OutletFallbackSelectorTests extends ControllerTestCase(OutletController) { | ||
fixtureHTML = ` | ||
<div id="container"> | ||
<div data-controller="alpha" id="alpha1"></div> | ||
<div data-controller="beta" id="beta1"> | ||
<div data-controller="alpha beta" id="mixed"></div> | ||
<div data-controller="beta" id="beta2"></div> | ||
</div> | ||
<div | ||
data-controller="${this.identifier}" | ||
data-${this.identifier}-connected-class="connected" | ||
data-${this.identifier}-disconnected-class="disconnected" | ||
> | ||
</div> | ||
</div> | ||
` | ||
get identifiers() { | ||
return ["test", "alpha", "beta", "delta"] | ||
} | ||
|
||
"test OutletSet#find"() { | ||
this.assert.equal(this.controller.outlets.find("alpha"), this.findElement("#alpha1")) | ||
this.assert.equal(this.controller.outlets.find("beta"), this.findElement("#beta1")) | ||
this.assert.equal(this.controller.outlets.find("delta"), undefined) | ||
} | ||
|
||
"test OutletSet#findAll"() { | ||
this.assert.deepEqual(this.controller.outlets.findAll("alpha"), this.findElements("#alpha1", "#mixed")) | ||
this.assert.deepEqual(this.controller.outlets.findAll("beta"), this.findElements("#beta1", "#mixed", "#beta2")) | ||
this.assert.deepEqual(this.controller.outlets.findAll("delta"), []) | ||
} | ||
|
||
"test OutletSet#findAll with multiple arguments"() { | ||
this.assert.deepEqual( | ||
this.controller.outlets.findAll("alpha", "beta"), | ||
this.findElements("#alpha1", "#mixed", "#beta1", "#mixed", "#beta2") | ||
) | ||
} | ||
|
||
"test OutletSet#has"() { | ||
this.assert.equal(this.controller.outlets.has("alpha"), true) | ||
this.assert.equal(this.controller.outlets.has("beta"), true) | ||
this.assert.equal(this.controller.outlets.has("gamma"), false) | ||
} | ||
|
||
"test OutletSet#has when no element with selector exists"() { | ||
const element = document.createElement("div") | ||
element.setAttribute("data-controller", "gamma") | ||
|
||
this.assert.equal(this.controller.outlets.has("gamma"), false) | ||
|
||
this.controller.element.appendChild(element) | ||
this.assert.equal(this.controller.outlets.has("gamma"), true) | ||
} | ||
|
||
"test singular linked outlet property throws an error when no outlet is found"() { | ||
this.findElements("#alpha1", "#mixed", "#beta1", "#mixed", "#beta2").forEach((e) => e.remove()) | ||
|
||
this.assert.equal(this.controller.hasAlphaOutlet, false) | ||
this.assert.equal(this.controller.alphaOutlets.length, 0) | ||
this.assert.equal(this.controller.alphaOutletElements.length, 0) | ||
this.assert.throws(() => this.controller.alphaOutlet) | ||
this.assert.throws(() => this.controller.alphaOutletElement) | ||
|
||
this.assert.equal(this.controller.hasBetaOutlet, false) | ||
this.assert.equal(this.controller.betaOutlets.length, 0) | ||
this.assert.equal(this.controller.betaOutletElements.length, 0) | ||
this.assert.throws(() => this.controller.betaOutlet) | ||
this.assert.throws(() => this.controller.betaOutletElement) | ||
} | ||
|
||
"test outlet connected callback fires"() { | ||
const alphaOutlets = this.controller.alphaOutletElements.filter((outlet) => outlet.classList.contains("connected")) | ||
|
||
this.assert.equal(alphaOutlets.length, 2) | ||
this.assert.equal(this.controller.alphaOutletConnectedCallCountValue, 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters