1
- import * as config from "trix/config"
2
1
import { rangesAreEqual } from "trix/core/helpers"
2
+ import TrixEditorElement from "trix/elements/trix_editor_element"
3
3
4
4
import {
5
5
TEST_IMAGE_URL ,
@@ -560,7 +560,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
560
560
assert . equal ( "trix-editor" , element . type )
561
561
} )
562
562
563
- testIfFormAssociated ( "adds [disabled] attribute based on .disabled property" , ( ) => {
563
+ testIf ( TrixEditorElement . formAssociated , "adds [disabled] attribute based on .disabled property" , ( ) => {
564
564
const editor = document . getElementById ( "editor-with-ancestor-form" )
565
565
566
566
editor . disabled = true
@@ -572,7 +572,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
572
572
assert . equal ( editor . hasAttribute ( "disabled" ) , false , "removes [disabled] attribute" )
573
573
} )
574
574
575
- testIfFormAssociated ( "removes [contenteditable] and disables input when editor element has [disabled]" , ( ) => {
575
+ testIf ( TrixEditorElement . formAssociated , "removes [contenteditable] and disables input when editor element has [disabled]" , ( ) => {
576
576
const editor = document . getElementById ( "editor-with-no-form" )
577
577
578
578
editor . setAttribute ( "disabled" , "" )
@@ -590,7 +590,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
590
590
assert . equal ( editor . hasAttribute ( "contenteditable" ) , true , "adds [contenteditable] attribute" )
591
591
} )
592
592
593
- testIfFormAssociated ( "removes [contenteditable] and disables input when editor element is :disabled" , ( ) => {
593
+ testIf ( TrixEditorElement . formAssociated , "removes [contenteditable] and disables input when editor element is :disabled" , ( ) => {
594
594
const editor = document . getElementById ( "editor-within-fieldset" )
595
595
const fieldset = document . getElementById ( "fieldset" )
596
596
@@ -611,7 +611,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
611
611
assert . equal ( editor . hasAttribute ( "contenteditable" ) , true , "adds [contenteditable] attribute" )
612
612
} )
613
613
614
- testIfFormAssociated ( "does not receive focus when :disabled" , ( ) => {
614
+ testIf ( TrixEditorElement . formAssociated , "does not receive focus when :disabled" , ( ) => {
615
615
const activeEditor = document . getElementById ( "editor-with-input-form" )
616
616
const editor = document . getElementById ( "editor-within-fieldset" )
617
617
@@ -622,7 +622,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
622
622
assert . equal ( activeEditor , document . activeElement , "disabled editor does not receive focus" )
623
623
} )
624
624
625
- testIfFormAssociated ( "disabled editor does not encode its value when the form is submitted" , ( ) => {
625
+ testIf ( TrixEditorElement . formAssociated , "disabled editor does not encode its value when the form is submitted" , ( ) => {
626
626
const editor = document . getElementById ( "editor-with-ancestor-form" )
627
627
const form = editor . form
628
628
@@ -632,7 +632,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
632
632
assert . deepEqual ( { } , Object . fromEntries ( new FormData ( form ) . entries ( ) ) , "does not write to FormData" )
633
633
} )
634
634
635
- testIfFormAssociated ( "validates with [required] attribute as invalid" , ( ) => {
635
+ testIf ( TrixEditorElement . formAssociated , "validates with [required] attribute as invalid" , ( ) => {
636
636
const editor = document . getElementById ( "editor-with-ancestor-form" )
637
637
const form = editor . form
638
638
let invalidEvent , submitEvent = null
@@ -651,7 +651,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
651
651
assert . equal ( submitEvent , null , "does not dispatch a 'submit' event" )
652
652
} )
653
653
654
- testIfFormAssociated ( "does not validate with [disabled] attribute" , ( ) => {
654
+ testIf ( TrixEditorElement . formAssociated , "does not validate with [disabled] attribute" , ( ) => {
655
655
const editor = document . getElementById ( "editor-with-ancestor-form" )
656
656
let invalidEvent = null
657
657
@@ -663,7 +663,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
663
663
assert . equal ( invalidEvent , null , "does not dispatch an 'invalid' event" )
664
664
} )
665
665
666
- testIfFormAssociated ( "re-validates when the value changes" , async ( ) => {
666
+ testIf ( TrixEditorElement . formAssociated , "re-validates when the value changes" , async ( ) => {
667
667
const editor = document . getElementById ( "editor-with-ancestor-form" )
668
668
editor . required = true
669
669
editor . focus ( )
@@ -677,7 +677,7 @@ testGroup("form property references its <form>", { template: "editors_with_forms
677
677
assert . equal ( editor . validationMessage , "" , "clears the validationMessage" )
678
678
} )
679
679
680
- testIfFormAssociated ( "accepts a customError validation message" , ( ) => {
680
+ testIf ( TrixEditorElement . formAssociated , "accepts a customError validation message" , ( ) => {
681
681
const editor = document . getElementById ( "editor-with-ancestor-form" )
682
682
683
683
editor . setCustomValidity ( "A custom validation message" )
@@ -687,13 +687,3 @@ testGroup("form property references its <form>", { template: "editors_with_forms
687
687
assert . equal ( editor . validationMessage , "A custom validation message" )
688
688
} )
689
689
} )
690
-
691
- function testIfFormAssociated ( name , callback ) {
692
- test ( name , async ( ) => {
693
- if ( config . editor . formAssociated ) {
694
- await callback ( )
695
- } else {
696
- assert . equal ( config . editor . formAssociated , false , "skipping test that requires ElementInternals" )
697
- }
698
- } )
699
- }
0 commit comments