@@ -19,7 +19,7 @@ import {
1919import { fireEvent , render , screen } from "@testing-library/react" ;
2020
2121import { AnytimeActionSearch } from "@/components/dashboard/AnytimeActionSearch" ;
22- import { taskIdLicenseNameMapping } from "@businessnjgovnavigator/shared/index" ;
22+ import { getMergedConfig , taskIdLicenseNameMapping } from "@businessnjgovnavigator/shared/index" ;
2323import userEvent from "@testing-library/user-event" ;
2424
2525function setupMockAnalytics ( ) : typeof analytics {
@@ -50,6 +50,8 @@ describe("<AnytimeActionSearch />", () => {
5050 const taskName = "some-task-name" ;
5151 const licenseReinstatementName = "some-license-reinstatement-name" ;
5252
53+ const Config = getMergedConfig ( ) ;
54+
5355 const anytimeActionTasksAlternate = [
5456 generateAnytimeActionTask ( {
5557 name : "test-title-1" ,
@@ -226,6 +228,7 @@ describe("<AnytimeActionSearch />", () => {
226228 filename : "some-filename-license" ,
227229 } ) ,
228230 ] ;
231+ anytimeActionTasksFromNonEssentialQuestions = [ ] ;
229232 } ) ;
230233
231234 const renderAnytimeActionSearch = ( ) : void => {
@@ -398,6 +401,60 @@ describe("<AnytimeActionSearch />", () => {
398401 expect ( screen . queryByText ( "license - hvac-reinstatement" ) ) . not . toBeInTheDocument ( ) ;
399402 } ) ;
400403
404+ it ( "creates and moves anytime action to recommended for you section when flag is set" , ( ) => {
405+ anytimeActionTasks = [
406+ generateAnytimeActionTask ( {
407+ filename : "vacant-building-fire-permit" ,
408+ moveToRecommendedForYouSection : true ,
409+ } ) ,
410+ ...anytimeActionTasks ,
411+ ] ;
412+ anytimeActionTasksFromNonEssentialQuestions = [ ] ;
413+
414+ useMockBusiness ( {
415+ profileData : generateProfileData ( {
416+ vacantPropertyOwner : true ,
417+ } ) ,
418+ } ) ;
419+ renderAnytimeActionSearch ( ) ;
420+ fireEvent . click ( screen . getByLabelText ( "Open" ) ) ;
421+ const nonEssentialAnytimeAction = screen . getByTestId ( "vacant-building-fire-permit-option" ) ;
422+ const recommendedForYouCategory = screen . getByText (
423+ Config . dashboardAnytimeActionDefaults . recommendedForYouCategoryHeader ,
424+ ) ;
425+ const category1Title = screen . getByText ( "Some Category" ) ;
426+ expect ( recommendedForYouCategory . compareDocumentPosition ( nonEssentialAnytimeAction ) ) . toBe (
427+ Node . DOCUMENT_POSITION_FOLLOWING ,
428+ ) ;
429+ expect ( nonEssentialAnytimeAction . compareDocumentPosition ( category1Title ) ) . toBe (
430+ Node . DOCUMENT_POSITION_FOLLOWING ,
431+ ) ;
432+ } ) ;
433+
434+ it ( "does not creates recommended for you section when flag is set and nonEssentialQuestions is empty" , ( ) => {
435+ anytimeActionTasks = [
436+ generateAnytimeActionTask ( {
437+ filename : "vacant-building-fire-permit" ,
438+ moveToRecommendedForYouSection : false ,
439+ } ) ,
440+ ...anytimeActionTasks ,
441+ ] ;
442+
443+ anytimeActionTasksFromNonEssentialQuestions = [ ] ;
444+
445+ useMockBusiness ( {
446+ profileData : generateProfileData ( {
447+ vacantPropertyOwner : true ,
448+ } ) ,
449+ } ) ;
450+ renderAnytimeActionSearch ( ) ;
451+ fireEvent . click ( screen . getByLabelText ( "Open" ) ) ;
452+ expect ( screen . getByTestId ( "vacant-building-fire-permit-option" ) ) . toBeInTheDocument ( ) ;
453+ expect (
454+ screen . queryByText ( Config . dashboardAnytimeActionDefaults . recommendedForYouCategoryHeader ) ,
455+ ) . not . toBeInTheDocument ( ) ;
456+ } ) ;
457+
401458 describe ( "non essential questions" , ( ) => {
402459 it ( "duplicate Anytime Actions added via non-essential questions are removed" , ( ) => {
403460 const duplicateAnytimeAction = generateAnytimeActionTask ( {
@@ -413,10 +470,35 @@ describe("<AnytimeActionSearch />", () => {
413470 expect ( screen . getAllByText ( "same-anytime-action" ) . length ) . toBe ( 1 ) ;
414471 } ) ;
415472
473+ it ( "promotes non essential questions to the recommended for you section" , ( ) => {
474+ anytimeActionTasksFromNonEssentialQuestions = [
475+ generateAnytimeActionTask ( { filename : "vacant-building-fire-permit" } ) ,
476+ ...anytimeActionTasksFromNonEssentialQuestions ,
477+ ] ;
478+
479+ useMockBusiness ( {
480+ profileData : generateProfileData ( {
481+ vacantPropertyOwner : true ,
482+ } ) ,
483+ } ) ;
484+ renderAnytimeActionSearch ( ) ;
485+ fireEvent . click ( screen . getByLabelText ( "Open" ) ) ;
486+ const nonEssentialAnytimeAction = screen . getByTestId ( "vacant-building-fire-permit-option" ) ;
487+ const recommendedForYouCategory = screen . getByText (
488+ Config . dashboardAnytimeActionDefaults . recommendedForYouCategoryHeader ,
489+ ) ;
490+ const category1Title = screen . getByText ( "Some Category" ) ;
491+ expect ( recommendedForYouCategory . compareDocumentPosition ( nonEssentialAnytimeAction ) ) . toBe (
492+ Node . DOCUMENT_POSITION_FOLLOWING ,
493+ ) ;
494+ expect ( nonEssentialAnytimeAction . compareDocumentPosition ( category1Title ) ) . toBe (
495+ Node . DOCUMENT_POSITION_FOLLOWING ,
496+ ) ;
497+ } ) ;
498+
416499 it ( "adds vacant property anytime action for vacant property owners" , ( ) => {
417500 anytimeActionTasks = [
418501 generateAnytimeActionTask ( { filename : "vacant-building-fire-permit" } ) ,
419- ...anytimeActionTasks ,
420502 ] ;
421503 useMockBusiness ( {
422504 profileData : generateProfileData ( {
@@ -440,7 +522,6 @@ describe("<AnytimeActionSearch />", () => {
440522 it ( "adds fire carnival modification for carnival ride owning businesses" , ( ) => {
441523 anytimeActionTasks = [
442524 generateAnytimeActionTask ( { filename : "carnival-ride-supplemental-modification" } ) ,
443- ...anytimeActionTasks ,
444525 ] ;
445526 useMockBusiness ( {
446527 profileData : generateProfileData ( {
@@ -468,7 +549,6 @@ describe("<AnytimeActionSearch />", () => {
468549 it ( "adds operating carnival fire permit for carnival owning businesses" , ( ) => {
469550 anytimeActionTasks = [
470551 generateAnytimeActionTask ( { filename : "operating-carnival-fire-permit" } ) ,
471- ...anytimeActionTasks ,
472552 ] ;
473553 useMockBusiness ( {
474554 profileData : generateProfileData ( {
@@ -496,7 +576,6 @@ describe("<AnytimeActionSearch />", () => {
496576 it ( "adds operating carnival fire permit for traveling circus or carnival owning businesses" , ( ) => {
497577 anytimeActionTasks = [
498578 generateAnytimeActionTask ( { filename : "operating-carnival-fire-permit" } ) ,
499- ...anytimeActionTasks ,
500579 ] ;
501580 useMockBusiness ( {
502581 profileData : generateProfileData ( {
@@ -524,7 +603,6 @@ describe("<AnytimeActionSearch />", () => {
524603 it ( "adds operating carnival fire permit for traveling circus or carnival owning businesses based on non-essential question answers" , ( ) => {
525604 anytimeActionTasks = [
526605 generateAnytimeActionTask ( { filename : "operating-carnival-fire-permit" } ) ,
527- ...anytimeActionTasks ,
528606 ] ;
529607 useMockBusiness ( {
530608 profileData : generateProfileData ( {
@@ -560,7 +638,6 @@ describe("<AnytimeActionSearch />", () => {
560638 it ( "adds carnival ride supplemental modification for traveling circus or carnival owning businesses based on non-essential question answers" , ( ) => {
561639 anytimeActionTasks = [
562640 generateAnytimeActionTask ( { filename : "carnival-ride-supplemental-modification" } ) ,
563- ...anytimeActionTasks ,
564641 ] ;
565642 useMockBusiness ( {
566643 profileData : generateProfileData ( {
0 commit comments