diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/ar/arabicPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/ar/arabicPaper.js index 425932b41a8..d79b329e2a6 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/ar/arabicPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/ar/arabicPaper.js @@ -112,7 +112,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/de/germanPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/de/germanPaper.js index 3314cb82141..a054ad05097 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/de/germanPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/de/germanPaper.js @@ -115,7 +115,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. " + + resultText: "Paragraph length: There are no paragraphs that are too long. " + "Great job!", }, textSentenceLength: { diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/en/englishPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/en/englishPaper.js index 8d4b2d3ba19..25c93a79385 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/en/englishPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/en/englishPaper.js @@ -112,7 +112,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/hu/hungarianPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/hu/hungarianPaper.js index 6fd5beeef3f..db239192f14 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/hu/hungarianPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/hu/hungarianPaper.js @@ -112,7 +112,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/nb/norwegianPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/nb/norwegianPaper.js index 5429eee77c7..cab6dd4ebb8 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/nb/norwegianPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/nb/norwegianPaper.js @@ -112,7 +112,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/nl/dutchPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/nl/dutchPaper.js index 382800b7521..d4a51a72336 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/nl/dutchPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/nl/dutchPaper.js @@ -110,7 +110,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/pl/polishPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/pl/polishPaper.js index b0d8408ed8e..81c232939a6 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/pl/polishPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/pl/polishPaper.js @@ -104,7 +104,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/sk/slovakPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/sk/slovakPaper.js index 99449c56617..1bc0b77b32f 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/sk/slovakPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/sk/slovakPaper.js @@ -111,7 +111,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/sv/swedishPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/sv/swedishPaper.js index 9ed8170dad5..0fb8bc07962 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/sv/swedishPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/sv/swedishPaper.js @@ -101,7 +101,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/fullTextTests/testTexts/tr/turkishPaper.js b/packages/yoastseo/spec/fullTextTests/testTexts/tr/turkishPaper.js index 2c69af16c1e..63bc8b6a7b1 100644 --- a/packages/yoastseo/spec/fullTextTests/testTexts/tr/turkishPaper.js +++ b/packages/yoastseo/spec/fullTextTests/testTexts/tr/turkishPaper.js @@ -103,7 +103,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, @@ -111,8 +111,9 @@ const expectedResults = { resultText: "Sentence length: Great!", }, textTransitionWords: { - // This assessment is not applicable to this paper as the text contains less than 200 words. - isApplicable: false, + isApplicable: true, + score: 9, + resultText: "Transition words: Well done!", }, passiveVoice: { isApplicable: true, diff --git a/packages/yoastseo/spec/scoring/assessments/readability/ListAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/ListAssessmentSpec.js index c999d48b070..e6cd31eaa61 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/ListAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/ListAssessmentSpec.js @@ -6,7 +6,7 @@ import buildTree from "../../../specHelpers/parse/buildTree"; const listAssessment = new ListAssessment(); describe( "a test for an assessment that checks whether a paper contains a list or not", function() { - it( "assesses when there are no lists", function() { + it( "returns a bad score when there are no lists", function() { const mockPaper = new Paper( "text with no list" ); const mockResearcher = new EnglishResearcher( mockPaper ); buildTree( mockPaper, mockResearcher ); @@ -17,6 +17,17 @@ describe( "a test for an assessment that checks whether a paper contains a list expect( assessment.getText() ).toEqual( "Lists: " + "No lists appear on this page. Add at least one ordered or unordered list!" ); } ); + it( "returns a bad score when there are is no text", function() { + const mockPaper = new Paper( "" ); + const mockResearcher = new EnglishResearcher( mockPaper ); + buildTree( mockPaper, mockResearcher ); + + const assessment = listAssessment.getResult( mockPaper ); + + expect( assessment.getScore() ).toEqual( 3 ); + expect( assessment.getText() ).toEqual( "Lists: " + + "No lists appear on this page. Add at least one ordered or unordered list!" ); + } ); it( "assesses when there is a list inside an element we want to exclude from the analysis", function() { const mockPaper = new Paper( "
These are the most important things in life:\n" + "\n" + @@ -91,26 +102,6 @@ describe( "a test for an assessment that checks whether a paper contains a list } ); } ); -describe( "tests for the assessment applicability.", function() { - it( "returns false when the paper is empty.", function() { - const paper = new Paper( "" ); - expect( listAssessment.isApplicable( paper ) ).toBe( false ); - } ); - - it( "returns true when the paper is not empty.", function() { - const paper = new Paper( "sample keyword containing a minimum of fifty characters.", { - slug: "sample-with-keyword", - keyword: "kéyword", - } ); - expect( listAssessment.isApplicable( paper ) ).toBe( true ); - } ); - - it( "returns false if the text is too short", function() { - const paper = new Paper( "hallo" ); - expect( listAssessment.isApplicable( paper ) ).toBe( false ); - } ); -} ); - describe( "a test for retrieving the feedback texts", () => { it( "should return the custom feedback texts when `callbacks.getResultTexts` is provided", () => { const assessment = new ListAssessment( { diff --git a/packages/yoastseo/spec/scoring/assessments/readability/ParagraphTooLongAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/ParagraphTooLongAssessmentSpec.js index 5cf0fea9d5f..f8b9b7b0eed 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/ParagraphTooLongAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/ParagraphTooLongAssessmentSpec.js @@ -17,8 +17,8 @@ describe( "An assessment for scoring too long paragraphs.", function() { it( "should score 1 paragraph with ok length", function() { const assessment = paragraphTooLongAssessment.getResult( paper, Factory.buildMockResearcher( [ { paragraphLength: 60 } ] ) ); expect( assessment.getScore() ).toBe( 9 ); - expect( assessment.getText() ).toBe( "Paragraph length: None of the paragraphs" + - " are too long. Great job!" ); + expect( assessment.getText() ).toBe( "Paragraph length:" + + " There are no paragraphs that are too long. Great job!" ); expect( assessment.hasMarks() ).toBe( false ); } ); it( "should score 1 slightly too long paragraph", function() { @@ -41,8 +41,8 @@ describe( "An assessment for scoring too long paragraphs.", function() { const assessment = paragraphTooLongAssessment.getResult( paper, Factory.buildMockResearcher( [ { paragraphLength: 60 }, { paragraphLength: 71 }, { paragraphLength: 83 } ] ) ); expect( assessment.getScore() ).toBe( 9 ); - expect( assessment.getText() ).toBe( "Paragraph length: None of the paragraphs" + - " are too long. Great job!" ); + expect( assessment.getText() ).toBe( "Paragraph length: " + + "There are no paragraphs that are too long. Great job!" ); expect( assessment.hasMarks() ).toBe( false ); } ); it( "should score 3 paragraphs, one of which is too long", function() { @@ -63,10 +63,12 @@ describe( "An assessment for scoring too long paragraphs.", function() { " Shorten your paragraphs!" ); expect( assessment.hasMarks() ).toBe( true ); } ); - it( "should return an empty assessment result for a paper without paragraphs.", function() { + it( "should return a good result for a paper without paragraphs.", function() { const assessment = paragraphTooLongAssessment.getResult( paper, Factory.buildMockResearcher( [ ] ) ); - expect( assessment.getScore() ).toBe( 0 ); - expect( assessment.getText() ).toBe( "" ); + expect( assessment.getScore() ).toBe( 9 ); + expect( assessment.getText() ).toBe( "Paragraph length: " + + "There are no paragraphs that are too long. Great job!" ); + expect( assessment.hasMarks() ).toBe( false ); } ); } ); @@ -113,29 +115,6 @@ describe( "An assessment for scoring too long paragraphs in Japanese in which ch } ); } ); -describe( "Applicability of the assessment.", function() { - it( "should return true for isApplicable on a paper with text.", function() { - const paper = new Paper( "This is a very interesting paper. With at least fifty characters." ); - expect( paragraphTooLongAssessment.isApplicable( paper ) ).toBe( true ); - } ); - it( "should return false for isApplicable on a paper without text.", function() { - const paper = new Paper( "" ); - expect( paragraphTooLongAssessment.isApplicable( paper ) ).toBe( false ); - } ); - it( "should return false for isApplicable for a paper with only an image.", function() { - const paper = new Paper( "
" ); - expect( paragraphTooLongAssessment.isApplicable( paper ) ).toBe( false ); - } ); - it( "should return false for isApplicable for a paper with only spaces.", function() { - const paper = new Paper( " " ); - expect( paragraphTooLongAssessment.isApplicable( paper ) ).toBe( false ); - } ); - it( "returns false if the text is too short", function() { - const paper = new Paper( "hallo" ); - expect( paragraphTooLongAssessment.isApplicable( paper ) ).toBe( false ); - } ); -} ); - describe( "A test for marking the sentences", function() { it( "should return markers for a default text", function() { const paper = new Paper( "
You just got Yoast SEO, and you are ready to get the most out of it! Or, have you already been using it for a " + @@ -335,7 +314,7 @@ describe( "test for paragraph too long assessment when is used in product page a ] ) ); expect( result.getScore() ).toEqual( 9 ); expect( result.getText() ).toEqual( "Paragraph length: " + - "None of the paragraphs are too long. Great job!" ); + "There are no paragraphs that are too long. Great job!" ); } ); it( "should assess a paper on a product page with paragraphs that contain more than 100 words", function() { const paper = new Paper( "" ); @@ -390,7 +369,7 @@ describe( "test for paragraph too long assessment for languages that have langua const result = new ParagraphTooLongAssessment().getResult( paper, mockResearcher ); expect( result.getScore() ).toEqual( 9 ); expect( result.getText() ).toEqual( "Paragraph length: " + - "None of the paragraphs are too long. Great job!" ); + "There are no paragraphs that are too long. Great job!" ); } ); it( "should assess a paper with two paragraphs that contain more than 400 characters (red bullet)", function() { const paper = new Paper( "" ); @@ -440,7 +419,7 @@ describe( "test for paragraph too long assessment for languages that have langua const result = new ParagraphTooLongAssessment( {}, true ).getResult( paper, mockResearcher ); expect( result.getScore() ).toEqual( 9 ); expect( result.getText() ).toEqual( "Paragraph length: " + - "None of the paragraphs are too long. Great job!" ); + "There are no paragraphs that are too long. Great job!" ); } ); it( "should assess a paper with three paragraphs that contain more than 200 characters (red bullet)", function() { const paper = new Paper( "" ); diff --git a/packages/yoastseo/spec/scoring/assessments/readability/PassiveVoiceAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/PassiveVoiceAssessmentSpec.js index 4d196e87f32..54c97ad7ec0 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/PassiveVoiceAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/PassiveVoiceAssessmentSpec.js @@ -67,38 +67,13 @@ describe( "An assessment for scoring passive voice.", function() { } ); describe( "A test for checking the applicability", function() { - it( "returns true for isApplicable for an English paper with text.", function() { - const paper = new Paper( "This is a very interesting paper. With at least 50 characters.", { locale: "en_US" } ); + it( "returns true if the researcher has the passive voice research.", function() { + const paper = new Paper( "This is a very interesting paper.", { locale: "en_US" } ); expect( new PassiveVoiceAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( true ); } ); - it( "should return false for isApplicable for a paper with only an image.", function() { - const paper = new Paper( "
" ); - expect( new PassiveVoiceAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only spaces.", function() { - const paper = new Paper( " " ); - expect( new PassiveVoiceAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "returns false if the text is too short", function() { - const paper = new Paper( "hallo" ); - expect( new PassiveVoiceAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "returns false for isApplicable for an Afrikaans paper with text.", function() { - const paper = new Paper( "Hierdie is 'n interessante papier.", { locale: "af_ZA" } ); - expect( new PassiveVoiceAssessment().isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); - } ); - - it( "returns false for isApplicable for an English paper without text.", function() { - const paper = new Paper( "", { locale: "en_US" } ); - expect( new PassiveVoiceAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "returns false for isApplicable for an Afrikaans paper without text.", function() { - const paper = new Paper( "", { locale: "af_ZA" } ); + it( "returns false if the researcher doesn't have the passive voice research.", function() { + const paper = new Paper( "This is a very interesting paper.' alt='test'>" ); expect( new PassiveVoiceAssessment().isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); } ); } ); diff --git a/packages/yoastseo/spec/scoring/assessments/readability/SentenceBeginningsAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/SentenceBeginningsAssessmentSpec.js index 72a4cf3549b..0613012dc29 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/SentenceBeginningsAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/SentenceBeginningsAssessmentSpec.js @@ -40,34 +40,20 @@ describe( "An assessment for scoring repeated sentence beginnings.", function() "There is enough variety in your sentences. That's great!" ); } ); - it( "is not applicable for a paper without text and a researcher that has the getSentenceBeginnings research.", function() { - paper = new Paper( "", { locale: "it_IT" } ); - const assessment = new SentenceBeginningsAssessment().isApplicable( paper, new ItalianResearcher( paper ) ); - expect( assessment ).toBe( false ); + it( "returns a good score when there are no words in the text.", function() { + const assessment = new SentenceBeginningsAssessment().getResult( paper, Factory.buildMockResearcher( [] ) ); + expect( assessment.getScore() ).toBe( 9 ); + expect( assessment.getText() ).toBe( "Consecutive sentences: " + + "There is enough variety in your sentences. That's great!" ); } ); - it( "is applicable for an paper with text and a researcher that has the getSentenceBeginnings research.", function() { - paper = new Paper( "Era una gatta, assai trita, e non era d’alcuno, e, vecchia, aveva un suo gattino.", { locale: "it_IT" } ); + it( "is applicable when the researcher that has the getSentenceBeginnings research.", function() { + paper = new Paper( "", { locale: "it_IT" } ); const assessment = new SentenceBeginningsAssessment().isApplicable( paper, new ItalianResearcher( paper ) ); expect( assessment ).toBe( true ); } ); - it( "returns false if the text is too short", function() { - paper = new Paper( "hallo" ); - expect( new SentenceBeginningsAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only an image.", function() { - paper = new Paper( "
" ); - expect( new SentenceBeginningsAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only spaces.", function() { - paper = new Paper( " " ); - expect( new SentenceBeginningsAssessment().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "is not applicable for a paper with text and a researcher without sentence beginning support.", function() { + it( "is not applicable when the researcher doesn't have the sentence beginning support.", function() { paper = new Paper( "hello", { locale: "jv_ID" } ); const assessment = new SentenceBeginningsAssessment().isApplicable( paper, new DefaultResearcher( paper ) ); expect( assessment ).toBe( false ); diff --git a/packages/yoastseo/spec/scoring/assessments/readability/SentenceLengthInTextAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/SentenceLengthInTextAssessmentSpec.js index e3bb9e5c17a..229ffd9de4c 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/SentenceLengthInTextAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/SentenceLengthInTextAssessmentSpec.js @@ -32,6 +32,19 @@ describe( "An assessment for sentence length", function() { expect( assessment.hasMarks() ).toBe( false ); } ); + it( "returns a good score if there is no text", function() { + const mockPaper = new Paper( "" ); + const mockResearcher = new DefaultResearcher( mockPaper ); + buildTree( mockPaper, mockResearcher ); + + const assessment = new SentenceLengthInTextAssessment().getResult( mockPaper, mockResearcher ); + + expect( assessment.hasScore() ).toBe( true ); + expect( assessment.getScore() ).toEqual( 9 ); + expect( assessment.getText() ).toEqual( "Sentence length: Great!" ); + expect( assessment.hasMarks() ).toBe( false ); + } ); + it( "returns the score for 50% long sentences using the default config", function() { const mockPaper = new Paper( shortSentenceDefault + longSentenceDefault ); const mockResearcher = new DefaultResearcher( mockPaper ); @@ -310,24 +323,6 @@ describe( "An assessment for sentence length", function() { expect( assessment.getText() ).toEqual( "Sentence length: Great!" ); expect( assessment.hasMarks() ).toBe( true ); } ); - - it( "is not applicable for empty papers", function() { - const mockPaper = new Paper(); - const assessment = new SentenceLengthInTextAssessment().isApplicable( mockPaper ); - expect( assessment ).toBe( false ); - } ); - - it( "returns false if the text is too short", function() { - const paper = new Paper( "hallo" ); - const assessment = new SentenceLengthInTextAssessment().isApplicable( paper ); - expect( assessment ).toBe( false ); - } ); - - it( "returns true if the text is long enough", function() { - const paper = new Paper( "hallo".repeat( 100 ) ); - const assessment = new SentenceLengthInTextAssessment().isApplicable( paper ); - expect( assessment ).toBe( true ); - } ); } ); describe( "A test for getting the right scoring config", function() { diff --git a/packages/yoastseo/spec/scoring/assessments/readability/SubheadingDistributionTooLongAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/SubheadingDistributionTooLongAssessmentSpec.js index 15dddb1e931..c941e3e6a81 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/SubheadingDistributionTooLongAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/SubheadingDistributionTooLongAssessmentSpec.js @@ -4,7 +4,6 @@ import Factory from "../../../../src/helpers/factory.js"; import Mark from "../../../../src/values/Mark.js"; import CornerstoneContentAssessor from "../../../../src/scoring/assessors/cornerstone/contentAssessor.js"; import ProductCornerstoneContentAssessor from "../../../../src/scoring/assessors/productPages/cornerstone/contentAssessor.js"; -import DefaultResearcher from "../../../../src/languageProcessing/languages/_default/Researcher.js"; import EnglishResearcher from "../../../../src/languageProcessing/languages/en/Researcher.js"; import JapaneseResearcher from "../../../../src/languageProcessing/languages/ja/Researcher.js"; import japaneseConfig from "../../../../src/languageProcessing/languages/ja/config/subheadingsTooLong.js"; @@ -29,6 +28,17 @@ describe( "An assessment for scoring too long text fragments without a subheadin "You are not using any subheadings, but your text is short enough and probably doesn't need them." ); } ); + it( "returns a good score when the paper has no text", function() { + const assessment = new SubheadingDistributionTooLong(); + const result = assessment.getResult( + new Paper( "" ), + Factory.buildMockResearcher( [] ) + ); + expect( result.getScore() ).toBe( 9 ); + expect( result.getText() ).toBe( "Subheading distribution: " + + "You are not using any subheadings, but your text is short enough and probably doesn't need them." ); + } ); + it( "Scores a text that's short (<300 words) after excluding elements we don't want to analyze," + " and which does not have subheadings.", function() { const assessment = new SubheadingDistributionTooLong(); @@ -409,75 +419,6 @@ describe( "An assessment for scoring too long text fragments without a subheadin } ); } ); -describe( "A test for the assessment applicability", () => { - it( "Returns false from isApplicable to the paper without text", function() { - const paper = new Paper( "" ); - const assessment = new SubheadingDistributionTooLong(); - const isApplicable = assessment.isApplicable( paper, new DefaultResearcher( paper ) ); - expect( isApplicable ).toBe( false ); - } ); - - it( "Returns true from isApplicable to the paper with text longer than 50 characters", function() { - const paper = new Paper( shortText ); - const assessment = new SubheadingDistributionTooLong(); - const isApplicable = assessment.isApplicable( paper ); - expect( isApplicable ).toBe( true ); - } ); - - it( "returns false if the text is less than 50 characters", function() { - const paper = new Paper( "hallo" ); - expect( new SubheadingDistributionTooLong().isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); - } ); - - it( "returns false if the text is less than 50 characters after excluding text inside elements we don't want to analyze", function() { - const paper = new Paper( "
" + longText + "" ); - const assessment = new SubheadingDistributionTooLong( { shouldNotAppearInShortText: true } ); - expect( assessment.isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only an image.", function() { - const paper = new Paper( "" ); - expect( new SubheadingDistributionTooLong().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only spaces.", function() { - const paper = new Paper( " " ); - expect( new SubheadingDistributionTooLong().isApplicable( paper, new EnglishResearcher( paper ) ) ).toBe( false ); - } ); - it( "Returns false when the assessment shouldn't appear in short text analysis and the paper is empty", function() { - const paper = new Paper( "" ); - const assessment = new SubheadingDistributionTooLong( { shouldNotAppearInShortText: true } ); - expect( assessment.isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); - } ); - - it( "Returns true when the assessment shouldn't appear in short text analysis but the text contains more than 300 words", function() { - const paper = new Paper( longText ); - const assessment = new SubheadingDistributionTooLong( { shouldNotAppearInShortText: true } ); - expect( assessment.isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( true ); - } ); - - it( "Returns false when the assessment shouldn't appear in short text analysis and the text contains less than 300 words", function() { - const paper = new Paper( shortText ); - const assessment = new SubheadingDistributionTooLong( { shouldNotAppearInShortText: true } ); - expect( assessment.isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); - } ); - - it( "Returns false when the assessment shouldn't appear in short text analysis and the text contains less " + - "than 600 characters in Japanese", function() { - const paper = new Paper( shortTextJapanese ); - const assessment = new SubheadingDistributionTooLong( { shouldNotAppearInShortText: true } ); - expect( assessment.isApplicable( paper, new JapaneseResearcher( paper ) ) ).toBe( false ); - } ); - - it( "Returns true when the assessment shouldn't appear in short text analysis but the text contains more " + - "than 600 characters in Japanese", function() { - const paper = new Paper( longTextJapanese ); - const assessment = new SubheadingDistributionTooLong( { shouldNotAppearInShortText: true } ); - expect( assessment.isApplicable( paper, new JapaneseResearcher( paper ) ) ).toBe( true ); - } ); -} ); - - describe( "Language-specific configuration for specific types of content is used: English", function() { const mockPaper = new Paper( "" ); const mockOptions = { subheadingUrlTitle: "https://yoa.st/34x", subheadingCTAUrl: "https://yoa.st/34y" }; diff --git a/packages/yoastseo/spec/scoring/assessments/readability/TextAlignmentAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/TextAlignmentAssessmentSpec.js index 43618f92a96..14ce04e9d2a 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/TextAlignmentAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/TextAlignmentAssessmentSpec.js @@ -323,20 +323,13 @@ describe( "tests for retrieving the feedback strings.", function() { } ); describe( "tests for the assessment's applicability.", function() { - it( "returns false when the paper is empty.", function() { - const paperWithNoText = new Paper( "" ); - const researcher = new EnglishResearcher( paperWithNoText ); - researcher.addResearch( "getLongCenterAlignedTexts", getLongCenterAlignedTexts ); - expect( textAlignmentAssessment.isApplicable( paperWithNoText, researcher ) ).toBe( false ); - } ); - it( "returns false when the researcher doesn't have the research.", function() { const mockPaper = new Paper( "
This is a paragraph with a bit more than fifty characters.
" ); const researcher = new EnglishResearcher( mockPaper ); expect( textAlignmentAssessment.isApplicable( mockPaper, researcher ) ).toBe( false ); } ); - it( "returns true when the paper has more than 50 characters and the researcher has the research.", function() { + it( "returns true when the researcher has the research.", function() { const mockPaper = new Paper( "This is a paragraph with a bit more than fifty characters.
" ); const researcher = new EnglishResearcher( mockPaper ); researcher.addResearch( "getLongCenterAlignedTexts", getLongCenterAlignedTexts ); diff --git a/packages/yoastseo/spec/scoring/assessments/readability/TransitionWordsAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/TransitionWordsAssessmentSpec.js index 5e866ed1ffc..c4ed1ec0957 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/TransitionWordsAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/TransitionWordsAssessmentSpec.js @@ -6,12 +6,14 @@ import Paper from "../../../../src/values/Paper.js"; import Factory from "../../../../src/helpers/factory.js"; import Mark from "../../../../src/values/Mark.js"; -const shortTextJapanese = "熱".repeat( 399 ); +const shortText = "a ".repeat( 199 ); +const longText = "a ".repeat( 201 ); +const shortTextJapanese = "熱".repeat( 390 ); const longTextJapanese = "熱".repeat( 400 ); -describe( "An assessment for transition word percentage", function() { - it( "returns the score for 0% of the sentences with transition words", function() { - const mockPaper = new Paper(); +describe( "An assessment for checking the percentage of transition words in the text", function() { + it( "returns the score for 0% of the sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 10, transitionWordSentences: 0 } ) ); @@ -21,8 +23,8 @@ describe( "An assessment for transition word percentage", function() { expect( assessment.hasMarks() ).toBe( false ); } ); - it( "returns the score for a paper with text but no sentences (e.g. only images)", function() { - const mockPaper = new Paper(); + it( "returns the score for a paper with a long text but no sentences (e.g. only images)", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 0, transitionWordSentences: 0 } ) ); @@ -32,8 +34,8 @@ describe( "An assessment for transition word percentage", function() { expect( assessment.hasMarks() ).toBe( false ); } ); - it( "returns the score for 10.0% of the sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 10.0% of the sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 10, transitionWordSentences: 1 } ) ); @@ -43,8 +45,8 @@ describe( "An assessment for transition word percentage", function() { "target='_blank'>Use more of them." ); expect( assessment.hasMarks() ).toBe( true ); } ); - it( "returns the score for 20.0% of the sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 20.0% of the sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 5, transitionWordSentences: 1 } ) ); @@ -54,8 +56,8 @@ describe( "An assessment for transition word percentage", function() { "target='_blank'>Use more of them." ); expect( assessment.hasMarks() ).toBe( true ); } ); - it( "returns the score for 25.0% of the sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 25.0% of the sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 4, transitionWordSentences: 1 } ) ); @@ -65,16 +67,16 @@ describe( "An assessment for transition word percentage", function() { "target='_blank'>Use more of them." ); expect( assessment.hasMarks() ).toBe( true ); } ); - it( "returns the score for 35.0% of the sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 35.0% of the sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 20, transitionWordSentences: 7 } ) ); expect( assessment.getScore() ).toEqual( 9 ); expect( assessment.getText() ).toEqual( "Transition words: Well done!" ); expect( assessment.hasMarks() ).toBe( true ); } ); - it( "returns the score for 40% sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 40% sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 10, transitionWordSentences: 4 } ) ); expect( assessment.getScore() ).toEqual( 9 ); @@ -82,8 +84,8 @@ describe( "An assessment for transition word percentage", function() { expect( assessment.hasMarks() ).toBe( true ); } ); - it( "returns the score for 47% sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 47% sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 100, transitionWordSentences: 47 } ) ); expect( assessment.getScore() ).toEqual( 9 ); @@ -91,8 +93,8 @@ describe( "An assessment for transition word percentage", function() { expect( assessment.hasMarks() ).toBe( true ); } ); - it( "returns the score for 66.7% of the sentences with transition words", function() { - const mockPaper = new Paper(); + it( "returns the score for 66.7% of the sentences with transition words in a long text", function() { + const mockPaper = new Paper( longText ); const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 3, transitionWordSentences: 2 } ) ); @@ -113,62 +115,72 @@ describe( "An assessment for transition word percentage", function() { expect( result.getText() ).toEqual( "Transition words: Well done!" ); } ); - it( "is not applicable for empty papers", function() { - const mockPaper = new Paper(); - const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new EnglishResearcher( mockPaper ) ); - expect( assessment ).toBe( false ); + it( "returns the score for a short text with a low percentage of sentences with transition words", function() { + const mockPaper = new Paper( shortText ); + const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 10, + transitionWordSentences: 1 } ) ); + + expect( assessment.getScore() ).toEqual( 9 ); + expect( assessment.getText() ).toEqual( "Transition words: Well done!" ); + expect( assessment.hasMarks() ).toBe( true ); } ); - it( "is not applicable when the text is less than 200 words", function() { - const mockPaper = new Paper( "Lorem ipsum dolor sit amet, ne sed agam oblique alterum. Eos percipit singulis no. No scripta graecis cum. " + - "Ut vim eius porro labore. Id quem civibus sit. Sed no primis urbanitas, aperiri laboramus voluptatibus ei per. Esse consul possim " + - "duo eu, eu duo natum ferri libris. Tritani percipit interpretaris ne ius. Mel prima definitionem eu, partem labores vim at. " + - "Prompta vivendum usu te. Indoctum philosophia definitiones usu ad, cum quodsi alienum et. " ); - const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new EnglishResearcher( mockPaper ) ); - expect( assessment ).toBe( false ); + it( "returns the score for a short text with no transition words", function() { + const mockPaper = new Paper( shortText ); + const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 10, + transitionWordSentences: 0 } ) ); + + expect( assessment.getScore() ).toEqual( 9 ); + expect( assessment.getText() ).toEqual( "Transition words:" + + " You are not using any transition words, but your text is short enough and probably doesn't need them." ); + expect( assessment.hasMarks() ).toBe( false ); } ); + it( "returns a good score if the paper has no text", function() { + const mockPaper = new Paper( "" ); + const assessment = new TransitionWordsAssessment().getResult( mockPaper, Factory.buildMockResearcher( { totalSentences: 0, + transitionWordSentences: 0 } ) ); - it( "is not applicable when the text is more than 200 words but the text is inside an element we want to exclude from the analysis", function() { - const mockPaper = new Paper( "Lorem ipsum dolor sit amet, ne sed agam oblique alterum. Eos percipit singulis no." + - " No scripta graecis cum. Ut vim eius porro labore. Id quem civibus sit. Sed no primis urbanitas, aperiri laboramus voluptatibus" + - " ei per. Esse consul possim duo eu, eu duo natum ferri libris. Tritani percipit interpretaris ne ius. Mel prima definitionem eu," + - " partem labores vim at. Prompta vivendum usu te. Indoctum philosophia definitiones usu ad, cum quodsi alienum et. " + - "Sumo civibus appareat est ea, in iriure euismod dolores mel. Mea scripta senserit maluisset ei." + - " Vel id mollis delicata constituam, laoreet scriptorem his cu, " + - "facilis accusam quaerendum nam in. Adversarium philosophia deterruisset duo at, augue postulant ut eos, usu ne iuvaret docendi. " + - "Iudicabit eloquentiam usu no. Vide volumus pri ne. Eos ignota timeam ponderum ei, an postea principes prodesset sit, " + - "purto blandit offendit pro an. Ei vim ludus veniam mnesarchum. Ne modus consul dolorem his, solum alienum eu nec. " + - "Mea legendos deserunt quaerendum te, fierent fabellas eu per. Ei sea accumsan fabellas signiferumque. Veri ludus aperiri his at, " + - "meis dicant impedit an qui. Est error offendit ex, at affert mediocrem interpretaris nam. Percipit persecuti et mel, persecuti " + - "inciderint signiferumque cu usu, an sit nemore nusquam. Brute iracundia sea ei, ad esse dictas aliquam est, prompta ceteros " + - "aliquando ne vix. Fabulas voluptua eu vel. Ceteros euripidis has cu. Pro ea esse ignota perfecto, ius noluisse liberavisse ei. " + - "Has possim mediocritatem in. Paulo alienum accusamus pro cu, magna labore sit ad. Sumo paulo sea in, cum te latine " + - "labores inciderint." ); - const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new EnglishResearcher( mockPaper ) ); - expect( assessment ).toBe( false ); + expect( assessment.getScore() ).toEqual( 9 ); + expect( assessment.getText() ).toEqual( "Transition words:" + + " You are not using any transition words, but your text is short enough and probably doesn't need them." ); + expect( assessment.hasMarks() ).toBe( false ); } ); +} ); +describe( "An assessment for checking the percentage of transition words in a Japanese text ", function() { + it( "returns the score for a short Japanese text with a low percentage of sentences with transition words.", function() { + const mockPaper = new Paper( "ならば。" + shortTextJapanese ); + const mockResearcher = new JapaneseResearcher( mockPaper ); + const assessment = new TransitionWordsAssessment().getResult( mockPaper, mockResearcher ); - it( "should not be applicable if the text has more than 200 words, but part of the words are shortcodes", function() { - const mockPaper = new Paper( "Text " + "text ".repeat( 198 ) + "[shortcode]".repeat( 2 ), { shortcodes: [ "shortcode" ] } ); - const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new EnglishResearcher( mockPaper ) ); - expect( assessment ).toBe( false ); + expect( assessment.getScore() ).toEqual( 9 ); + expect( assessment.getText() ).toEqual( "Transition words: Well done!" ); + expect( assessment.hasMarks() ).toBe( true ); + } ); + it( "returns the score for a short Japanese text with no transition words.", function() { + const mockPaper = new Paper( shortTextJapanese ); + const mockResearcher = new JapaneseResearcher( mockPaper ); + const assessment = new TransitionWordsAssessment().getResult( mockPaper, mockResearcher ); + + expect( assessment.getScore() ).toEqual( 9 ); + expect( assessment.getText() ).toEqual( "Transition words:" + + " You are not using any transition words, but your text is short enough and probably doesn't need them." ); + expect( assessment.hasMarks() ).toBe( false ); + } ); + it( "returns the score for a long Japanese text with no transition words.", function() { + const mockPaper = new Paper( longTextJapanese ); + const mockResearcher = new JapaneseResearcher( mockPaper ); + const assessment = new TransitionWordsAssessment().getResult( mockPaper, mockResearcher ); + + expect( assessment.getScore() ).toEqual( 3 ); + expect( assessment.getText() ).toEqual( "Transition words: " + + "None of the sentences contain transition words. Use some." ); + expect( assessment.hasMarks() ).toBe( false ); } ); +} ); +describe( "A test for applicability", function() { it( "is applicable when used with a supported researcher, e.g. the English researcher", function() { - const mockPaper = new Paper( "Lorem ipsum dolor sit amet, ne sed agam oblique alterum. Eos percipit singulis no. No scripta graecis cum. " + - "Ut vim eius porro labore. Id quem civibus sit. Sed no primis urbanitas, aperiri laboramus voluptatibus ei per. Esse consul possim " + - "duo eu, eu duo natum ferri libris. Tritani percipit interpretaris ne ius. Mel prima definitionem eu, partem labores vim at. " + - "Prompta vivendum usu te. Indoctum philosophia definitiones usu ad, cum quodsi alienum et. Sumo civibus appareat est ea, " + - "in iriure euismod dolores mel. Mea scripta senserit maluisset ei. Vel id mollis delicata constituam, laoreet scriptorem his cu, " + - "facilis accusam quaerendum nam in. Adversarium philosophia deterruisset duo at, augue postulant ut eos, usu ne iuvaret docendi. " + - "Iudicabit eloquentiam usu no. Vide volumus pri ne. Eos ignota timeam ponderum ei, an postea principes prodesset sit, " + - "purto blandit offendit pro an. Ei vim ludus veniam mnesarchum. Ne modus consul dolorem his, solum alienum eu nec. " + - "Mea legendos deserunt quaerendum te, fierent fabellas eu per. Ei sea accumsan fabellas signiferumque. Veri ludus aperiri his at, " + - "meis dicant impedit an qui. Est error offendit ex, at affert mediocrem interpretaris nam. Percipit persecuti et mel, persecuti " + - "inciderint signiferumque cu usu, an sit nemore nusquam. Brute iracundia sea ei, ad esse dictas aliquam est, prompta ceteros " + - "aliquando ne vix. Fabulas voluptua eu vel. Ceteros euripidis has cu. Pro ea esse ignota perfecto, ius noluisse liberavisse ei. " + - "Has possim mediocritatem in. Paulo alienum accusamus pro cu, magna labore sit ad. Sumo paulo sea in, cum te latine " + - "labores inciderint.", { locale: "en_US" } ); + const mockPaper = new Paper( "Lorem ipsum dolor sit amet, ne sed agam oblique alterum.", { locale: "en_US" } ); const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new EnglishResearcher( mockPaper ) ); expect( assessment ).toBe( true ); } ); @@ -178,18 +190,6 @@ describe( "An assessment for transition word percentage", function() { const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new DefaultResearcher( mockPaper ) ); expect( assessment ).toBe( false ); } ); - - it( "is not applicable when the text is less than 400 characters in Japanese", function() { - const mockPaper = new Paper( shortTextJapanese ); - const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new JapaneseResearcher( mockPaper ) ); - expect( assessment ).toBe( false ); - } ); - - it( "is applicable when the text is 400 characters or longer in Japanese", function() { - const mockPaper = new Paper( longTextJapanese ); - const assessment = new TransitionWordsAssessment().isApplicable( mockPaper, new JapaneseResearcher( mockPaper ) ); - expect( assessment ).toBe( true ); - } ); } ); describe( "A test for marking sentences containing a transition word", function() { diff --git a/packages/yoastseo/spec/scoring/assessments/readability/WordComplexityAssessmentSpec.js b/packages/yoastseo/spec/scoring/assessments/readability/WordComplexityAssessmentSpec.js index e9bf4e0770f..7a673e85164 100644 --- a/packages/yoastseo/spec/scoring/assessments/readability/WordComplexityAssessmentSpec.js +++ b/packages/yoastseo/spec/scoring/assessments/readability/WordComplexityAssessmentSpec.js @@ -125,6 +125,17 @@ describe( "a test for an assessment that checks complex words in a text", functi ]; expect( assessment.getMarks( runningPaper, researcher ) ).toEqual( expected ); } ); + it( "should return with score 9 if there are no words in the text", function() { + const paper = new Paper( "" ); + researcher.setPaper( paper ); + + const result = assessment.getResult( paper, researcher ); + + expect( result.getScore() ).toBe( 9 ); + expect( result.getText() ).toBe( "Word complexity: " + + "You are not using too many complex words, which makes your text easy to read. Good job!" ); + expect( result.hasMarks() ).toBe( false ); + } ); } ); describe( "tests for the assessment applicability", function() { @@ -139,54 +150,18 @@ describe( "tests for the assessment applicability", function() { researcher.addResearchData( "morphology", morphologyData ); } ); - it( "returns false if there is no text available.", function() { - const paper = new Paper( "" ); - researcher.setPaper( paper ); - expect( assessment.isApplicable( paper, researcher ) ).toBe( false ); - } ); - - it( "returns false if the text is too short", function() { - const paper = new Paper( "hallo" ); - researcher.setPaper( paper ); - - expect( assessment.isApplicable( paper, researcher ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only an image.", function() { - const paper = new Paper( "" ); - researcher.setPaper( paper ); - - expect( assessment.isApplicable( paper, researcher ) ).toBe( false ); - } ); - - it( "should return false for isApplicable for a paper with only spaces.", function() { - const paper = new Paper( " " ); - researcher.setPaper( paper ); - - expect( assessment.isApplicable( paper, researcher ) ).toBe( false ); - } ); - - it( "should return true for isApplicable if the paper has enough content and the researcher has the wordComplexity research", () => { + it( "should return true for isApplicable if the researcher has the wordComplexity research", () => { const paper = new Paper( "Also called torties for short, tortoiseshell cats combine two colors other than white, " + - "either closely mixed or in larger patches." + - " The colors are often described as red and black, but the \"red\" patches can instead be orange, yellow, or cream," + - " and the \"black\" can instead be chocolate, gray, tabby, or blue. Tortoiseshell cats with the tabby " + - "pattern as one of their colors " + - "are sometimes referred to as a torbie. Cats having torbie coats are sometimes referred to as torbie cats.\n" + - "\"Tortoiseshell\" is typically reserved for particolored cats with relatively small or no white markings. " ); + "either closely mixed or in larger patches." ); researcher.setPaper( paper ); expect( assessment.isApplicable( paper, researcher ) ).toBe( true ); } ); } ); - it( "should return false for isApplicable if the paper has enough content but the researcher doesn't have the wordComplexity research", () => { + it( "should return false for isApplicable if the the researcher doesn't have the wordComplexity research", () => { const paper = new Paper( "Also called torties for short, tortoiseshell cats combine two colors other than white, " + - "either closely mixed or in larger patches." + - " The colors are often described as red and black, but the \"red\" patches can instead be orange, yellow, or cream," + - " and the \"black\" can instead be chocolate, gray, tabby, or blue. Tortoiseshell cats with the tabby pattern as one of their colors " + - "are sometimes referred to as a torbie. Cats having torbie coats are sometimes referred to as torbie cats.\n" + - "\"Tortoiseshell\" is typically reserved for particolored cats with relatively small or no white markings. " ); + "either closely mixed or in larger patches." ); expect( assessment.isApplicable( paper, new DefaultResearcher( paper ) ) ).toBe( false ); } ); } ); diff --git a/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper1.js b/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper1.js index 778a3072204..f4e9ca73290 100644 --- a/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper1.js +++ b/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper1.js @@ -83,12 +83,15 @@ const expectedResults = { isApplicable: false, }, subheadingsTooLong: { - isApplicable: false, + isApplicable: true, + score: 9, + resultText: "Subheading distribution: You are not using any subheadings," + + " but your text is short enough and probably doesn't need them.", }, textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper2.js b/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper2.js index 5f3f5bc5372..de3c9b2b528 100644 --- a/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper2.js +++ b/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper2.js @@ -84,12 +84,15 @@ const expectedResults = { isApplicable: false, }, subheadingsTooLong: { - isApplicable: false, + isApplicable: true, + score: 9, + resultText: "Subheading distribution: You are not using any subheadings," + + " but your text is short enough and probably doesn't need them.", }, textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, @@ -97,7 +100,9 @@ const expectedResults = { resultText: "Sentence length: Great!", }, textTransitionWords: { - isApplicable: false, + isApplicable: true, + score: 9, + resultText: "Transition words: Well done!", }, passiveVoice: { isApplicable: true, diff --git a/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper3.js b/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper3.js index 0dac860a15c..ee8f5785892 100644 --- a/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper3.js +++ b/packages/yoastseo/spec/scoring/assessors/collectionPages/fullTextTests/testTexts/en/englishPaper3.js @@ -91,7 +91,7 @@ const expectedResults = { textParagraphTooLong: { isApplicable: true, score: 9, - resultText: "Paragraph length: None of the paragraphs are too long. Great job!", + resultText: "Paragraph length: There are no paragraphs that are too long. Great job!", }, textSentenceLength: { isApplicable: true, diff --git a/packages/yoastseo/spec/scoring/assessors/productPages/contentAssessorSpec.js b/packages/yoastseo/spec/scoring/assessors/productPages/contentAssessorSpec.js index 9feb561c502..802bb5c5380 100644 --- a/packages/yoastseo/spec/scoring/assessors/productPages/contentAssessorSpec.js +++ b/packages/yoastseo/spec/scoring/assessors/productPages/contentAssessorSpec.js @@ -20,7 +20,7 @@ const options = { describe( "A product page content assessor", function() { describe( "Checks the applicable assessments for text containing less than 300 words", function() { - it( "Should have 5 available assessments for a fully supported language. " + + it( "Should have 6 available assessments for a fully supported language. " + "This doesn't include Word complexity and Lists assessments since the registration is done from Shopify side.", function() { const paper = new Paper( "Lorem ipsum dolor sit amet, voluptua probatus ullamcorper id vis, ceteros consetetur qui ea, " + "nam movet populo aliquam te. His eu debitis fastidii. Pri ea amet dicant. Ut his suas corpora, eu reformidans " + @@ -42,6 +42,7 @@ describe( "A product page content assessor", function() { }; const actual = contentAssessor.getApplicableAssessments().map( result => result.identifier ); const expected = [ + "subheadingsTooLong", "textParagraphTooLong", "textSentenceLength", "textTransitionWords", @@ -51,7 +52,7 @@ describe( "A product page content assessor", function() { expect( actual ).toEqual( expected ); } ); - it( "Should have 3 available assessments for a basic supported language", function() { + it( "Should have 4 available assessments for a basic supported language", function() { // A text of at least 50 characters. const longEnoughText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sagittis. There is more"; const paper = new Paper( longEnoughText, { locale: "xx_XX" } ); @@ -63,6 +64,7 @@ describe( "A product page content assessor", function() { const actual = contentAssessor.getApplicableAssessments().map( result => result.identifier ); const expected = [ + "subheadingsTooLong", "textParagraphTooLong", "textSentenceLength", "textPresence", @@ -132,8 +134,6 @@ describe( "A product page content assessor", function() { expect( assessment ).toBeDefined(); expect( assessment._config ).toBeDefined(); - expect( assessment._config.shouldNotAppearInShortText ).toBeDefined(); - expect( assessment._config.shouldNotAppearInShortText ).toBe( true ); expect( assessment._config.urlTitle ).toBe( "" ); expect( assessment._config.urlCallToAction ).toBe( "" ); } ); diff --git a/packages/yoastseo/spec/scoring/assessors/productPages/cornerstone/contentAssessorSpec.js b/packages/yoastseo/spec/scoring/assessors/productPages/cornerstone/contentAssessorSpec.js index fcd65a84cbe..d9ee825c6ec 100644 --- a/packages/yoastseo/spec/scoring/assessors/productPages/cornerstone/contentAssessorSpec.js +++ b/packages/yoastseo/spec/scoring/assessors/productPages/cornerstone/contentAssessorSpec.js @@ -33,7 +33,7 @@ describe( "A cornerstone product page content assessor", function() { "accommodare. Mutat gloriatur ex cum, rebum salutandi ei his, vis delenit quaestio ne. Iisque qualisque duo ei. " + "Splendide tincidunt te sit, commune oporteat quo id. Sumo recusabo suscipiantur duo an, no eum malis vulputate " + "consectetuer. Mel te noster invenire, nec ad vidisse constituto. Eos ut quod." ); - it( "Should have 5 available assessments for a fully supported language. " + + it( "Should have 6 available assessments for a fully supported language. " + "This doesn't include Word complexity assessment since the registration is done from Shopify side.", function() { const contentAssessor = new ContentAssessor( new EnglishResearcher( paper ), options ); contentAssessor.getPaper = function() { @@ -41,18 +41,18 @@ describe( "A cornerstone product page content assessor", function() { }; const actual = contentAssessor.getApplicableAssessments().length; - const expected = 5; + const expected = 6; expect( actual ).toBe( expected ); } ); - it( "Should have 3 available assessments for a basic supported language", function() { + it( "Should have 4 available assessments for a basic supported language", function() { const contentAssessor = new ContentAssessor( new DefaultResearcher( paper ), options ); contentAssessor.getPaper = function() { return paper; }; const actual = contentAssessor.getApplicableAssessments().length; - const expected = 3; + const expected = 4; expect( actual ).toBe( expected ); } ); } ); @@ -104,8 +104,6 @@ describe( "A cornerstone product page content assessor", function() { expect( assessment ).toBeDefined(); expect( assessment._config ).toBeDefined(); - expect( assessment._config.shouldNotAppearInShortText ).toBeDefined(); - expect( assessment._config.shouldNotAppearInShortText ).toBe( true ); expect( assessment._config.urlTitle ).toBe( "" ); expect( assessment._config.urlCallToAction ).toBe( "" ); } ); diff --git a/packages/yoastseo/spec/scoring/assessors/productPages/fullTextTests/testTexts/en/englishPaper1.js b/packages/yoastseo/spec/scoring/assessors/productPages/fullTextTests/testTexts/en/englishPaper1.js index 671c8cd0a10..8a9fd5ff324 100644 --- a/packages/yoastseo/spec/scoring/assessors/productPages/fullTextTests/testTexts/en/englishPaper1.js +++ b/packages/yoastseo/spec/scoring/assessors/productPages/fullTextTests/testTexts/en/englishPaper1.js @@ -126,7 +126,9 @@ const expectedResults = { "do not contain the keyphrase or its synonyms. Distribute them more evenly.", }, subheadingsTooLong: { - isApplicable: false, + isApplicable: true, + score: 9, + resultText: "Subheading distribution: Great job!", }, textParagraphTooLong: { isApplicable: true, diff --git a/packages/yoastseo/spec/scoring/assessors/storePostsAndPages/contentAssessorSpec.js b/packages/yoastseo/spec/scoring/assessors/storePostsAndPages/contentAssessorSpec.js index 99b6557f340..4a24e6789c5 100644 --- a/packages/yoastseo/spec/scoring/assessors/storePostsAndPages/contentAssessorSpec.js +++ b/packages/yoastseo/spec/scoring/assessors/storePostsAndPages/contentAssessorSpec.js @@ -202,7 +202,6 @@ describe( "A content assessor for English", function() { expect( assessment ).toBeDefined(); expect( assessment._config ).toBeDefined(); - expect( assessment._config.shouldNotAppearInShortText ).toBeDefined(); expect( assessment._config.urlTitle ).toBe( "" ); expect( assessment._config.urlCallToAction ).toBe( "" ); } ); diff --git a/packages/yoastseo/src/languageProcessing/researches/wordComplexity.js b/packages/yoastseo/src/languageProcessing/researches/wordComplexity.js index b657ead8fe6..db06d484814 100644 --- a/packages/yoastseo/src/languageProcessing/researches/wordComplexity.js +++ b/packages/yoastseo/src/languageProcessing/researches/wordComplexity.js @@ -85,6 +85,9 @@ const getComplexWords = function( currentSentence, researcher, topicForms ) { * @returns {number} The percentage of the complex words compared to the total words in the text. */ const calculateComplexWordsPercentage = function( complexWordsResults, words ) { + if ( words.length === 0 ) { + return 0; + } const totalComplexWords = flatMap( complexWordsResults, result => result.complexWords ); const percentage = ( totalComplexWords.length / words.length ) * 100; diff --git a/packages/yoastseo/src/scoring/assessments/SCORING READABILITY.md b/packages/yoastseo/src/scoring/assessments/SCORING READABILITY.md index 2b15d36545c..2b3316ddff0 100644 --- a/packages/yoastseo/src/scoring/assessments/SCORING READABILITY.md +++ b/packages/yoastseo/src/scoring/assessments/SCORING READABILITY.md @@ -24,7 +24,7 @@ Below is a detailed overview of how scores for the readability assessments are c ### 1) Subheading distribution **What it does**: Checks whether long texts are divided by subheadings. -**When applies**: When the (sanitized) text has more than 50 characters. +**When applies**: Always. **Name in code**: SubheadingsDistributionTooLong @@ -45,7 +45,7 @@ Below is a detailed overview of how scores for the readability assessments are c ### 2) Paragraph length **What it does**: Checks whether the paragraphs exceed the recommended maximum length. -**When applies**: When the (sanitized) text has more than 50 characters. This is tied to the TextPresenceAssessment. +**When applies**: Always. **Name in code**: ParagraphTooLongAssessment @@ -53,16 +53,16 @@ Below is a detailed overview of how scores for the readability assessments are c **Call to action URL**: [https://yoa.st/35e](https://yoast.com/paragraph-length-check/#utm_source=yoast-seo&utm_medium=software&utm_term=paragraph-length-cta&utm_content=content-analysis) (link placement is in bold in the feedback strings) -| Traffic light | Score | Criterion | Feedback | -|------------|------------------ |--------------------- |---------------------| -| Red |3 |> 200 words |**Paragraph length**: X of the paragraphs contain more than the recommended maximum of X words. **Shorten your paragraphs!**| -| Orange |6 |Between 150 and 200 words |**Paragraph length**: X of the paragraphs contain more than the recommended maximum of X words. **Shorten your paragraphs!**| -| Green |9 |≤ 150 words |**Paragraph length**: none of the paragraphs are too long. Great job! | +| Traffic light | Score | Criterion | Feedback | +|------------|------------------ |--------------------- |------------------------------------------------------------------------------------------------------------------------------| +| Red |3 |> 200 words | **Paragraph length**: X of the paragraphs contain more than the recommended maximum of X words. **Shorten your paragraphs!** | +| Orange |6 |Between 150 and 200 words | **Paragraph length**: X of the paragraphs contain more than the recommended maximum of X words. **Shorten your paragraphs!** | +| Green |9 |≤ 150 words | **Paragraph length**: There are no paragraphs that are too long. Great job! | ### 3) Sentence length **What it does**: Checks whether the sentences exceed the recommended maximum length (default: 20 words, IT: 25 words, RU: 15 words, HE: 15 words, TR: 15 words). -**When applies**: When the (sanitized) has more than 50 characters. This is tied to the TextPresenceAssessment. +**When applies**: Always. **Name in code**: SentenceLengthInTextAssessment @@ -79,7 +79,7 @@ Below is a detailed overview of how scores for the readability assessments are c ### 4) Consecutive sentences **What it does**: Checks whether there are more than 3 sentences in a row that start with the same word. -**When applies**: When the (sanitized) text has more than 50 characters (this is tied to the TextPresenceAssessment), and the research has a result. +**When applies**: When the researcher has a research (the assessment is supported in the researcher's language). **Name in code**: SentenceBeginningsAssessment @@ -95,7 +95,7 @@ Below is a detailed overview of how scores for the readability assessments are c ### 5) Passive voice **What it does**: Checks whether the number of sentences containing passive voice exceeds the recommended maximum amount. -**When applies**: When the (sanitized) text has more than 50 characters (this is tied to the TextPresenceAssessment), and the assessment is supported in the specific language (the researcher has a research). +**When applies**: When the researcher has a research (the assessment is supported in the researcher's language). **Name in code**: PassiveVoiceAssessment @@ -112,7 +112,7 @@ Below is a detailed overview of how scores for the readability assessments are c ### 6) Transition words **What it does**: Checks whether there are enough sentences containing transition words. -**When applies**: When there is at least 200 words in the text +**When applies**: When the researcher has a research (the assessment is supported in the researcher's language). **Name in code**: TransitionWordsAssessment @@ -120,12 +120,16 @@ Below is a detailed overview of how scores for the readability assessments are c **Call to action URL**: [https://yoa.st/35a](https://yoast.com/transition-words-why-and-how-to-use-them/#utm_source=yoast-seo&utm_medium=software&utm_term=transition-words-name&utm_content=content-analysis) (link placement is in bold in the feedback strings) -|Traffic light |Score |Criterion| Feedback| -|-------|------ |----- |------- | -|Red |3| No transition words found |**Transition words**: None of the sentences contain transition words. **Use some**.| -|Red |3| < 20% of sentences |**Transition words**: Only X of the sentences contain them. This is not enough. **Use more transition words**.| -|Orange |6| Between 20 and 30% of sentences|**Transition words**: Only X of the sentences contain them. This is not enough. **Use more transition words**.| -|Green |9| ≥ 30% of sentences |**Transition words**: Well done!| +|Traffic light |Score | Criterion | Feedback| +|-------|------ |------------------------------------------------------------------------------------------------------------------|------- | +|Red |3| No transition words found in a long text (more than 200 words or 400 characters in Japanese) |**Transition words**: None of the sentences contain transition words. **Use some**.| +|Red |3| < 20% of sentences in a long text (more than 200 words or 400 characters in Japanese) |**Transition words**: Only X of the sentences contain them. This is not enough. **Use more transition words**.| +|Orange |6| Between 20 and 30% of sentences in a long text (more than 200 words or 400 characters in Japanese) |**Transition words**: Only X of the sentences contain them. This is not enough. **Use more transition words**.| +|Green |9| ≥ 30% of sentences in a long text (more than 200 words or 400 characters in Japanese) |**Transition words**: Well done!| +|Green |9| At least one sentence with transition words in a short text (less than 200 words or 400 characters in Japanese) |**Transition words**: Well done!| +|Green |9| No transition words found in a short text (less than 200 words or 400 characters in Japanese) |**Transition words**: You are not using any transition words, but your text is short enough and probably doesn't need them.| + + ### 7) Text presence **What it does**: Checks whether there is enough text in the copy @@ -143,7 +147,7 @@ Below is a detailed overview of how scores for the readability assessments are c ### 8) Word complexity (only in Premium) **What it does**: Checks whether the text contains complex words. Word forms from the keyphrase are excluded. -**When applies**: When the (sanitized) text has more than 50 characters +**When applies**: When the researcher has a research (the assessment is supported in the researcher's language). **Name in code**: WordComplexityAssessment diff --git a/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js index e2ecc1a587a..aada2943e45 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/ListAssessment.js @@ -75,17 +75,6 @@ export default class ListAssessment extends Assessment { return assessmentResult; } - /** - * Checks whether the paper has text. - * - * @param {Paper} paper The paper to use for the assessment. - * - * @returns {boolean} True when there is text. - */ - isApplicable( paper ) { - return this.hasEnoughContentForAssessment( paper ); - } - /** * Calculate the result based on the availability of lists in the text. * diff --git a/packages/yoastseo/src/scoring/assessments/readability/ParagraphTooLongAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/ParagraphTooLongAssessment.js index 6f08493aa3b..335c4ea50dd 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/ParagraphTooLongAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/ParagraphTooLongAssessment.js @@ -77,6 +77,10 @@ export default class ParagraphTooLongAssessment extends Assessment { * @returns {number} The score. */ getScore( paragraphsLength, config ) { + if ( paragraphsLength.length === 0 ) { + return 9; + } + const sortedParagraphsLength = paragraphsLength.sort( ( a, b ) => b.paragraphLength - a.paragraphLength ); const longestParagraphLength = sortedParagraphsLength[ 0 ].paragraphLength; @@ -111,10 +115,6 @@ export default class ParagraphTooLongAssessment extends Assessment { const assessmentResult = new AssessmentResult(); - if ( paragraphsLength.length === 0 ) { - return assessmentResult; - } - const score = this.getScore( paragraphsLength, config ); assessmentResult.setScore( score ); @@ -124,7 +124,7 @@ export default class ParagraphTooLongAssessment extends Assessment { assessmentResult.setText( sprintf( /* translators: %1$s expands to a link on yoast.com, %2$s expands to the anchor end tag */ __( - "%1$sParagraph length%2$s: None of the paragraphs are too long. Great job!", + "%1$sParagraph length%2$s: There are no paragraphs that are too long. Great job!", "wordpress-seo" ), config.urlTitle, @@ -227,15 +227,4 @@ export default class ParagraphTooLongAssessment extends Assessment { return this.calculateResult( paragraphsLength, this.getConfig( researcher ) ); } - - /** - * Checks if the paragraphTooLong assessment is applicable to the paper. - * - * @param {Paper} paper The paper to check. - * - * @returns {boolean} Returns true if the assessment is applicable to the paper. - */ - isApplicable( paper ) { - return this.hasEnoughContentForAssessment( paper ); - } } diff --git a/packages/yoastseo/src/scoring/assessments/readability/PassiveVoiceAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/PassiveVoiceAssessment.js index 4994e6475d6..1db91b368dc 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/PassiveVoiceAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/PassiveVoiceAssessment.js @@ -149,9 +149,9 @@ export default class PassiveVoiceAssessment extends Assessment { * @param {Paper} paper The paper to check. * @param {Researcher} researcher The researcher object. * - * @returns {boolean} Returns true if the language is available and the paper is not empty. + * @returns {boolean} Returns true if the researcher has the passive voice research. */ isApplicable( paper, researcher ) { - return this.hasEnoughContentForAssessment( paper ) && researcher.hasResearch( "getPassiveVoiceResult" ); + return researcher.hasResearch( "getPassiveVoiceResult" ); } } diff --git a/packages/yoastseo/src/scoring/assessments/readability/SentenceBeginningsAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/SentenceBeginningsAssessment.js index 8ea315d769c..8a29b63f783 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/SentenceBeginningsAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/SentenceBeginningsAssessment.js @@ -154,9 +154,9 @@ export default class SentenceBeginningsAssessment extends Assessment { * @param {Paper} paper The paper to check. * @param {Researcher} researcher The researcher object. * - * @returns {boolean} Returns true if the paper has enough content for the assessment and the researcher has the required research. + * @returns {boolean} Returns true if the researcher has the sentence beginnings research. */ isApplicable( paper, researcher ) { - return this.hasEnoughContentForAssessment( paper ) && researcher.hasResearch( "getSentenceBeginnings" ); + return researcher.hasResearch( "getSentenceBeginnings" ); } } diff --git a/packages/yoastseo/src/scoring/assessments/readability/SentenceLengthInTextAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/SentenceLengthInTextAssessment.js index cac01ad8807..51c610f585c 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/SentenceLengthInTextAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/SentenceLengthInTextAssessment.js @@ -72,17 +72,6 @@ class SentenceLengthInTextAssessment extends Assessment { return assessmentResult; } - /** - * Checks whether the paper has text. - * - * @param {Paper} paper The paper to use for the assessment. - * - * @returns {boolean} True when there is text. - */ - isApplicable( paper ) { - return this.hasEnoughContentForAssessment( paper ); - } - /** * Mark the sentences. * diff --git a/packages/yoastseo/src/scoring/assessments/readability/SubheadingDistributionTooLongAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/SubheadingDistributionTooLongAssessment.js index 52f20b7a395..fe38abe7892 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/SubheadingDistributionTooLongAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/SubheadingDistributionTooLongAssessment.js @@ -30,8 +30,6 @@ import { filterShortcodesFromHTML } from "../../../languageProcessing/helpers"; * @property {number} scores.okSubheadings The score for okay subheading distribution. * @property {number} scores.badSubheadings The score for bad subheading distribution. * @property {number} scores.badLongTextNoSubheadings The score for a bad long text without subheadings. - * @property {number} applicableIfTextLongerThan The minimum text length for the assessment to be applicable. - * @property {boolean} shouldNotAppearInShortText Whether the assessment should not appear in short texts. * @property {boolean} cornerstoneContent Whether the text is cornerstone content. * @property {boolean} countCharacters Whether to count characters instead of words. */ @@ -69,8 +67,6 @@ class SubheadingsDistributionTooLong extends Assessment { badSubheadings: 3, badLongTextNoSubheadings: 2, }, - applicableIfTextLongerThan: 300, - shouldNotAppearInShortText: false, cornerstoneContent: false, countCharacters: false, }; @@ -173,34 +169,6 @@ class SubheadingsDistributionTooLong extends Assessment { return merge( currentConfig, languageSpecificConfig.defaultParameters ); } - /** - * Checks the applicability of the assessment based on the presence of text, and, if required, text length. - * - * @param {Paper} paper The paper to use for the assessment. - * @param {Researcher} researcher The language-specific or default researcher. - * - * @returns {boolean} True when there is text or when text is longer than the specified length and "shouldNotAppearInShortText" is set to true. - */ - isApplicable( paper, researcher ) { - /* - * If the assessment should not appear for shorter texts, only set the assessment as applicable if the text meets the minimum required length. - * Language-specific length requirements and methods of counting text length may apply (e.g. for Japanese, the text should be counted in - * characters instead of words, which also makes the minimum required length higher). - */ - if ( this._config.shouldNotAppearInShortText ) { - if ( researcher.getConfig( "subheadingsTooLong" ) ) { - this._config = this.getLanguageSpecificConfig( researcher ); - } - - const textLength = this.getTextLength( paper, researcher ); - - // Do not use hasEnoughContentForAssessment as it is redundant with textLength > this._config.applicableIfTextLongerThan. - return textLength > this._config.applicableIfTextLongerThan; - } - - return this.hasEnoughContentForAssessment( paper ); - } - /** * Checks whether the paper has subheadings. * @@ -405,7 +373,7 @@ class SubheadingsDistributionTooLong extends Assessment { * @returns {{resultText: string, score: number, hasMarks: boolean}} The calculated result. */ calculateResult( textBeforeFirstSubheading ) { - if ( this._textLength > this._config.applicableIfTextLongerThan ) { + if ( this._textLength > this._config.parameters.recommendedMaximumLength ) { return this.calculateResultForLongTextWithoutSubheadings( textBeforeFirstSubheading ); } if ( this._hasSubheadings ) { diff --git a/packages/yoastseo/src/scoring/assessments/readability/TextAlignmentAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/TextAlignmentAssessment.js index c3f73f8fc9b..310c9fcdffd 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/TextAlignmentAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/TextAlignmentAssessment.js @@ -91,16 +91,15 @@ export default class TextAlignmentAssessment extends Assessment { /** * Checks whether the assessment is applicable. * The assessment is applicable when the paper has at least 50 characters (after sanitation) - * and when the researcher has `getLongCenterAlignedText` research. + * and when the researcher has `getLongCenterAlignedTexts` research. * * @param {Paper} paper The paper to use for the assessment. * @param {Researcher} researcher The researcher used in the assessment. * - * @returns {boolean} True when the paper has at least 50 characters (after sanitation) - * and when the researcher has `getLongCenterAlignedText` research. + * @returns {boolean} True when the researcher has `getLongCenterAlignedText` research. */ isApplicable( paper, researcher ) { - return this.hasEnoughContentForAssessment( paper ) && researcher.hasResearch( "getLongCenterAlignedTexts" ); + return researcher.hasResearch( "getLongCenterAlignedTexts" ); } /** diff --git a/packages/yoastseo/src/scoring/assessments/readability/TransitionWordsAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/TransitionWordsAssessment.js index 68e5d7cbe35..7945bb4a53c 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/TransitionWordsAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/TransitionWordsAssessment.js @@ -31,7 +31,7 @@ export default class TransitionWordsAssessment extends Assessment { const defaultConfig = { urlTitle: createAnchorOpeningTag( "https://yoa.st/34z" ), urlCallToAction: createAnchorOpeningTag( "https://yoa.st/35a" ), - applicableIfTextLongerThan: 200, + transitionWordsNeededIfTextLongerThan: 200, }; this.identifier = "textTransitionWords"; @@ -81,14 +81,45 @@ export default class TransitionWordsAssessment extends Assessment { * * @param {object} transitionWordSentences The object containing the total number of sentences and the number of sentences containing * a transition word. + * @param {number} textLength The length of the text. * * @returns {object} Object containing score and text. */ - calculateTransitionWordResult( transitionWordSentences ) { + calculateTransitionWordResult( transitionWordSentences, textLength ) { const percentage = this.calculateTransitionWordPercentage( transitionWordSentences ); const score = this.calculateScoreFromPercentage( percentage ); const hasMarks = ( percentage > 0 ); + // If the text is shorter than the minimum required length for transition words, we always return a green traffic light. + if ( textLength < this._config.transitionWordsNeededIfTextLongerThan ) { + if ( percentage > 0 ) { + return { + score: formatNumber( 9 ), + hasMarks: hasMarks, + text: sprintf( + /* translators: %1$s expands to a link on yoast.com, %2$s expands to the anchor end tag. */ + __( + "%1$sTransition words%2$s: Well done!", + "wordpress-seo" + ), + this._config.urlTitle, + "" ), + }; + } + return { + score: formatNumber( 9 ), + hasMarks: hasMarks, + text: sprintf( + /* translators: %1$s expands to a link on yoast.com, %2$s expands to the anchor end tag. */ + __( + "%1$sTransition words%2$s: You are not using any transition words, but your text is short enough and probably doesn't need them.", + "wordpress-seo" + ), + this._config.urlTitle, + "" ), + }; + } + if ( score < 7 && percentage === 0 ) { return { score: formatNumber( score ), @@ -127,7 +158,7 @@ export default class TransitionWordsAssessment extends Assessment { score: formatNumber( score ), hasMarks: hasMarks, text: sprintf( - /* translators: %1$s expands to a link on yoast.com, %3$s expands to the anchor end tag. */ + /* translators: %1$s expands to a link on yoast.com, %2$s expands to the anchor end tag. */ __( "%1$sTransition words%2$s: Well done!", "wordpress-seo" @@ -146,8 +177,19 @@ export default class TransitionWordsAssessment extends Assessment { * @returns {object} The Assessment result. */ getResult( paper, researcher ) { + const customCountLength = researcher.getHelper( "customCountLength" ); + const customMinimumRequiredTextLength = researcher.getConfig( "assessmentApplicability" ).transitionWords; + if ( customMinimumRequiredTextLength ) { + this._config.transitionWordsNeededIfTextLongerThan = customMinimumRequiredTextLength; + } + let text = paper.getText(); + text = removeHtmlBlocks( text ); + text = filterShortcodesFromHTML( text, paper._attributes && paper._attributes.shortcodes ); + const textLength = customCountLength ? customCountLength( text ) : getWords( text ).length; + const transitionWordSentences = researcher.getResearch( "findTransitionWords" ); - const transitionWordResult = this.calculateTransitionWordResult( transitionWordSentences ); + + const transitionWordResult = this.calculateTransitionWordResult( transitionWordSentences, textLength ); const assessmentResult = new AssessmentResult(); assessmentResult.setScore( transitionWordResult.score ); @@ -179,27 +221,14 @@ export default class TransitionWordsAssessment extends Assessment { } /** - * Checks if the transition words assessment is applicable to the paper. Language-specific length requirements and methods of counting text length - * may apply (e.g. for Japanese, the text should be counted in characters instead of words, which also makes the minimum required length higher). + * Checks if the transition words assessment is applicable to the paper. * * @param {Paper} paper The paper to check. * @param {Researcher} researcher The researcher object. * - * @returns {boolean} Returns true if the language is available, the paper is not empty and the text is longer than the minimum required length. + * @returns {boolean} Returns true if the assessment is available in the researcher of the language. */ isApplicable( paper, researcher ) { - const customCountLength = researcher.getHelper( "customCountLength" ); - const customApplicabilityConfig = researcher.getConfig( "assessmentApplicability" ).transitionWords; - if ( customApplicabilityConfig ) { - this._config.applicableIfTextLongerThan = customApplicabilityConfig; - } - let text = paper.getText(); - text = removeHtmlBlocks( text ); - text = filterShortcodesFromHTML( text, paper._attributes && paper._attributes.shortcodes ); - const textLength = customCountLength ? customCountLength( text ) : getWords( text ).length; - - // Do not use hasEnoughContent in this assessment as it is mostly redundant with `textLength >= this._config.applicableIfTextLongerThan` - return textLength >= this._config.applicableIfTextLongerThan && - researcher.hasResearch( "findTransitionWords" ); + return researcher.hasResearch( "findTransitionWords" ); } } diff --git a/packages/yoastseo/src/scoring/assessments/readability/WordComplexityAssessment.js b/packages/yoastseo/src/scoring/assessments/readability/WordComplexityAssessment.js index 8d6cbc36954..8fd5746b9c6 100644 --- a/packages/yoastseo/src/scoring/assessments/readability/WordComplexityAssessment.js +++ b/packages/yoastseo/src/scoring/assessments/readability/WordComplexityAssessment.js @@ -155,9 +155,9 @@ export default class WordComplexityAssessment extends Assessment { * @param {Paper} paper The paper to check. * @param {Researcher} researcher The researcher object. * - * @returns {boolean} Returns true if the paper has text and the researcher has word complexity research. + * @returns {boolean} Returns true if the researcher has word complexity research. */ isApplicable( paper, researcher ) { - return this.hasEnoughContentForAssessment( paper ) && researcher.hasResearch( "wordComplexity" ); + return researcher.hasResearch( "wordComplexity" ); } } diff --git a/packages/yoastseo/src/scoring/assessors/cornerstone/contentAssessor.js b/packages/yoastseo/src/scoring/assessors/cornerstone/contentAssessor.js index aa52faa1bae..650ea257e4c 100644 --- a/packages/yoastseo/src/scoring/assessors/cornerstone/contentAssessor.js +++ b/packages/yoastseo/src/scoring/assessors/cornerstone/contentAssessor.js @@ -17,7 +17,6 @@ export default class CornerstoneContentAssessor extends ContentAssessor { this.addAssessment( "subheadingsTooLong", new SubheadingDistributionTooLong( { parameters: { slightlyTooMany: 250, farTooMany: 300, recommendedMaximumLength: 250 }, - applicableIfTextLongerThan: 250, cornerstoneContent: true, } ) ); this.addAssessment( "textSentenceLength", new SentenceLengthInText( { diff --git a/packages/yoastseo/src/scoring/assessors/productPages/contentAssessor.js b/packages/yoastseo/src/scoring/assessors/productPages/contentAssessor.js index e9449786aba..0ae8986e23b 100644 --- a/packages/yoastseo/src/scoring/assessors/productPages/contentAssessor.js +++ b/packages/yoastseo/src/scoring/assessors/productPages/contentAssessor.js @@ -22,7 +22,6 @@ export default class ProductContentAssessor extends ContentAssessor { this._assessments = [ new SubheadingDistributionTooLongAssessment( { - shouldNotAppearInShortText: true, urlTitle: createAnchorOpeningTag( options.subheadingUrlTitle ), urlCallToAction: createAnchorOpeningTag( options.subheadingCTAUrl ), } ), diff --git a/packages/yoastseo/src/scoring/assessors/productPages/cornerstone/contentAssessor.js b/packages/yoastseo/src/scoring/assessors/productPages/cornerstone/contentAssessor.js index 9014991a227..0a0e07bafd6 100644 --- a/packages/yoastseo/src/scoring/assessors/productPages/cornerstone/contentAssessor.js +++ b/packages/yoastseo/src/scoring/assessors/productPages/cornerstone/contentAssessor.js @@ -19,8 +19,6 @@ export default class ProductCornerstoneContentAssessor extends ProductContentAss this.addAssessment( "subheadingsTooLong", new SubheadingDistributionTooLongAssessment( { parameters: { slightlyTooMany: 250, farTooMany: 300, recommendedMaximumLength: 250 }, - applicableIfTextLongerThan: 250, - shouldNotAppearInShortText: true, urlTitle: createAnchorOpeningTag( options.subheadingUrlTitle ), urlCallToAction: createAnchorOpeningTag( options.subheadingCTAUrl ), cornerstoneContent: true,