-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20685 from Yoast/20675-replacement-variable-edito…
…r-replacement-variable-editortestsreplacementvariableeditortestjs 20675 replacement variable editor replacement variable editortestsreplacementvariableeditortestjs
- Loading branch information
Showing
7 changed files
with
255 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module.exports = { | ||
root: true, | ||
"extends": [ | ||
"yoast", | ||
], | ||
settings: { | ||
react: { | ||
version: "detect", | ||
}, | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
}, | ||
ignorePatterns: [ | ||
"/build/", | ||
"/coverage/", | ||
"/dist/", | ||
], | ||
rules: { | ||
"no-prototype-builtins": 0, | ||
"comma-dangle": [ | ||
"error", | ||
{ | ||
arrays: "always-multiline", | ||
objects: "always-multiline", | ||
imports: "always-multiline", | ||
exports: "always-multiline", | ||
functions: "never", | ||
}, | ||
], | ||
}, | ||
overrides: [ | ||
{ | ||
files: [ "tests/**/*.js" ], | ||
env: { | ||
jest: true, | ||
}, | ||
rules: { | ||
"no-restricted-imports": 0, | ||
}, | ||
}, | ||
{ | ||
files: [ "**/*.js" ], | ||
rules: { | ||
"react/jsx-no-bind": 1, | ||
"react/require-default-props": 1, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
248 changes: 130 additions & 118 deletions
248
packages/replacement-variable-editor/tests/ReplacementVariableEditorTest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,139 @@ | ||
/* eslint-disable react/jsx-no-bind */ | ||
// import ReplacementVariableEditorStandalone, { ReplacementVariableEditorStandaloneInnerComponent } | ||
// from "../src/ReplacementVariableEditorStandalone"; | ||
// import React from "react"; | ||
import React from "react"; | ||
import { render } from "./test-utils"; | ||
import ReplacementVariableEditorStandalone, { ReplacementVariableEditorStandaloneInnerComponent } | ||
from "../src/ReplacementVariableEditorStandalone"; | ||
|
||
// jest.mock( "draft-js/lib/generateRandomKey", () => () => { | ||
// let randomKey = global._testDraftJSRandomNumber; | ||
jest.mock( "draft-js/lib/generateRandomKey", () => () => { | ||
let randomKey = global._testDraftJSRandomNumber; | ||
|
||
// if ( ! randomKey ) { | ||
// randomKey = 0; | ||
// } | ||
if ( ! randomKey ) { | ||
randomKey = 0; | ||
} | ||
|
||
// randomKey++; | ||
// global._testDraftJSRandomNumber = randomKey; | ||
randomKey++; | ||
global._testDraftJSRandomNumber = randomKey; | ||
|
||
// return randomKey + ""; | ||
// } ); | ||
return randomKey + ""; | ||
} ); | ||
|
||
describe( "ReplacementVariableEditor", () => { | ||
describe( "ReplacementVariableEditorStandalone", () => { | ||
it( "wraps a Draft.js editor instance", () => { | ||
|
||
const { container } = render( | ||
<ReplacementVariableEditorStandalone | ||
replacementVariables={ [] } | ||
content="Dummy content" | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onChange={ () => {} } | ||
ariaLabelledBy="id" | ||
fieldId="test-field-id" | ||
theme={ { isRtl: "false" } } | ||
/> | ||
); | ||
|
||
expect( container ).toMatchSnapshot(); | ||
} ); | ||
} ); | ||
|
||
// describe( "suggestionsFilter", () => { | ||
// let searchValue, replacementVariables, suggestions, replacementVariablesEditor, expected; | ||
|
||
// beforeEach( () => { | ||
// searchValue = "cat"; | ||
// replacementVariables = [ | ||
// { | ||
// name: "category", | ||
// label: "Category", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// name: "primary_category", | ||
// label: "Primary category", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// name: "category_description", | ||
// label: "Category description", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// name: "date", | ||
// label: "Date", | ||
// value: "May 30, 2018", | ||
// }, | ||
// ]; | ||
|
||
// const props = { | ||
// replacementVariables, | ||
// content: "Dummy content", | ||
// onChange: () => {}, | ||
// ariaLabelledBy: "id", | ||
// theme: { isRtl: false }, | ||
// }; | ||
|
||
// replacementVariablesEditor = new ReplacementVariableEditorStandaloneInnerComponent( props ); | ||
|
||
// suggestions = replacementVariablesEditor.mapReplacementVariablesToSuggestions( props.replacementVariables ); | ||
|
||
// expected = [ | ||
// { | ||
// replaceName: "category", | ||
// label: "Category", | ||
// name: "Category", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// replaceName: "category_description", | ||
// label: "Category description", | ||
// name: "Category description", | ||
// value: "uncategorized", | ||
// }, | ||
// ]; | ||
// } ); | ||
|
||
// it( "Replacement variables are correctly mapped to suggestions by mapReplacementVariablesToSuggestions.", () => { | ||
// expected = [ | ||
// { | ||
// replaceName: "category", | ||
// label: "Category", | ||
// name: "Category", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// replaceName: "primary_category", | ||
// label: "Primary category", | ||
// name: "Primary category", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// replaceName: "category_description", | ||
// label: "Category description", | ||
// name: "Category description", | ||
// value: "uncategorized", | ||
// }, | ||
// { | ||
// replaceName: "date", | ||
// label: "Date", | ||
// name: "Date", | ||
// value: "May 30, 2018", | ||
// }, | ||
// ]; | ||
|
||
// const actual = replacementVariablesEditor.mapReplacementVariablesToSuggestions( replacementVariables ); | ||
|
||
// expect( actual ).toEqual( expected ); | ||
// } ); | ||
|
||
// it( "Returns only the replacement variables where the start of the name matches with the search value.", () => { | ||
// const actual = replacementVariablesEditor.suggestionsFilter( searchValue, suggestions ); | ||
|
||
// expect( actual ).toEqual( expected ); | ||
// } ); | ||
|
||
// it( "Returns the matching replacement variables, regardless of upper- or lowercase in the search value.", () => { | ||
// searchValue = "Cat"; | ||
|
||
// const actual = replacementVariablesEditor.suggestionsFilter( searchValue, suggestions ); | ||
|
||
// expect( actual ).toEqual( expected ); | ||
// } ); | ||
// } ); | ||
describe( "suggestionsFilter", () => { | ||
let searchValue, replacementVariables, suggestions, replacementVariablesEditor, expected; | ||
|
||
beforeEach( () => { | ||
searchValue = "cat"; | ||
replacementVariables = [ | ||
{ | ||
name: "category", | ||
label: "Category", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
name: "primary_category", | ||
label: "Primary category", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
name: "category_description", | ||
label: "Category description", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
name: "date", | ||
label: "Date", | ||
value: "May 30, 2018", | ||
}, | ||
]; | ||
|
||
const props = { | ||
replacementVariables, | ||
content: "Dummy content", | ||
onChange: () => {}, | ||
ariaLabelledBy: "id", | ||
theme: { isRtl: false }, | ||
}; | ||
suggestions = [ | ||
{ name: "cat", value: "meow" }, | ||
]; | ||
replacementVariablesEditor = new ReplacementVariableEditorStandaloneInnerComponent( props ); | ||
suggestions = replacementVariablesEditor.mapReplacementVariablesToSuggestions( props.replacementVariables ); | ||
expected = [ | ||
{ | ||
replaceName: "category", | ||
label: "Category", | ||
name: "Category", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
replaceName: "category_description", | ||
label: "Category description", | ||
name: "Category description", | ||
value: "uncategorized", | ||
}, | ||
]; | ||
} ); | ||
|
||
it( "Replacement variables are correctly mapped to suggestions by mapReplacementVariablesToSuggestions.", () => { | ||
expected = [ | ||
{ | ||
replaceName: "category", | ||
label: "Category", | ||
name: "Category", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
replaceName: "primary_category", | ||
label: "Primary category", | ||
name: "Primary category", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
replaceName: "category_description", | ||
label: "Category description", | ||
name: "Category description", | ||
value: "uncategorized", | ||
}, | ||
{ | ||
replaceName: "date", | ||
label: "Date", | ||
name: "Date", | ||
value: "May 30, 2018", | ||
}, | ||
]; | ||
|
||
const actual = replacementVariablesEditor.mapReplacementVariablesToSuggestions( replacementVariables ); | ||
|
||
expect( actual ).toEqual( expected ); | ||
} ); | ||
|
||
it( "Returns only the replacement variables where the start of the name matches with the search value.", () => { | ||
const actual = replacementVariablesEditor.suggestionsFilter( searchValue, suggestions ); | ||
|
||
expect( actual ).toEqual( expected ); | ||
} ); | ||
|
||
it( "Returns the matching replacement variables, regardless of upper- or lowercase in the search value.", () => { | ||
searchValue = "Cat"; | ||
|
||
const actual = replacementVariablesEditor.suggestionsFilter( searchValue, suggestions ); | ||
|
||
expect( actual ).toEqual( expected ); | ||
} ); | ||
} ); |
Oops, something went wrong.