swapped crypto with uuid() for generating ids for components when customId is not supplied

This commit is contained in:
Leah Schumann 2023-06-29 06:30:49 -04:00
parent 8a119e89f4
commit aefe924060
12 changed files with 21 additions and 35 deletions

View file

@ -1,9 +1,6 @@
import { shallowMount, mount } from "@vue/test-utils"; import { shallowMount, mount } from "@vue/test-utils";
import buttonQuestion from "./button-question"; import buttonQuestion from "./button-question";
import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { getMountOptions } from "@/helpers/unit-test-helper.js";
import crypto from "crypto";
global.crypto = crypto;
describe("buttonQuestion.vue", () => { describe("buttonQuestion.vue", () => {
it("Should show overflow classes on fieldset if isOverflowScrollable is true", () => { it("Should show overflow classes on fieldset if isOverflowScrollable is true", () => {

View file

@ -1,6 +1,6 @@
import { shallowMount } from "@vue/test-utils"; import { shallowMount } from "@vue/test-utils";
import dropdownQuestion from "./dropdown-question"; import dropdownQuestion from "./dropdown-question";
import crypto from "crypto";
// Mock CMS content // Mock CMS content
const questionText = "Question Text"; const questionText = "Question Text";
@ -12,8 +12,6 @@ const mockMixin = {
}, },
}; };
global.crypto = crypto;
// TODO: Remove the following from dropdown-question.vue -> :class="(errors && errors.length) || hasError ? 'has-error' : ''" // TODO: Remove the following from dropdown-question.vue -> :class="(errors && errors.length) || hasError ? 'has-error' : ''"
// It is not being used. // It is not being used.
describe("dropdownQuestion.vue", () => { describe("dropdownQuestion.vue", () => {

View file

@ -30,27 +30,27 @@
<script> <script>
import { useField } from "vee-validate"; import { useField } from "vee-validate";
import { v4 as uuidv4 } from "uuid";
export default { export default {
name: "dropdown-question", name: "dropdown-question",
props: { props: {
modelValue: String, customDropdownId: String,
customInputId: String,
options: { options: {
type: Object, type: Object,
required: true, required: true,
}, },
modelValue: String,
isDisabled: Boolean, isDisabled: Boolean,
isRequired: Boolean, isRequired: Boolean,
validationRules: String, validationRules: String,
cmsWidgetName: String, cmsWidgetName: String,
hasError: Boolean, hasError: Boolean,
placeHolderText: String,
customDropdownId: String,
}, },
setup(props) { setup(props) {
const uuid = uuidv4();
const dropdownId = !props.customDropdownId const dropdownId = !props.customDropdownId
? `dropdown-${crypto.randomUUID()}` ? `dropdown-${uuid}`
: props.customDropdownId; : props.customDropdownId;
const propsClone = Object.assign({}, props); const propsClone = Object.assign({}, props);

View file

@ -7,15 +7,13 @@ const mockMeta = (returnValue) => jest.fn(async () => Promise.resolve(returnValu
import { shallowMount } from "@vue/test-utils"; import { shallowMount } from "@vue/test-utils";
import modal from "./modal"; import modal from "./modal";
import crypto from "crypto";
import { useForm } from "vee-validate"; import { useForm } from "vee-validate";
import { Modal } from "bootstrap"; import { Modal } from "bootstrap";
const footerButtonText = "Sample footer text here."; const footerButtonText = "Sample footer text here.";
const headerText = "Sample header text here."; const headerText = "Sample header text here.";
global.crypto = crypto;
describe("modal.vue", () => { describe("modal.vue", () => {
it("Should display modal header text when headerText is defined", async () => { it("Should display modal header text when headerText is defined", async () => {
// Arrange / Act // Arrange / Act

View file

@ -44,6 +44,7 @@
import modalButtonMain from "@/digital-components/modal/ux-components/modal-button-main/modal-button-main"; import modalButtonMain from "@/digital-components/modal/ux-components/modal-button-main/modal-button-main";
import { Modal } from "bootstrap"; import { Modal } from "bootstrap";
import { useForm } from "vee-validate"; import { useForm } from "vee-validate";
import { v4 as uuidv4 } from "uuid";
export default { export default {
name: "modal", name: "modal",
@ -58,7 +59,9 @@ export default {
}, },
}, },
setup() { setup() {
const modalId = `modal-${crypto.randomUUID()}`; const uuid = uuidv4();
const modalId = `modal-${uuid}`;
const { meta, validate, resetForm } = useForm(); const { meta, validate, resetForm } = useForm();
return { return {

View file

@ -1,6 +1,5 @@
import { shallowMount } from "@vue/test-utils"; import { shallowMount } from "@vue/test-utils";
import textboxQuestion from "./textbox-question"; import textboxQuestion from "./textbox-question";
import crypto from "crypto";
// Mock CMS content // Mock CMS content
const questionText = "Question Text"; const questionText = "Question Text";
@ -13,8 +12,6 @@ const mockMixin = {
}; };
const maska = jest.fn(); const maska = jest.fn();
global.crypto = crypto;
describe("textboxQuestion.vue", () => { describe("textboxQuestion.vue", () => {
it("Should render a text input", async () => { it("Should render a text input", async () => {
// Arrange // Arrange

View file

@ -77,13 +77,14 @@
<script> <script>
import { useField, validate } from "vee-validate"; import { useField, validate } from "vee-validate";
import { storeActions } from "@/constants/store-actions";
import loader from "@/ux-components/loader/loader.vue"; import loader from "@/ux-components/loader/loader.vue";
import { ref } from "vue"; import { ref } from "vue";
import { v4 as uuidv4 } from "uuid";
export default { export default {
name: "textbox-question", name: "textbox-question",
props: { props: {
customInputId: String,
type: { type: {
type: String, type: String,
default: "text", default: "text",
@ -97,7 +98,6 @@ export default {
default: true, default: true,
}, },
modelValue: String, modelValue: String,
customInputId: String,
isDisabled: Boolean, isDisabled: Boolean,
isRequired: Boolean, isRequired: Boolean,
hasIcon: Boolean, // If input has an icon hasIcon: Boolean, // If input has an icon
@ -120,7 +120,8 @@ export default {
centerErrorMessage: Boolean, centerErrorMessage: Boolean,
}, },
setup(props) { setup(props) {
const inputId = !props.customInputId ? `input-${crypto.randomUUID()}` : props.customInputId; const uuid = uuidv4();
const inputId = !props.customInputId ? `input-${uuid}` : props.customInputId;
const propsClone = Object.assign({}, props); const propsClone = Object.assign({}, props);
const modelValue = propsClone.modelValue; const modelValue = propsClone.modelValue;

View file

@ -1,8 +1,5 @@
import { mount } from "@vue/test-utils"; import { mount } from "@vue/test-utils";
import contentGroupModal from "./content-group-modal"; import contentGroupModal from "./content-group-modal";
import crypto from "crypto";
global.crypto = crypto;
describe("content-group-modal.vue", () => { describe("content-group-modal.vue", () => {
it("Should display header text when HeaderText is defined in the CMS", async () => { it("Should display header text when HeaderText is defined in the CMS", async () => {

View file

@ -1,6 +1,6 @@
<template> <template>
<div class="address-questions" role="application"> <div class="address-questions" >
<div class="row mb-4"> <div class="row mb-4" aria-live="polite">
<div class="col"> <div class="col">
<textboxQuestion <textboxQuestion
id="streetAddressField" id="streetAddressField"

View file

@ -2,11 +2,6 @@ import mobileLocationModalQuestions from "./mobile-location-modal-questions";
import { mount, shallowMount } from "@vue/test-utils"; import { mount, shallowMount } from "@vue/test-utils";
import { storeActions } from "@/constants/store-actions"; import { storeActions } from "@/constants/store-actions";
import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { getMountOptions } from "@/helpers/unit-test-helper.js";
import modal from "@/digital-components/modal/modal";
import crypto from "crypto";
global.crypto = crypto;
const linkWidgetName = "linkWidgetName"; const linkWidgetName = "linkWidgetName";
const modalWidgetName = "modalWidgetName"; const modalWidgetName = "modalWidgetName";

View file

@ -76,6 +76,7 @@ import {
// Validation // Validation
import { useField } from "vee-validate"; import { useField } from "vee-validate";
import { v4 as uuidv4 } from "uuid";
export default { export default {
name: "mobile-location-modal-questions", name: "mobile-location-modal-questions",
@ -89,8 +90,9 @@ export default {
}; };
}, },
setup(props) { setup(props) {
const uuid = uuidv4();
const componentId = !props.customComponentId const componentId = !props.customComponentId
? `component-${crypto.randomUUID()}` ? `component-${uuid}`
: props.customComponentId; : props.customComponentId;
// Integrate this component as a single field with an object for it's value into the page level validation // Integrate this component as a single field with an object for it's value into the page level validation

View file

@ -1,7 +1,5 @@
import { mount, shallowMount } from "@vue/test-utils"; import { mount, shallowMount } from "@vue/test-utils";
import serviceZipModalQuestion from "./service-zip-modal-question"; import serviceZipModalQuestion from "./service-zip-modal-question";
import crypto from "crypto";
global.crypto = crypto;
jest.mock("@/digital-components/textbox-question/textbox-question", () => ({ jest.mock("@/digital-components/textbox-question/textbox-question", () => ({
getCmsContent: jest.fn((widgetName, cmsFieldName) => { getCmsContent: jest.fn((widgetName, cmsFieldName) => {