@@ -2,6 +2,7 @@ import Paper from "../../../../../src/values/Paper";
22import EnglishResearcher from "../../../../../src/languageProcessing/languages/en/Researcher" ;
33import InclusiveLanguageAssessment from "../../../../../src/scoring/assessments/inclusiveLanguage/InclusiveLanguageAssessment" ;
44import assessments from "../../../../../src/scoring/assessments/inclusiveLanguage/configuration/appearanceAssessments" ;
5+ import Factory from "../../../../specHelpers/factory" ;
56import Mark from "../../../../../src/values/Mark" ;
67
78describe ( "Appearance assessments" , function ( ) {
@@ -19,18 +20,19 @@ describe( "Appearance assessments", function() {
1920 expect ( assessmentResult . getScore ( ) ) . toEqual ( 6 ) ;
2021 expect ( assessmentResult . getText ( ) ) . toEqual (
2122 "Be careful when using <i>albinos</i> as it is potentially harmful. " +
22- "Consider using an alternative, such as people with albinism, albino people, " +
23+ "Consider using an alternative, such as <i> people with albinism, albino people</i> , " +
2324 "unless referring to someone who explicitly wants to be referred to with this term. " +
2425 "<a href='https://yoa.st/inclusive-language-appearance' target='_blank'>Learn more.</a>" ) ;
2526 expect ( assessmentResult . hasMarks ( ) ) . toBeTruthy ( ) ;
26- expect ( assessor . getMarks ( ) ) . toEqual ( [ new Mark ( {
27- original : mockText ,
28- marked : "<yoastmark class='yoast-text-mark'>" + mockText + "</yoastmark>" ,
29- } ) ] ) ;
27+ expect ( assessor . getMarks ( ) ) . toEqual ( [ { _properties :
28+ { marked : "<yoastmark class='yoast-text-mark'>This ad is aimed at albinos</yoastmark>" ,
29+ original : "This ad is aimed at albinos" ,
30+ fieldsToMark : [ ] ,
31+ } } ] ) ;
3032 } ) ;
3133
3234 it ( "should target potentially non-inclusive phrases" , function ( ) {
33- const mockText = "This ad is aimed at obese citizens" ;
35+ const mockText = "This ad is aimed at obese citizens. " ;
3436 const mockPaper = new Paper ( mockText ) ;
3537 const mockResearcher = new EnglishResearcher ( mockPaper ) ;
3638 const assessor = new InclusiveLanguageAssessment ( assessments . find ( obj => obj . identifier === "obese" ) ) ;
@@ -47,25 +49,29 @@ describe( "Appearance assessments", function() {
4749 "Alternatively, if talking about a specific person, use their preferred descriptor if known. " +
4850 "<a href='https://yoa.st/inclusive-language-appearance' target='_blank'>Learn more.</a>" ) ;
4951 expect ( assessmentResult . hasMarks ( ) ) . toBeTruthy ( ) ;
50- expect ( assessor . getMarks ( ) ) . toEqual ( [ new Mark ( {
51- original : mockText ,
52- marked : "<yoastmark class='yoast-text-mark'>" + mockText + "</yoastmark>" ,
53- } ) ] ) ;
52+ expect ( assessor . getMarks ( ) ) . toEqual ( [
53+ { _properties : {
54+ marked : "<yoastmark class='yoast-text-mark'>This ad is aimed at obese citizens.</yoastmark>" ,
55+ original : "This ad is aimed at obese citizens." ,
56+ fieldsToMark : [ ] ,
57+ } } ] ) ;
5458 } ) ;
5559
5660 it ( "should not target phrases preceded by certain words" , function ( ) {
57- const mockText = "This ad is aimed at vertically challenged people" ;
61+ const mockText = "This ad is aimed at vertically challenged people. " ;
5862 const mockPaper = new Paper ( mockText ) ;
5963 const mockResearcher = new EnglishResearcher ( mockPaper ) ;
6064 const assessor = new InclusiveLanguageAssessment ( assessments . find ( obj => obj . identifier === "verticallyChallenged" ) ) ;
6165
6266 const isApplicable = assessor . isApplicable ( mockPaper , mockResearcher ) ;
6367
6468 expect ( isApplicable ) . toBeTruthy ( ) ;
65- expect ( assessor . getMarks ( ) ) . toEqual ( [ new Mark ( {
66- original : mockText ,
67- marked : "<yoastmark class='yoast-text-mark'>" + mockText + "</yoastmark>" ,
68- } ) ] ) ;
69+ expect ( assessor . getMarks ( ) ) . toEqual ( [
70+ { _properties : {
71+ marked : "<yoastmark class='yoast-text-mark'>This ad is aimed at vertically challenged people.</yoastmark>" ,
72+ original : "This ad is aimed at vertically challenged people." ,
73+ fieldsToMark : [ ] ,
74+ } } ] ) ;
6975 } ) ;
7076
7177 it ( "should not target phrases followed by by certain words" , function ( ) {
@@ -89,4 +95,69 @@ describe( "Appearance assessments", function() {
8995 expect ( isApplicable ) . toBeFalsy ( ) ;
9096 expect ( assessor . getMarks ( ) ) . toEqual ( [ ] ) ;
9197 } ) ;
98+ it ( "correctly identifies 'an albino' which is only recognized when followed by participle or simple past tense" , ( ) => {
99+ const mockPaper = new Paper ( "An albino worked, the better they are." ) ;
100+ const mockResearcher = Factory . buildMockResearcher ( [ "An albino worked, the better they are." ] ) ;
101+ const assessor = new InclusiveLanguageAssessment ( assessments . find ( obj => obj . identifier === "anAlbino" ) ) ;
102+ const isApplicable = assessor . isApplicable ( mockPaper , mockResearcher ) ;
103+ const assessmentResult = assessor . getResult ( ) ;
104+
105+ expect ( isApplicable ) . toBeTruthy ( ) ;
106+ expect ( assessmentResult . getScore ( ) ) . toEqual ( 3 ) ;
107+ expect ( assessmentResult . getText ( ) ) . toEqual (
108+ "Be careful when using <i>an albino</i> as it is potentially harmful. Consider using an alternative, such as " +
109+ "<i>people with albinism, albino people</i>, unless referring to someone who explicitly wants to be referred to with this term. " +
110+ "<a href='https://yoa.st/inclusive-language-appearance' target='_blank'>Learn more.</a>" ) ;
111+ expect ( assessmentResult . hasMarks ( ) ) . toBeTruthy ( ) ;
112+ expect ( assessor . getMarks ( ) ) . toEqual ( [ new Mark ( {
113+ original : "An albino worked, the better they are." ,
114+ marked : "<yoastmark class='yoast-text-mark'>An albino worked, the better they are.</yoastmark>" ,
115+ } ) ] ) ;
116+ } ) ;
117+ it ( "correctly identifies 'an albino', which is only recognized when followed by a function word" , ( ) => {
118+ const mockPaper = new Paper ( "An albino however, did not go to the zoo." ) ;
119+ const mockResearcher = Factory . buildMockResearcher ( [ "An albino however, did not go to the zoo." ] ) ;
120+ const assessor = new InclusiveLanguageAssessment ( assessments . find ( obj => obj . identifier === "anAlbino" ) ) ;
121+ const isApplicable = assessor . isApplicable ( mockPaper , mockResearcher ) ;
122+ const assessmentResult = assessor . getResult ( ) ;
123+
124+ expect ( isApplicable ) . toBeTruthy ( ) ;
125+ expect ( assessmentResult . getScore ( ) ) . toEqual ( 3 ) ;
126+ expect ( assessmentResult . getText ( ) ) . toEqual (
127+ "Be careful when using <i>an albino</i> as it is potentially harmful. Consider using an alternative, such as " +
128+ "<i>people with albinism, albino people</i>, unless referring to someone who explicitly wants to be referred to with this term. " +
129+ "<a href='https://yoa.st/inclusive-language-appearance' target='_blank'>Learn more.</a>" ) ;
130+ expect ( assessmentResult . hasMarks ( ) ) . toBeTruthy ( ) ;
131+ expect ( assessor . getMarks ( ) ) . toEqual ( [ new Mark ( {
132+ original : "An albino however, did not go to the zoo." ,
133+ marked : "<yoastmark class='yoast-text-mark'>An albino however, did not go to the zoo.</yoastmark>" ,
134+ } ) ] ) ;
135+ } ) ;
136+ it ( "correctly identifies 'an albino', which is only recognized when followed by a punctuation mark" , ( ) => {
137+ const mockPaper = new Paper ( "I have always loved an albino!" ) ;
138+ const mockResearcher = Factory . buildMockResearcher ( [ "I have always loved an albino!" ] ) ;
139+ const assessor = new InclusiveLanguageAssessment ( assessments . find ( obj => obj . identifier === "anAlbino" ) ) ;
140+ const isApplicable = assessor . isApplicable ( mockPaper , mockResearcher ) ;
141+ const assessmentResult = assessor . getResult ( ) ;
142+
143+ expect ( isApplicable ) . toBeTruthy ( ) ;
144+ expect ( assessmentResult . getScore ( ) ) . toEqual ( 3 ) ;
145+ expect ( assessmentResult . getText ( ) ) . toEqual (
146+ "Be careful when using <i>an albino</i> as it is potentially harmful. Consider using an alternative, such as " +
147+ "<i>people with albinism, albino people</i>, unless referring to someone who explicitly wants to be referred to with this term. " +
148+ "<a href='https://yoa.st/inclusive-language-appearance' target='_blank'>Learn more.</a>" ) ;
149+ expect ( assessmentResult . hasMarks ( ) ) . toBeTruthy ( ) ;
150+ expect ( assessor . getMarks ( ) ) . toEqual ( [ new Mark ( {
151+ original : "I have always loved an albino!" ,
152+ marked : "<yoastmark class='yoast-text-mark'>I have always loved an albino!</yoastmark>" ,
153+ } ) ] ) ;
154+ } ) ;
155+ it ( "does not identify 'an albino' when not followed by punctuation, function word or participle" , ( ) => {
156+ const mockPaper = new Paper ( "An albino person walks on the street." ) ;
157+ const mockResearcher = Factory . buildMockResearcher ( [ "An albino person walks on the street." ] ) ;
158+ const assessor = new InclusiveLanguageAssessment ( assessments . find ( obj => obj . identifier === "anAlbino" ) ) ;
159+ const isApplicable = assessor . isApplicable ( mockPaper , mockResearcher ) ;
160+
161+ expect ( isApplicable ) . toBeFalsy ( ) ;
162+ } ) ;
92163} ) ;
0 commit comments