Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 28c8307

Browse files
authored
test(behaviors): make behavior tests and specification mandatory (#455)
* first raw changes adding specification tag * make tests mandatory * make tests mandatory * small fix in name * reverting change, which have not been done by purpose * fix number of ticket * adding test if description and specification is missing in the file * adressing comments from PR * fix2 after review * adressing changes after PR, another fixes * adressing changes after PR 2 * rename parameter
1 parent 3df60db commit 28c8307

25 files changed

+129
-55
lines changed

build/gulp/plugins/gulp-component-menu-behaviors.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ type BehaviorMenuItem = {
1414
type: string
1515
variations: {
1616
name: string
17-
text: string
17+
description: string
18+
specification: string
1819
}
1920
}
2021

22+
const getTextFromCommentToken = (commentTokens, tokenTitle): string => {
23+
const token = commentTokens.find(token => token.title === tokenTitle)
24+
return token ? token.description : ''
25+
}
26+
2127
export default () => {
2228
const result: BehaviorMenuItem[] = []
2329
function bufferContents(file, enc, cb) {
@@ -37,28 +43,25 @@ export default () => {
3743
const componentType = _.lowerFirst(path.basename(path.dirname(dir)).replace(/s$/, ''))
3844
const behaviorVariantName = file.basename
3945
const behaviorName = path.basename(dir)
40-
41-
let description
4246
const fileContent = fs.readFileSync(file.path).toString()
4347
const blockComments = extract(fileContent).filter(comment => comment.type === 'BlockComment') // filtering only block comments
44-
const emptyDescriptionText = 'Behavior file has no description.'
48+
const variation = {
49+
name: behaviorVariantName,
50+
description: '',
51+
specification: '',
52+
}
4553

46-
// getting object that describes '@description' part of the comment's text
54+
// getting description and specification of the comment's text
4755
if (!_.isEmpty(blockComments)) {
4856
const commentTokens = doctrine.parse(blockComments[0].raw, { unwrap: true }).tags
49-
const descriptionToken = commentTokens.find(token => token.title === 'description')
50-
description = descriptionToken ? descriptionToken.description : emptyDescriptionText
51-
} else {
52-
description = emptyDescriptionText
57+
variation.description = getTextFromCommentToken(commentTokens, 'description')
58+
variation.specification = getTextFromCommentToken(commentTokens, 'specification')
5359
}
5460

5561
result.push({
5662
displayName: behaviorName,
5763
type: componentType,
58-
variations: {
59-
name: behaviorVariantName,
60-
text: description,
61-
},
64+
variations: variation,
6265
})
6366
cb()
6467
} catch (err) {

docs/src/components/DocsBehaviorRoot.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,24 @@ class DocsBehaviorRoot extends React.Component<any, any> {
7171
<div style={{ padding: '1em' }}>
7272
<span> Description: </span>
7373
<br />
74-
{variation.text.split('\n').map((splittedText, keyValue) => {
75-
return (
76-
<span key={keyValue}>
77-
{splittedText}
78-
<br />
79-
</span>
80-
)
81-
})}
74+
{variation.description &&
75+
variation.description.split('\n').map((splittedText, keyValue) => {
76+
return (
77+
<span key={keyValue}>
78+
{splittedText}
79+
<br />
80+
</span>
81+
)
82+
})}
83+
{variation.specification &&
84+
variation.specification.split('\n').map((splittedText, keyValue) => {
85+
return (
86+
<span key={keyValue}>
87+
{splittedText}
88+
<br />
89+
</span>
90+
)
91+
})}
8292
</div>
8393
</Grid.Row>
8494
))}

src/lib/accessibility/Behaviors/Button/buttonBehavior.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Accessibility } from '../../types'
22
import * as _ from 'lodash'
33

44
/**
5-
* @description
6-
* Adds role='button' if element type is other than 'button'. This allows screen readers to handle the component as a button.
7-
* Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component.
5+
* @specification
6+
* Adds role='button' if element type is other than 'button'. This allows screen readers to handle the component as a button.
7+
* Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component.
88
*/
99

1010
const buttonBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/Button/buttonGroupBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Accessibility, FocusZoneMode } from '../../types'
22

33
/**
4-
* @description
4+
* @specification
55
* Adds role 'presentation' to 'root' component's part.
66
* Wraps component in FocusZone allowing arrow key navigation through the children of the component.
77
*/

src/lib/accessibility/Behaviors/Button/toggleButtonBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Accessibility } from '../../types'
22
import * as _ from 'lodash'
33

44
/**
5-
* @description
5+
* @specification
66
* Adds role='button' if element type is other than 'button'. This allows screen readers to handle the component as a button
77
* Adds attribute 'aria-pressed=true' based on the property 'active'. This can be overriden by providing 'aria-presssed' property directly to the component.
88
* Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component.

src/lib/accessibility/Behaviors/Dialog/dialogBehavior.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as _ from 'lodash'
66
* @description
77
* Adds role='button' to 'trigger' component's part, if it is not focusable element and no role attribute provided.
88
* Adds tabIndex='0' to 'trigger' component's part, if it is not tabbable element and no tabIndex attribute provided.
9+
*
10+
* @specification
911
* Adds attribute 'aria-disabled=true' to 'trigger' component's part based on the property 'disabled'.
1012
* Adds attribute 'aria-modal=true' to 'popup' component's part.
1113
* Adds attribute 'role=dialog' to 'popup' component's part.

src/lib/accessibility/Behaviors/Grid/gridBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Accessibility, FocusZoneMode } from '../../types'
22

33
/**
4-
* @description
4+
* @specification
55
* Wraps component in FocusZone allowing circular arrow key navigation through the children of the component.
66
*/
77
const gridBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/Icon/iconBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Accessibility } from '../../types'
22

33
/**
44
* @description
5-
* Adds attribute 'aria-hidden=true' to icon.
65
* Icon is usually only visual representation and therefore is hidden from screen readers.
6+
*
7+
* @specification
8+
* Adds attribute 'aria-hidden=true' to icon.
79
*/
810

911
const iconBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/Image/imageBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Accessibility } from '../../types'
22

33
/**
44
* @description
5-
* Adds attribute 'aria-hidden=true', if there is no 'alt' property provided.
65
* Image is usually only visual representation and therefore is hidden from screen readers.
6+
*
7+
* @specification
8+
* Adds attribute 'aria-hidden=true', if there is no 'alt' property provided.
79
*/
810

911
const imageBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/Input/inputBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Accessibility } from '../../types'
22
import * as _ from 'lodash'
33

44
/**
5-
* @description
5+
* @specification
66
* Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component.
77
*/
88

src/lib/accessibility/Behaviors/List/basicListBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Accessibility } from '../../types'
22

33
/**
44
* @description
5-
* Adds role='list'.
65
* The 'list' role is used to identify an element that creates a list.
6+
*
7+
* @specification
8+
* Adds role='list'.
79
*/
810

911
const basicListBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/List/basicListItemBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Accessibility } from '../../types'
22

33
/**
44
* @description
5-
* Adds role='listitem'.
65
* The 'listitem' role is used to identify an element that is a single item in a list.
6+
*
7+
* @specification
8+
* Adds role='listitem'.
79
*/
810

911
const basicListItemBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/List/selectableListBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { Accessibility } from '../../types'
33

44
/**
55
* @description
6-
* Adds role='listbox'.
76
* The listbox role is used to identify an element that creates a list from which a user may select one or more items.
7+
*
8+
* @specification
9+
* Adds role='listbox'.
810
*/
911

1012
const selectableListBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/List/selectableListItemBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Accessibility } from '../../types'
22

33
/**
4-
* @description
4+
* @specification
55
* Adds role='option'. This role is used for a selectable item in a list.
66
* Adds attribute 'aria-selected=true' based on the property 'active'. Based on this screen readers will recognize the selected state of the item.
77
*/

src/lib/accessibility/Behaviors/Menu/menuBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Accessibility, FocusZoneMode } from '../../types'
22

33
/**
44
* @description
5-
* Adds role='menu'.
65
* The 'menu' role is used to identify an element that creates a list of common actions or functions that a user can invoke.
6+
*
7+
* @specification
8+
* Adds role='menu'.
79
* Wraps component in FocusZone allowing circular arrow key navigation through the children of the component.
810
*/
911

src/lib/accessibility/Behaviors/Menu/menuItemBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import * as keyboardKey from 'keyboard-key'
44

55
/**
66
* @description
7+
* The behavior is designed for particular structure of menu item. The item consists of root element and anchor inside the root element.
8+
*
9+
* @specification
710
* Adds role 'presentation' to 'root' component's part.
811
* Adds role 'menuitem' to 'anchor' component's part.
912
* Adds attribute 'tabIndex=0' to 'anchor' component's part.
1013
* Adds attribute 'data-is-focusable=true' to 'anchor' component's part.
1114
* Adds attribute 'aria-label' based on the property 'aria-label' to 'anchor' component's part.
1215
* Adds attribute 'aria-labelledby' based on the property 'aria-labelledby' to 'anchor' component's part.
1316
* Adds attribute 'aria-describedby' based on the property 'aria-describedby' to 'anchor' component's part.
14-
* The behavior is designed for particular structure of menu item. The item consists of root element and anchor inside the root element.
1517
*/
1618

1719
const menuItemBehavior: Accessibility = (props: any) => ({

src/lib/accessibility/Behaviors/Popup/popupBehavior.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import * as _ from 'lodash'
44

55
/**
66
* @description
7-
* Adds role='button' to 'trigger' component's part, if it is not focusable element and no role attribute provided.
8-
* Adds tabIndex='0' to 'trigger' component's part, if it is not tabbable element and no tabIndex attribute provided.
9-
* Adds attribute 'aria-disabled=true' to 'trigger' component's part based on the property 'disabled'.
7+
* Adds role='button' to 'trigger' component's part, if it is not focusable element and no role attribute provided.
8+
* Adds tabIndex='0' to 'trigger' component's part, if it is not tabbable element and no tabIndex attribute provided.
9+
*
10+
* @specification
11+
* Adds attribute 'aria-disabled=true' to 'trigger' component's part based on the property 'disabled'.
1012
*/
1113
const popupBehavior: Accessibility = (props: any) => ({
1214
attributes: {

src/lib/accessibility/Behaviors/Popup/popupFocusTrapBehavior.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as _ from 'lodash'
66
* @description
77
* Adds role='button' to 'trigger' component's part, if it is not focusable element and no role attribute provided.
88
* Adds tabIndex='0' to 'trigger' component's part, if it is not tabbable element and no tabIndex attribute provided.
9+
*
10+
* @specification
911
* Adds attribute 'aria-disabled=true' to 'trigger' component's part based on the property 'disabled'.
1012
* Traps focus inside component.
1113
*/

src/lib/accessibility/Behaviors/Radio/radioGroupBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Accessibility } from '../../types'
22
import * as keyboardKey from 'keyboard-key'
33

44
/**
5-
* @description
5+
* @specification
66
* Adds role='radiogroup'. This allows screen readers to handle the component as a radio group.
77
* Performs 'nextItem' action on ArrowDown, ArrowRight.
88
* Performs 'prevItem' action on ArrowUp, ArrowLeft.

src/lib/accessibility/Behaviors/Radio/radioGroupItemBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Accessibility } from '../../types'
22
import * as _ from 'lodash'
33

44
/**
5-
* @description
5+
* @specification
66
* Adds role='radio'. This allows screen readers to handle the component as a radio button.
77
* Adds attribute 'aria-checked=true' based on the property 'checked'.
88
* Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component.

src/lib/accessibility/Behaviors/Tab/tabBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IS_FOCUSABLE_ATTRIBUTE } from '../../FocusZone/focusUtilities'
44
import * as _ from 'lodash'
55

66
/**
7-
* @description
7+
* @specification
88
* Adds role 'presentation' to 'root' component's part.
99
* Adds role 'tab' to 'anchor' component's part.
1010
* Adds attribute 'tabIndex=0' to 'anchor' component's part.

src/lib/accessibility/Behaviors/Tab/tabListBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Accessibility, FocusZoneMode } from '../../types'
22

33
/**
4-
* @description
4+
* @specification
55
* Adds role 'tablist' to 'root' component's part.
66
* Wraps component in FocusZone allowing arrow key navigation through the children of the component.
77
*/

src/lib/accessibility/Behaviors/Toolbar/toolbarBehavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Accessibility, FocusZoneMode } from '../../types'
22

33
/**
4-
* @description
4+
* @specification
55
* Adds role 'toolbar' to 'root' component's part.
66
* Wraps component in FocusZone allowing arrow key navigation through the children of the component.
77
*/

src/lib/accessibility/Behaviors/Toolbar/toolbarButtonBehavior.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import * as _ from 'lodash'
55

66
/**
77
* @description
8+
* The behavior is designed for particular structure of menu item. The item consists of root element and anchor inside the root element.
9+
*
10+
* @specification
811
* Adds role 'presentation' to 'root' component's part.
912
* Adds role 'button' to 'anchor' component's part.
1013
* Adds attribute 'tabIndex=0' to 'anchor' component's part.
@@ -13,7 +16,6 @@ import * as _ from 'lodash'
1316
* Adds attribute 'aria-describedby' based on the property 'aria-describedby' to 'anchor' component's part.
1417
* Adds attribute 'aria-disabled=true' to 'anchor' component's part based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component.
1518
* Performs click action with 'Enter' and 'Spacebar' on 'anchor'.
16-
* The behavior is designed for particular structure of menu item. The item consists of root element and anchor inside the root element.
1719
*/
1820
const toolbarButtonBehavior: Accessibility = (props: any) => ({
1921
attributes: {

0 commit comments

Comments
 (0)