-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test cases for special attribute in DomValidator
Add test cases to verify DomValidator accepts attribute: - ':' prefix for binding attributes (e.g. :class) - '@' prefix for event handlers (e.g. @scroll.window)
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'package:jaspr/src/server/markup_render_object.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('DomValidator', () { | ||
late DomValidator validator; | ||
|
||
setUp(() { | ||
validator = DomValidator(); | ||
}); | ||
|
||
group('validateElementName', () { | ||
test('accepts valid element names', () { | ||
expect(() => validator.validateElementName('div'), returnsNormally); | ||
expect(() => validator.validateElementName('custom-element'), | ||
returnsNormally); | ||
expect(() => validator.validateElementName('h1'), returnsNormally); | ||
}); | ||
|
||
test('throws on invalid element names', () { | ||
expect( | ||
() => validator.validateElementName('1div'), throwsArgumentError); | ||
expect(() => validator.validateElementName('-element'), | ||
throwsArgumentError); | ||
expect( | ||
() => validator.validateElementName('div!'), throwsArgumentError); | ||
}); | ||
}); | ||
|
||
group('validateAttributeName', () { | ||
test('accepts valid attribute names', () { | ||
expect(() => validator.validateAttributeName('id'), returnsNormally); | ||
expect(() => validator.validateAttributeName('data-test'), | ||
returnsNormally); | ||
expect(() => validator.validateAttributeName('aria-label'), | ||
returnsNormally); | ||
expect( | ||
() => validator.validateAttributeName(':class'), returnsNormally); | ||
expect(() => validator.validateAttributeName('@scroll.window'), | ||
returnsNormally); | ||
}); | ||
|
||
test('throws on invalid attribute names', () { | ||
expect( | ||
() => validator.validateAttributeName('1id'), throwsArgumentError); | ||
expect(() => validator.validateAttributeName('-test'), | ||
throwsArgumentError); | ||
expect(() => validator.validateAttributeName('data!'), | ||
throwsArgumentError); | ||
}); | ||
}); | ||
|
||
group('isSelfClosing', () { | ||
test('returns true for self-closing elements', () { | ||
expect(validator.isSelfClosing('img'), isTrue); | ||
expect(validator.isSelfClosing('br'), isTrue); | ||
expect(validator.isSelfClosing('input'), isTrue); | ||
}); | ||
|
||
test('returns false for non-self-closing elements', () { | ||
expect(validator.isSelfClosing('div'), isFalse); | ||
expect(validator.isSelfClosing('span'), isFalse); | ||
expect(validator.isSelfClosing('p'), isFalse); | ||
}); | ||
}); | ||
|
||
group('hasStrictWhitespace', () { | ||
test('returns true for elements with strict whitespace', () { | ||
expect(validator.hasStrictWhitespace('p'), isTrue); | ||
expect(validator.hasStrictWhitespace('h1'), isTrue); | ||
expect(validator.hasStrictWhitespace('label'), isTrue); | ||
}); | ||
|
||
test('returns false for elements without strict whitespace', () { | ||
expect(validator.hasStrictWhitespace('div'), isFalse); | ||
expect(validator.hasStrictWhitespace('span'), isFalse); | ||
}); | ||
}); | ||
|
||
group('hasStrictFormatting', () { | ||
test('returns true for elements with strict formatting', () { | ||
expect(validator.hasStrictFormatting('pre'), isTrue); | ||
expect(validator.hasStrictFormatting('span'), isTrue); | ||
}); | ||
|
||
test('returns false for elements without strict formatting', () { | ||
expect(validator.hasStrictFormatting('div'), isFalse); | ||
expect(validator.hasStrictFormatting('p'), isFalse); | ||
}); | ||
}); | ||
}); | ||
} |