Skip to content

Commit

Permalink
Merge branch 'main' into simple-forms/978-safari-focus-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tlei123 committed Feb 27, 2024
2 parents 3a99559 + 17405ec commit b059f87
Show file tree
Hide file tree
Showing 188 changed files with 4,858 additions and 1,433 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -14,14 +14,11 @@ concurrency:
jobs:
build:
name: Build
runs-on: self-hosted
runs-on: ubuntu-16-cores-latest
outputs:
entry_names: ${{ steps.get-changed-apps.outputs.entry_names }}
continuous_deployment: ${{ steps.get-changed-apps.outputs.continuous_deployment }}

env:
NODE_EXTRA_CA_CERTS: /etc/ssl/certs/VA-Internal-S2-RCA1-v1.cer.pem

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -210,7 +207,7 @@ jobs:
name: Unit Tests
needs: [fetch-allow-lists, unit-tests-prep]
timeout-minutes: 30
runs-on: ubuntu-16-cores-latest
runs-on: ubuntu-latest
outputs:
app_folders: ${{ steps.get-changed-apps.outputs.folders }}
changed-files: ${{ steps.get-changed-apps.outputs.changed_files }}
Expand All @@ -222,8 +219,7 @@ jobs:
fail-fast: false
max-parallel: 72
matrix:
ci_node_index: [mock-form, ezr, post-911-gib-status, appeals, facility-locator, pre-need-integration, ask-a-question, financial-status-report, pre-need, ask-va, auth, avs, gi, hca, rated-disabilities, burial-poc-v6, burials, caregivers, check-in, claims-status, combined-debt-portal, coronavirus-research, coronavirus-screener, debt-letters, dhp-connected-devices, disability-benefits, discharge-wizard, ds-playground, ds-v3-playground, e-folders, edu-benefits, education-letters, enrollment-verification, find-forms, fry-dea, health-care-supply-reordering, income-limits, ivc-champva, letters, lgy, login, medical-copays, messages, mhv-inherited-proofing, mhv-landing-page, mhv, mock-sip-form, my-education-benefits, office-directory, pact-act, pensions, personalization, proxy-rewrite, public-outreach-materials, representative-search, representatives, resources-and-support, sah, search, simple-forms, static-pages, terms-of-use, third-party-app-directory, toe, travel-pay, vaos, verify-your-enrollment, verify, veteran-id-card, virtual-agent, vre, yellow-ribbon]

ci_node_index: [0,1,2,3,4,5,6,7,8,9]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -251,14 +247,14 @@ jobs:
output-type: 'folder'

- name: Run unit tests
run: yarn test:unit --app-folder ${{ matrix.ci_node_index }} ${APP_FOLDERS:+"{script,$APP_FOLDERS}/**/*.unit.spec.js?(x)"} --coverage
run: yarn test:unit ${APP_FOLDERS:+"{script,$APP_FOLDERS}/**/*.unit.spec.js?(x)"} --coverage
env:
MOCHA_FILE: test-results/unit-tests.xml
CHANGED_FILES: ${{ steps.get-changed-apps.outputs.changed_files }}
APP_FOLDERS: ${{ steps.get-changed-apps.outputs.folders }}
STEP: ${{ matrix.ci_node_index }}
IS_STRESS_TEST: false
NUM_CONTAINERS: 72
NUM_CONTAINERS: 10

- name: Archive unit test results
if: ${{ always() }}
Expand Down Expand Up @@ -334,12 +330,11 @@ jobs:

unit-tests-stress-test:
name: Unit Test Stability Review
runs-on: self-hosted
runs-on: ubuntu-latest
needs: [fetch-allow-lists, unit-tests-prep]
if: ${{ always() && needs.unit-tests-prep.outputs.tests-to-stress-test != '[]' && github.ref != 'refs/heads/main' }}

env:
NODE_EXTRA_CA_CERTS: /etc/ssl/certs/VA-Internal-S2-RCA1-v1.cer.pem
TESTS_TO_VERIFY: ${{ needs.unit-tests-prep.outputs.tests-to-stress-test }}
DISALLOWED_TESTS: '[]'

Expand Down
1 change: 0 additions & 1 deletion config/mocha.json
Expand Up @@ -4,7 +4,6 @@
"core-js/stable",
"regenerator-runtime/runtime",
"blob-polyfill",
"choma",
"isomorphic-fetch",
"mocha-snapshots",
"src/platform/testing/unit/mocha-setup.js",
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -150,7 +150,6 @@
"chai-dom": "^1.9.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.2",
"choma": "^1.1.0",
"clear": "^0.1.0",
"cli-spinner": "^0.2.10",
"cli-table": "^0.3.6",
Expand Down Expand Up @@ -318,7 +317,7 @@
"url-search-params-polyfill": "^8.1.1",
"uswds": "1.6.10",
"vanilla-lazyload": "^16.1.0",
"vets-json-schema": "https://github.com/department-of-veterans-affairs/vets-json-schema.git#39dd490a3031bbb28ec30acdb1efa131122a77c8"
"vets-json-schema": "https://github.com/department-of-veterans-affairs/vets-json-schema.git#9e97ed438ab16e131513e7df72712dc91db4e6a3"
},
"resolutions": {
"**/lodash": "4.17.21",
Expand Down
92 changes: 65 additions & 27 deletions script/run-unit-test.js
@@ -1,14 +1,15 @@
/* eslint-disable no-console */
const commandLineArgs = require('command-line-args');
const glob = require('glob');
const path = require('path');
const printUnitTestHelp = require('./run-unit-test-help');
const { runCommand } = require('./utils');
// For usage instructions see https://github.com/department-of-veterans-affairs/vets-website#unit-tests

const specDirs = '{src,script}';
const defaultPath = `./${specDirs}/**/*.unit.spec.js?(x)`;
// const numContainers = process.env.NUM_CONTAINERS || 10;
// const matrixStep = process.env.STEP || 1;
const numContainers = process.env.NUM_CONTAINERS || 1;
const matrixStep = process.env.STEP || 0;

const COMMAND_LINE_OPTIONS_DEFINITIONS = [
{ name: 'log-level', type: String, defaultValue: 'log' },
Expand All @@ -26,16 +27,28 @@ const COMMAND_LINE_OPTIONS_DEFINITIONS = [
defaultValue: [defaultPath],
},
];
const allUnitTests = glob.sync(defaultPath);
const allUnitTestDirs = Array.from(
new Set(
allUnitTests.map(spec =>
JSON.stringify(
path
.dirname(spec)
.split('/')
.slice(1, 4),
),
),
),
).filter(spec => spec !== undefined);

// const allUnitTests = glob.sync(defaultPath);
// function splitArray(array, chunks) {
// const [...arrayCopy] = array;
// const arrayChunks = [];
// while (arrayCopy.length) {
// arrayChunks.push(arrayCopy.splice(0, chunks));
// }
// return arrayChunks;
// }
function splitArray(array, chunks) {
const [...arrayCopy] = array;
const arrayChunks = [];
while (arrayCopy.length) {
arrayChunks.push(arrayCopy.splice(0, chunks));
}
return arrayChunks;
}
const options = commandLineArgs(COMMAND_LINE_OPTIONS_DEFINITIONS);
let coverageInclude = '';

Expand Down Expand Up @@ -77,23 +90,48 @@ if (process.env.TESTS_TO_VERIFY) {
testsToVerify = JSON.parse(process.env.TESTS_TO_VERIFY).join(' ');
}

// const splitUnitTests = splitArray(
// allUnitTests,
// Math.ceil(allUnitTests.length / numContainers),
// );
console.log('app folder selected: ', options['app-folder']);
// const testsToRun = options['app-folder']
// ? `--recursive ${options.path.map(p => `'${p}'`).join(' ')}`
// : splitUnitTests[matrixStep].join(' ');
const splitUnitTests = splitArray(
allUnitTestDirs,
Math.ceil(allUnitTestDirs.length / numContainers),
);
const appsToRun = options['app-folder']
? [options['app-folder']]
: splitUnitTests[matrixStep];
if (testsToVerify === null) {
for (const dir of appsToRun) {
const updatedPath = options['app-folder']
? options.path.map(p => `'${p}'`).join(' ')
: options.path[0].replace(
`/${specDirs}/`,
`/${JSON.parse(dir).join('/')}/`,
);
const testsToRun = options['app-folder']
? `--recursive ${updatedPath}`
: `--recursive ${glob.sync(updatedPath)}`;
const command = `LOG_LEVEL=${options[
'log-level'
].toLowerCase()} ${testRunner} --max-old-space-size=8192 --config ${configFile} ${testsToRun.replace(
/,/g,
' ',
)} `;
if (testsToRun !== '') {
runCommand(command);
} else {
console.log('This app has no tests to run');
}
}
} else {
const command = `LOG_LEVEL=${options[
'log-level'
].toLowerCase()} ${testRunner} --max-old-space-size=8192 --config ${configFile} ${testsToVerify}`;
runCommand(command);
}

// const command = `LOG_LEVEL=${options[
// 'log-level'
// ].toLowerCase()} ${testRunner} --max-old-space-size=8192 --config ${configFile} ${testsToVerify ||
// testsToRun} `;
const command = `LOG_LEVEL=${options[
'log-level'
].toLowerCase()} ${testRunner} --max-old-space-size=8192 --config ${configFile} ${testsToVerify ||
`--recursive ${options.path.map(p => `'${p}'`).join(' ')}`} `;

console.log(command);

runCommand(command);
// const command = `LOG_LEVEL=${options[
// 'log-level'
// ].toLowerCase()} ${testRunner} --max-old-space-size=8192 --config ${configFile} ${testsToVerify ||
// `--recursive ${options.path.map(p => `'${p}'`).join(' ')}`} `;
Expand Up @@ -61,7 +61,7 @@ const defaultLogSettings = {
forwardErrorsToLogs: true,
forwardConsoleLogs: ['error'],
forwardReports: [],
telemetrySampleRate: 20, // default
telemetrySampleRate: 100, // default 20
};

const initializeBrowserLogging = customLogSettings => {
Expand Down
Expand Up @@ -124,7 +124,10 @@ export const Form526Entry = ({
sessionStorage.setItem(SHOW_8940_4192, showSubforms);

// save feature flag for Toxic Exposure pages
sessionStorage.setItem(SHOW_TOXIC_EXPOSURE, showToxicExposurePages);
window.sessionStorage.setItem(
SHOW_TOXIC_EXPOSURE,
showToxicExposurePages,
);
}
// Set user account & application id in Sentry so we can access their form
// data for any thrown errors
Expand Down
@@ -1,24 +1,38 @@
import React from 'react';
import get from '@department-of-veterans-affairs/platform-forms-system/get';
import { isClaimingNew, showToxicExposurePages } from '../utils';
import { checkboxGroupSchema } from 'platform/forms-system/src/js/web-component-patterns';
import {
capitalizeEachWord,
isClaimingNew,
showToxicExposurePages,
sippableId,
} from '../utils';
import { NULL_CONDITION_STRING } from '../constants';

/**
* Checks if toggle is enabled and user is claiming at least one new condition for toxic exposure
* Checks if
* 1. toggle is enabled
* 2. at least one new condition is being claimed
* 3. at least one checkbox on the TE conditions page is selected that is not 'none'
*
* @param {*} formData
* @returns true if at least one condition is claimed for toxic exposure, false otherwise
*/
export const isClaimingTECondition = formData =>
showToxicExposurePages &&
isClaimingNew(formData) &&
Object.values(get('toxicExposureConditions', formData, {})).includes(true);
formData.toxicExposureConditions &&
Object.keys(formData.toxicExposureConditions).some(
condition =>
condition !== 'none' &&
formData.toxicExposureConditions[condition] === true,
);

export const conditionsPageTitle = 'Toxic Exposure';
export const conditionsQuestion =
'Are any of your new conditions related to toxic exposure during your military service? Check any that are related.';
export const conditionsDescription = (
<va-additional-info
class="vads-u-margin-bottom--4"
class="vads-u-margin-top--2"
trigger="What is toxic exposure?"
>
<div>
Expand All @@ -42,3 +56,100 @@ export const conditionsDescription = (
export const gulfWar1990PageTitle = 'Service locations after August 2, 1990';
export const gulfWar1990Question =
'Did you serve in any of these Gulf War locations on or after August 2, 1990? Check any locations where you served.';

/**
* Builds the Schema based on user entered condition names
*
* Example output:
{
type: 'object',
properties: {
anemia: {
type: 'boolean'
},
tinnitusringingorhissinginears: {
type: 'boolean'
},
none: {
type: 'boolean'
}
}
}
}
*
* @param {object} formData - Full formData for the form
* @returns {object} Object with id's for each condition
*/
export const makeTEConditionsSchema = formData => {
const options = (formData?.newDisabilities || []).map(disability =>
sippableId(disability.condition),
);

options.push('none');

return checkboxGroupSchema(options);
};

/**
* Builds the UI Schema based on user entered condition names.
*
* Example output:
* {
* anemia: {
* 'ui:title': 'Anemia',
* },
* tinnitusringingorhissinginears: {
* 'ui:title': 'Tinnitus (Ringing Or Hissing In Ears)',
* },
* none: {
* 'ui:title': 'I am not claiming any conditions related to toxic exposure',
* },
* }
* @param {*} formData - Full formData for the form
* @returns {object} Object with id and title for each condition
*/
export const makeTEConditionsUISchema = formData => {
const { newDisabilities = [] } = formData;
const options = {};

newDisabilities.forEach(disability => {
const { condition } = disability;

const capitalizedDisabilityName =
typeof condition === 'string'
? capitalizeEachWord(condition)
: NULL_CONDITION_STRING;

options[sippableId(condition || NULL_CONDITION_STRING)] = {
'ui:title': capitalizedDisabilityName,
};
});

options.none = {
'ui:title': 'I am not claiming any conditions related to toxic exposure',
};

return options;
};

export const noneAndConditionError =
'You selected a condition, and you also selected “I’m not claiming any conditions related to toxic exposure.” You’ll need to uncheck one of these options to continue.';

/**
* Validates selected Toxic Exposure conditions. If the 'none' checkbox is selected along with a new condition
* adds an error.
*
* @param {object} errors - Errors object from rjsf
* @param {object} formData
*/
export function validateTEConditions(errors, formData) {
const { toxicExposureConditions = {} } = formData;

if (
toxicExposureConditions.none === true &&
Object.values(toxicExposureConditions).filter(value => value === true)
.length > 1
) {
errors.toxicExposureConditions.addError(noneAndConditionError);
}
}

0 comments on commit b059f87

Please sign in to comment.