PageSourceSearch

https://app.cookiefirst.com/dist/2026-09-15/13-16-9680/inputs/Quil…r-__tests__-QuillTextEditor-test.9c3ff4b.js

js cookiefirst.com collected 2026-10-01 08:37:33 UTC 11,701 bytes, 2 lines download raw bytes

1/*! For license information please see QuillTextEditor-__tests__-QuillTextEditor-test.9c3ff4b.js.LICENSE.txt */
2"use strict";(self.webpackChunkcookiefirst_admin_panel=self.webpackChunkcookiefirst_admin_panel||[]).push([[4035],{67430:function(e,t,n){n.r(t),n(52675),n(2008),n(83851),n(81278),n(79432),n(26099),n(23500);var o=n(10467),r=n(58168),c=n(64467),a=n(54756),s=n.n(a),i=n(40253),u=n(96540),l=n(13815);function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function f(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach(function(t){(0,c.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var h=function(){var e=document.createElement("div");return e.className="ql-toolbar",{querySelector:jest.fn(function(t){return".ql-toolbar"===t?e:null}),toolbarEl:e}},p={getLength:jest.fn(function(){return 0}),getSelection:jest.fn(function(){return{index:0,length:0}}),getText:jest.fn(function(){return""}),insertText:jest.fn(),setSelection:jest.fn(),updateContents:jest.fn(),on:jest.fn(),off:jest.fn(),container:{parentNode:h()},root:{parentNode:{querySelector:jest.fn(function(){return null})},addEventListener:jest.fn(),removeEventListener:jest.fn()}},m=jest.fn(function(){return p});jest.mock("../../../../../hooks/useTranslate",function(){return{__esModule:!0,default:function(e){return[function(t){return"widgetTexts:quillTextEditor"===e?"widget:".concat(t):t}]}}}),jest.mock("../../../../../helpers/sanitizeHtml",function(){return{__esModule:!0,default:function(e){return e}}}),jest.mock("react-dom",function(){return f(f({},jest.requireActual("react-dom")),{},{createPortal:function(e){return e}})}),jest.mock("react-quill-new",function(){var e=n(96540),t=e.forwardRef(function(t,n){var o=t.className,r=t.theme,c=(t.value,t.onChange);return e.useImperativeHandle(n,function(){return{getEditor:m}}),e.createElement("div",{"data-testid":"react-quill",className:o,"data-theme":r},e.createElement("div",{className:"ql-toolbar","data-testid":"ql-toolbar"}),e.createElement("button",{type:"button",onClick:function(){return c("<p>New content</p>")}},"Change"),e.createElement("button",{type:"button","data-testid":"change-with-shortcode",onClick:function(){return c("[cf_deny]Deny[/cf_deny]",null,"user")}},"Shortcode"),e.createElement("button",{type:"button","data-testid":"change-with-link-in-shortcode",onClick:function(){return c('[cf_deny]<a href="#">link</a>[/cf_deny]',{ops:[{insert:"x",attributes:{link:"http://x"}}]},"user",p)}},"LinkInShortcode"),e.createElement("button",{type:"button","data-testid":"change-sanitize-shortcode",onClick:function(){return c('[cf_deny]<a href="#">link</a>[/cf_deny]')}},"SanitizeShortcode"))});return t.displayName="MockQuill",t}),jest.mock("../../../../../constants/quillDefalutModules",function(){return{toolbar:[["bold","italic"]]}}),describe("QuillTextEditor",function(){var e={name:"editor",value:"<p>Initial content</p>",onChange:jest.fn(),tabsOnSettingsPanel:[]};beforeEach(function(){var e;jest.clearAllMocks(),e=h(),p.getLength.mockReturnValue(0),p.getSelection.mockReturnValue({index:0,length:0}),p.getText.mockReturnValue(""),p.insertText.mockClear(),p.setSelection.mockClear(),p.updateContents.mockClear(),p.on.mockClear(),p.off.mockClear(),p.container={parentNode:e},p.root.parentNode.querySelector.mockReturnValue(null),m.mockReturnValue(p)}),it("should render ReactQuill",function(){(0,i.XX)(u.createElement(l.default,e)),expect(i.nj.getByTestId("react-quill")).toBeInTheDocument()}),it("should pass value to ReactQuill",function(){(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{value:"<p>Test content</p>"}))),expect(i.nj.getByTestId("react-quill")).toHaveAttribute("data-theme","snow")}),it("should handle empty value as empty string",function(){(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{value:""}))),expect(i.nj.getByTestId("react-quill")).toBeInTheDocument()}),it("should call onChange with new content",function(){var t=jest.fn();(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{onChange:t}))),i.rC.click(i.nj.getByText("Change")),expect(t).toHaveBeenCalledWith("<p>New content</p>")}),it("applies with-shortcodes class when useShortCodes is enabled",function(){var t=(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))).container;expect(t.firstChild).toHaveClass("with-shortcodes")}),it("shows shortcode info alert when content contains shortcodes",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,value:"[cf_deny]Deny[/cf_deny]"}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByText("shortcodeWarning")).toBeInTheDocument()});case 1:case"end":return t.stop()}},t)}))),it("shows disabled shortcode warning when tab shortcode is not enabled",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,tabsOnSettingsPanel:[],value:"[cf_tab_settings]Settings[/cf_tab_settings]"}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByText("disabledShortcodeWarning")).toBeInTheDocument()});case 1:case"end":return t.stop()}},t)}))),it("sanitizes anchor tags inside shortcodes on load",(0,o.A)(s().mark(function t(){var n;return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=jest.fn(),(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,onChange:n,value:'[cf_deny]<a href="#">link</a>[/cf_deny]'}))),t.next=1,(0,i.fm)(function(){expect(n).toHaveBeenCalledWith("[cf_deny]link[/cf_deny]")});case 1:case"end":return t.stop()}},t)}))),it("detects shortcodes after user edits content",function(){(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))),i.rC.click(i.nj.getByTestId("change-with-shortcode")),expect(i.nj.getByText("shortcodeWarning")).toBeInTheDocument()}),it("clears shortcode warnings when value becomes empty",(0,o.A)(s().mark(function t(){var n,o;return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,value:"[cf_deny]Deny[/cf_deny]"}))),o=n.rerender,t.next=1,(0,i.fm)(function(){expect(i.nj.getByText("shortcodeWarning")).toBeInTheDocument()});case 1:return o(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,value:""}))),t.next=2,(0,i.fm)(function(){expect(i.nj.queryByText("shortcodeWarning")).not.toBeInTheDocument()});case 2:case"end":return t.stop()}},t)}
2))),it("does not show disabled warning when tab shortcode is enabled",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,tabsOnSettingsPanel:["settings"],value:"[cf_tab_settings]Settings[/cf_tab_settings]"}))),t.next=1,(0,i.fm)(function(){expect(i.nj.queryByText("disabledShortcodeWarning")).not.toBeInTheDocument()});case 1:case"end":return t.stop()}},t)}))),it("opens shortcode dropdown and inserts selected shortcode",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return p.getSelection.mockReturnValue({index:2,length:0}),(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByTitle("shortcodeTitle")).toBeInTheDocument()});case 1:i.rC.click(i.nj.getByTitle("shortcodeTitle")),expect(i.nj.getByText("widget:deny")).toBeInTheDocument(),i.rC.click(i.nj.getByText("widget:deny")),expect(p.insertText).toHaveBeenCalledWith(2,"[cf_deny]widget:deny[/cf_deny]","user"),expect(p.setSelection).toHaveBeenCalled();case 2:case"end":return t.stop()}},t)}))),it("uses localeTranslations for shortcode labels when inserting",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return p.getSelection.mockReturnValue({index:0,length:0}),(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,localeTranslations:{quillTextEditor:{deny:"Translated deny"}}}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByTitle("shortcodeTitle")).toBeInTheDocument()});case 1:i.rC.click(i.nj.getByTitle("shortcodeTitle")),i.rC.click(i.nj.getByText("Translated deny")),expect(p.insertText).toHaveBeenCalledWith(0,"[cf_deny]Translated deny[/cf_deny]","user");case 2:case"end":return t.stop()}},t)}))),it("does not insert disabled tab shortcodes from dropdown",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,tabsOnSettingsPanel:[]}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByTitle("shortcodeTitle")).toBeInTheDocument()});case 1:i.rC.click(i.nj.getByTitle("shortcodeTitle")),i.rC.click(i.nj.getByText("widget:tabSettings")),expect(p.insertText).not.toHaveBeenCalled();case 2:case"end":return t.stop()}},t)}))),it("closes shortcode dropdown when clicking outside",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByTitle("shortcodeTitle")).toBeInTheDocument()});case 1:return i.rC.click(i.nj.getByTitle("shortcodeTitle")),expect(i.nj.getByText("widget:deny")).toBeInTheDocument(),i.rC.mouseDown(document.body),t.next=2,(0,i.fm)(function(){expect(i.nj.queryByText("widget:deny")).not.toBeInTheDocument()});case 2:case"end":return t.stop()}},t)}))),it("registers quill listeners when shortcodes are enabled",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))),t.next=1,(0,i.fm)(function(){expect(p.on).toHaveBeenCalledWith("selection-change",expect.any(Function)),expect(p.on).toHaveBeenCalledWith("text-change",expect.any(Function))});case 1:case"end":return t.stop()}},t)}))),it("inserts shortcode at document end when selection is unavailable",(0,o.A)(s().mark(function t(){return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return p.getSelection.mockReturnValue(null),p.getLength.mockReturnValue(4),(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByTitle("shortcodeTitle")).toBeInTheDocument()});case 1:i.rC.click(i.nj.getByTitle("shortcodeTitle")),i.rC.click(i.nj.getByText("widget:acceptAll")),expect(p.insertText).toHaveBeenCalledWith(4,"[cf_acceptAll]widget:acceptAll[/cf_acceptAll]","user");case 2:case"end":return t.stop()}},t)}))),it("toggles shortcode dropdown open and closed",(0,o.A)(s().mark(function t(){var n;return s().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0}))),t.next=1,(0,i.fm)(function(){expect(i.nj.getByTitle("shortcodeTitle")).toBeInTheDocument()});case 1:n=i.nj.getByTitle("shortcodeTitle"),i.rC.click(n),expect(i.nj.getByText("widget:deny")).toBeInTheDocument(),i.rC.click(n),expect(i.nj.queryByText("widget:deny")).not.toBeInTheDocument();case 2:case"end":return t.stop()}},t)}))),it("sanitizes shortcode html on user change",function(){var t=jest.fn();(0,i.XX)(u.createElement(l.default,(0,r.A)({},e,{useShortCodes:!0,onChange:t}))),i.rC.click(i.nj.getByTestId("change-sanitize-shortcode")),expect(t).toHaveBeenCalledWith("[cf_deny]link[/cf_deny]")})})}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.