diff options
Diffstat (limited to 'devtools/client/shared/components/test/node/components/reps/helper-tests.test.js')
-rw-r--r-- | devtools/client/shared/components/test/node/components/reps/helper-tests.test.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/devtools/client/shared/components/test/node/components/reps/helper-tests.test.js b/devtools/client/shared/components/test/node/components/reps/helper-tests.test.js new file mode 100644 index 0000000000..6fc1be64a3 --- /dev/null +++ b/devtools/client/shared/components/test/node/components/reps/helper-tests.test.js @@ -0,0 +1,122 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +"use strict"; + +const { + MODE, +} = require("resource://devtools/client/shared/components/reps/reps/constants.js"); +const stubs = require("resource://devtools/client/shared/components/test/node/stubs/reps/grip-array.js"); +const { + getGripLengthBubbleText, +} = require("resource://devtools/client/shared/components/test/node/components/reps/test-helpers.js"); + +describe("getGripLengthBubbleText - Zero length", () => { + const object = stubs.get("testBasic"); + + it("length bubble is invisible", () => { + const output = ""; + let text = getGripLengthBubbleText(object, { mode: undefined }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { mode: MODE.TINY }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { mode: MODE.SHORT }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { mode: MODE.LONG }); + expect(text).toBe(output); + }); + + it("length bubble is visible", () => { + const output = "(0)"; + let text = getGripLengthBubbleText(object, { + mode: undefined, + showZeroLength: true, + }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { + mode: MODE.TINY, + showZeroLength: true, + }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { + mode: MODE.SHORT, + showZeroLength: true, + }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { + mode: MODE.LONG, + showZeroLength: true, + }); + expect(text).toBe(output); + }); +}); + +describe("getGripLengthBubbleText - Obvious length for some modes", () => { + const object = stubs.get("testMoreThanShortMaxProps"); + const visibleOutput = `(${object.preview.length})`; + + it("text renders as expected", () => { + let text = getGripLengthBubbleText(object, { mode: undefined }); + expect(text).toBe(visibleOutput); + + text = getGripLengthBubbleText(object, { mode: MODE.TINY }); + expect(text).toBe(visibleOutput); + + text = getGripLengthBubbleText(object, { mode: MODE.SHORT }); + expect(text).toBe(visibleOutput); + + text = getGripLengthBubbleText(object, { mode: MODE.LONG }); + expect(text).toBe(visibleOutput); + + const visibilityThreshold = 5; + text = getGripLengthBubbleText(object, { + mode: undefined, + visibilityThreshold, + }); + expect(text).toBe(visibleOutput); + + text = getGripLengthBubbleText(object, { + mode: MODE.TINY, + visibilityThreshold, + }); + expect(text).toBe(visibleOutput); + + text = getGripLengthBubbleText(object, { + mode: MODE.SHORT, + visibilityThreshold, + }); + expect(text).toBe(visibleOutput); + + text = getGripLengthBubbleText(object, { + mode: MODE.LONG, + visibilityThreshold, + }); + expect(text).toBe(""); + }); +}); + +describe("getGripLengthBubbleText - Visible length", () => { + const object = stubs.get("testMoreThanLongMaxProps"); + const output = `(${object.preview.length})`; + + it("length bubble is always visible", () => { + let text = getGripLengthBubbleText(object, { mode: undefined }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { mode: MODE.TINY }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { mode: MODE.SHORT }); + expect(text).toBe(output); + + text = getGripLengthBubbleText(object, { mode: MODE.LONG }); + expect(text).toBe(output); + }); +}); |