Skip to content

Commit

Permalink
PXBF-1863-cypress-remove-cy-wait: Merge branch 'dev' of github.com:GS…
Browse files Browse the repository at this point in the history
…A/px-benefit-finder into 1863-cypress-remove-cy-wait
  • Loading branch information
scottqueen-bixal committed Dec 2, 2024
2 parents ac1de2b + d84c140 commit a2150a0
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 44 deletions.
47 changes: 3 additions & 44 deletions .github/workflows/test-cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ defaults:
working-directory: ./benefit-finder

jobs:

tests-chrome:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -45,7 +44,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: Chrome cypress screenshots
path: ./benefit-finder/cypress/screenshots
path: ./benefit-finder/cypress/screenshots

tests-firefox:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -77,7 +76,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: Firefox cypress screenshots
path: ./benefit-finder/cypress/screenshots
path: ./benefit-finder/cypress/screenshots

tests-edge:
runs-on: ubuntu-latest
Expand All @@ -103,50 +102,10 @@ jobs:
env: NODE_ENV=test
build: "npm run cy:build:storybook"
start: "npm run cy:run:pipeline"

- name: Edge Artifact(s)
if: failure()
uses: actions/upload-artifact@v4
with:
name: Edge cypress screenshots
path: ./benefit-finder/cypress/screenshots

tests-webkit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: "./benefit-finder/package.json"

- name: Install Submodule
run: |
cd ..
git submodule init
git submodule update
- name: Install dependencies
uses: cypress-io/github-action@v6
with:
working-directory: ./benefit-finder
build: npx playwright-webkit install-deps
runTests: false

- name: Cypress run (WebKit)
uses: cypress-io/github-action@v6
with:
working-directory: ./benefit-finder
install: false
browser: webkit
env: NODE_ENV=test
build: "npm run cy:build:storybook"
start: "npm run cy:run:pipeline"

- name: Webkit Artifact(s)
if: failure()
uses: actions/upload-artifact@v4
with:
name: Webkit cypress screenshots
path: ./benefit-finder/cypress/screenshots
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,81 @@ function _usagov_benefit_finder_content_check_criteria_has_child(int $nid) {
*/
function usagov_benefit_finder_content_form_node_bears_life_event_form_edit_form_alter(array &$form, FormStateInterface $form_state) {
$form['#validate'][] = '_usagov_benefit_finder_content_life_event_form_archived';
$form['#validate'][] = '_usagov_benefit_finder_content_check_life_event_form_criteria_depth';
}

/**
* It checks criteria depth of life event form.
* If criteria depth greater than 1, it gives error message and lists of the criteria.
*
* @param array $form
* Form array.
* @param FormStateInterface $form_state
* Form state object.
*/
function _usagov_benefit_finder_content_check_life_event_form_criteria_depth(array &$form, FormStateInterface $form_state) {
$error_flag = FALSE;
$criteria_depths = [];

$life_event_form_node = $form_state->getFormObject()->getEntity();
$sections = $life_event_form_node->get('field_b_sections_elg_criteria')->referencedEntities();

foreach ($sections as $section) {
$criterias = $section->get('field_b_criterias')->referencedEntities();

foreach ($criterias as $criteria) {
$criteria_fieldset = _usagov_benefit_finder_content_find_life_event_form_criteria_depth($criteria, 0);

foreach ($criteria_fieldset as $record) {
if ($record['depth'] > 1) {
$error_flag = TRUE;
}
$criteria_depths[] = $record;
}
}
}

if ($error_flag) {
$line = 0;
$form_state->setErrorByName(++$line, t("Benefit Finder V1 only supports one level nested criteria (depth <= 1)."));
foreach ($criteria_depths as $record) {
if ($record['depth'] > 1) {
$form_state->setErrorByName(++$line, "$record[criteriaKey] (depth=$record[depth])");
}
}
}
}

/**
* It finds criteria depth of life event form.
*
* @param $criteria
* The criteria
* @param $depth
* The depth
* @return array
* An array containing criteria key and depth.
*/
function _usagov_benefit_finder_content_find_life_event_form_criteria_depth($criteria, $depth) {
$criteria_fieldset = [];

$criteria_fieldset[] = [
"criteriaKey" => current($criteria->get('field_b_criteria_key')->referencedEntities())->get('field_b_id')->value,
"depth" => $depth,
];

$criterias_1 = $criteria->get('field_b_children')->referencedEntities();
if (!empty($criterias_1)) {
$depth++;
foreach ($criterias_1 as $criteria_1) {
$results = _usagov_benefit_finder_content_find_life_event_form_criteria_depth($criteria_1, $depth);
foreach ($results as $result) {
$criteria_fieldset[] = $result;
}
}
}

return $criteria_fieldset;
}

/**
Expand Down

0 comments on commit a2150a0

Please sign in to comment.