@@ -26,7 +26,7 @@ const createBCRouteCtrller = (breadcrumbs = {}, empty = false) =>
26
26
}
27
27
} ;
28
28
29
- // Resgiter a route and its controller and templates
29
+ // Register a route and its controller and templates
30
30
function setupRoute (
31
31
owner ,
32
32
{ routeName, routeClass, controllerClass, template = null }
@@ -827,7 +827,7 @@ module('Acceptance | Breadcrumbs Test', function (hooks) {
827
827
) ;
828
828
} ) ;
829
829
830
- test ( 'It recalculates breadcrumbs if visiting existing route in crumbs but with different models' , async function ( assert ) {
830
+ test ( 'It recalculates breadcrumbs if visiting existing route in crumbs but with different models (Without browser refresh) ' , async function ( assert ) {
831
831
assert . expect ( 35 ) ;
832
832
833
833
const parentWithModelRouteFallbackCrumbs = ( id ) => [
@@ -992,4 +992,133 @@ module('Acceptance | Breadcrumbs Test', function (hooks) {
992
992
assert
993
993
) ;
994
994
} ) ;
995
+
996
+ test ( 'It recalculates breadcrumbs if visiting existing route in crumbs but with different models (With browser refresh)' , async function ( assert ) {
997
+ assert . expect ( 21 ) ;
998
+
999
+ const parentWithModelRouteFallbackCrumbs = ( id ) => [
1000
+ ALL_ROUTE_CRUMB_PROPS [ 'tr-b-root' ] ,
1001
+ { ...ALL_ROUTE_CRUMB_PROPS [ 'tr-b-root/parent-with-model' ] , models : [ id ] } ,
1002
+ ] ;
1003
+
1004
+ class ParentWithModelController extends Controller {
1005
+ get breadcrumbs ( ) {
1006
+ return {
1007
+ ...ALL_ROUTE_CRUMB_PROPS [ 'tr-b-root/parent-with-model' ] ,
1008
+ models : [ this . model . id ] ,
1009
+ fallbackCrumbs : parentWithModelRouteFallbackCrumbs ( this . model . id ) ,
1010
+ } ;
1011
+ }
1012
+ }
1013
+
1014
+ // Register routes to be tested
1015
+ const routesConfig = [
1016
+ {
1017
+ routeName : 'tr-b-root/index' ,
1018
+ routeClass : createBCRoute ( ) ,
1019
+ controllerClass : createBCRouteCtrller (
1020
+ ALL_ROUTE_CRUMB_PROPS [ 'tr-b-root' ]
1021
+ ) ,
1022
+ } ,
1023
+ {
1024
+ routeName : 'tr-b-root' ,
1025
+ routeClass : createBCRoute ( ) ,
1026
+ controllerClass : createBCRouteCtrller ( { } , true ) ,
1027
+ template : hbs `
1028
+ <AkStack @spacing="1" @direction="column" class="px-2" data-test-rootBTemplate-container>
1029
+ Root B
1030
+
1031
+ <AkLink @route="authenticated.tr-b-root.parent-with-model" @model="1" data-test-linkToRootBParentWithModel1>
1032
+ Link to Root B - Parent With Model 1
1033
+ </AkLink>
1034
+
1035
+ <AkLink @route="authenticated.tr-b-root.parent-with-model" @models={{array 2}} data-test-linkToRootBParentWithModel2>
1036
+ Link to Root B - Parent With Model 2
1037
+ </AkLink>
1038
+
1039
+ {{outlet}}
1040
+ </AkStack>
1041
+ ` ,
1042
+ } ,
1043
+ {
1044
+ routeName : 'tr-b-root/parent-with-model' ,
1045
+ routeClass : createBCRoute ( ) ,
1046
+ controllerClass : ParentWithModelController ,
1047
+ template : hbs `
1048
+ <AkStack @spacing="1" @direction="column" class="px-2 my-2" data-test-rootAParentBTemplate-container>
1049
+ Root B - Parent With Model - {{@model.id}}
1050
+
1051
+ <AkDivider @color='dark' />
1052
+
1053
+ <AkStack @spacing="1" @direction="column">
1054
+ Parent With Model ({{@model.id}}) - Route Breadcrumb Items
1055
+
1056
+ <AkBreadcrumbs::AutoTrail />
1057
+ </AkStack>
1058
+
1059
+ <AkLink @route="authenticated.tr-b-root.parent-with-model.child" @models={{array @model.id}} data-test-LinkToRootBParentWithModelChild>
1060
+ Link to Parent With Model ({{@model.id}}) Child
1061
+ </AkLink>
1062
+
1063
+ {{outlet}}
1064
+ </AkStack>
1065
+ ` ,
1066
+ } ,
1067
+ ] ;
1068
+
1069
+ routesConfig . forEach ( ( route ) => setupRoute ( this . owner , route ) ) ;
1070
+
1071
+ // Start of test
1072
+ await visit ( '/tr-b-root' ) ;
1073
+
1074
+ assert . strictEqual ( currentURL ( ) , '/tr-b-root' , 'Route is at Root B' ) ;
1075
+
1076
+ assert . dom ( '[data-test-linkToRootBParentWithModel1]' ) . exists ( ) ;
1077
+ assert . dom ( '[data-test-linkToRootBParentWithModel2]' ) . exists ( ) ;
1078
+
1079
+ // Go to route with model with ID of 1
1080
+ await click ( '[data-test-linkToRootBParentWithModel1]' ) ;
1081
+
1082
+ const akBreadcrumbsService = this . owner . lookup ( 'service:ak-breadcrumbs' ) ;
1083
+
1084
+ let expectedCrumbs = [
1085
+ ALL_ROUTE_CRUMB_PROPS [ 'tr-b-root' ] ,
1086
+ {
1087
+ ...ALL_ROUTE_CRUMB_PROPS [ 'tr-b-root/parent-with-model' ] ,
1088
+ models : [ 1 ] ,
1089
+ } ,
1090
+ ] ;
1091
+
1092
+ doBreadcrumbItemsCompare (
1093
+ akBreadcrumbsService . breadcrumbItems ,
1094
+ expectedCrumbs ,
1095
+ assert
1096
+ ) ;
1097
+
1098
+ // Get router service
1099
+ const router = this . owner . lookup ( 'service:router' ) ;
1100
+
1101
+ // Reset router namespace simulates a window reload
1102
+ router . _router . reset ( ) ;
1103
+
1104
+ const routeHandler = ( transition ) => {
1105
+ if ( transition . to . name === 'authenticated.tr-b-root.parent-with-model' ) {
1106
+ // Ensure that routeFrom is null. Similar to a page refresh
1107
+ // eslint-disable-next-line qunit/no-conditional-assertions
1108
+ assert . strictEqual ( transition . from , null ) ;
1109
+ }
1110
+ } ;
1111
+
1112
+ router . on ( 'routeWillChange' , routeHandler ) ;
1113
+
1114
+ // Go to parent route with model with ID of 2
1115
+ await visit ( '/tr-b-root/parent-with-model/2' ) ;
1116
+
1117
+ // Defaults to fallback crumbs
1118
+ doBreadcrumbItemsCompare (
1119
+ akBreadcrumbsService . breadcrumbItems ,
1120
+ parentWithModelRouteFallbackCrumbs ( 2 ) ,
1121
+ assert
1122
+ ) ;
1123
+ } ) ;
995
1124
} ) ;
0 commit comments