-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17256 from emberjs/impl-build-routeinfo-metadata
[FEATURE] Impl. buildRouteInfoMetadata
- Loading branch information
Showing
7 changed files
with
309 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
packages/ember/tests/routing/router_service_test/build_routeinfo_metadata_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
import { | ||
EMBER_ROUTING_ROUTER_SERVICE, | ||
EMBER_ROUTING_BUILD_ROUTEINFO_METADATA, | ||
} from '@ember/canary-features'; | ||
import { RouterTestCase, moduleFor } from 'internal-test-helpers'; | ||
import { inject as service } from '@ember/service'; | ||
import { Route } from '@ember/-internals/routing'; | ||
|
||
if (EMBER_ROUTING_BUILD_ROUTEINFO_METADATA && EMBER_ROUTING_ROUTER_SERVICE) { | ||
moduleFor( | ||
'buildRouteInfoMetadata', | ||
class extends RouterTestCase { | ||
'@test basic metadata'(assert) { | ||
this.add( | ||
`route:application`, | ||
Route.extend({ | ||
router: service('router'), | ||
init() { | ||
this._super(...arguments); | ||
|
||
this.router.on('routeDidChange', transition => { | ||
assert.equal(transition.to.name, 'parent.index'); | ||
assert.equal(transition.to.metadata, 'parent-index-page'); | ||
}); | ||
}, | ||
}) | ||
); | ||
|
||
this.add( | ||
`route:parent.index`, | ||
Route.extend({ | ||
buildRouteInfoMetadata() { | ||
return 'parent-index-page'; | ||
}, | ||
}) | ||
); | ||
|
||
return this.visit('/'); | ||
} | ||
|
||
'@test hierarchical metadata'(assert) { | ||
this.add( | ||
`route:application`, | ||
Route.extend({ | ||
router: service('router'), | ||
buildRouteInfoMetadata() { | ||
return 'application-shell'; | ||
}, | ||
init() { | ||
this._super(...arguments); | ||
|
||
this.router.on('routeDidChange', transition => { | ||
assert.equal(transition.to.name, 'parent.index'); | ||
assert.equal(transition.to.metadata, 'parent-index-page'); | ||
assert.equal(transition.to.parent.name, 'parent'); | ||
assert.equal(transition.to.parent.metadata, 'parent-page'); | ||
assert.equal(transition.to.parent.parent.name, 'application'); | ||
assert.equal(transition.to.parent.parent.metadata, 'application-shell'); | ||
}); | ||
}, | ||
}) | ||
); | ||
|
||
this.add( | ||
`route:parent`, | ||
Route.extend({ | ||
buildRouteInfoMetadata() { | ||
return 'parent-page'; | ||
}, | ||
}) | ||
); | ||
|
||
this.add( | ||
`route:parent.index`, | ||
Route.extend({ | ||
buildRouteInfoMetadata() { | ||
return 'parent-index-page'; | ||
}, | ||
}) | ||
); | ||
|
||
return this.visit('/'); | ||
} | ||
|
||
'@test metadata can be complex objects'(assert) { | ||
this.add( | ||
`route:application`, | ||
Route.extend({ | ||
router: service('router'), | ||
init() { | ||
this._super(...arguments); | ||
|
||
this.router.on('routeDidChange', transition => { | ||
assert.equal(transition.to.name, 'parent.index'); | ||
assert.equal(transition.to.metadata.name, 'parent-index-page'); | ||
assert.equal(transition.to.metadata.title('PARENT'), 'My Name is PARENT'); | ||
}); | ||
}, | ||
}) | ||
); | ||
|
||
this.add(`route:parent`, Route.extend({})); | ||
|
||
this.add( | ||
`route:parent.index`, | ||
Route.extend({ | ||
buildRouteInfoMetadata() { | ||
return { | ||
name: 'parent-index-page', | ||
title: name => `My Name is ${name}`, | ||
}; | ||
}, | ||
}) | ||
); | ||
|
||
return this.visit('/'); | ||
} | ||
|
||
'@test metadata is placed on the `from`'(assert) { | ||
assert.expect(6); | ||
this.add( | ||
`route:application`, | ||
Route.extend({ | ||
router: service('router'), | ||
init() { | ||
this._super(...arguments); | ||
|
||
this.router.on('routeDidChange', transition => { | ||
if (transition.to.name === 'parent.index') { | ||
assert.equal(transition.to.metadata.name, 'parent-index-page'); | ||
assert.equal(transition.to.metadata.title('INDEX'), 'My Name is INDEX'); | ||
} else { | ||
assert.equal(transition.from.metadata.name, 'parent-index-page'); | ||
assert.equal(transition.from.metadata.title('INDEX'), 'My Name is INDEX'); | ||
assert.equal(transition.to.metadata.name, 'parent-child-page'); | ||
assert.equal(transition.to.metadata.title('CHILD'), 'My Name is CHILD!!'); | ||
} | ||
}); | ||
}, | ||
}) | ||
); | ||
|
||
this.add(`route:parent`, Route.extend({})); | ||
|
||
this.add( | ||
`route:parent.index`, | ||
Route.extend({ | ||
buildRouteInfoMetadata() { | ||
return { | ||
name: 'parent-index-page', | ||
title: name => `My Name is ${name}`, | ||
}; | ||
}, | ||
}) | ||
); | ||
|
||
this.add( | ||
`route:parent.child`, | ||
Route.extend({ | ||
buildRouteInfoMetadata() { | ||
return { | ||
name: 'parent-child-page', | ||
title: name => `My Name is ${name}!!`, | ||
}; | ||
}, | ||
}) | ||
); | ||
|
||
return this.visit('/').then(() => { | ||
return this.visit('/child'); | ||
}); | ||
} | ||
|
||
'@test can be used with model data from `attributes`'(assert) { | ||
assert.expect(6); | ||
this.add( | ||
`route:application`, | ||
Route.extend({ | ||
router: service('router'), | ||
init() { | ||
this._super(...arguments); | ||
|
||
this.router.on('routeDidChange', transition => { | ||
if (transition.to.name === 'parent.index') { | ||
assert.equal(transition.to.metadata.name, 'parent-index-page'); | ||
assert.equal( | ||
transition.to.metadata.title(transition.to.attributes), | ||
'My Name is INDEX' | ||
); | ||
} else { | ||
assert.equal(transition.from.metadata.name, 'parent-index-page'); | ||
assert.equal( | ||
transition.from.metadata.title(transition.from.attributes), | ||
'My Name is INDEX' | ||
); | ||
assert.equal(transition.to.metadata.name, 'parent-child-page'); | ||
assert.equal( | ||
transition.to.metadata.title(transition.to.attributes), | ||
'My Name is CHILD!!' | ||
); | ||
} | ||
}); | ||
}, | ||
}) | ||
); | ||
|
||
this.add(`route:parent`, Route.extend({})); | ||
|
||
this.add( | ||
`route:parent.index`, | ||
Route.extend({ | ||
model() { | ||
return { name: 'INDEX' }; | ||
}, | ||
buildRouteInfoMetadata() { | ||
return { | ||
name: 'parent-index-page', | ||
title: model => `My Name is ${model.name}`, | ||
}; | ||
}, | ||
}) | ||
); | ||
|
||
this.add( | ||
`route:parent.child`, | ||
Route.extend({ | ||
model() { | ||
return { name: 'CHILD' }; | ||
}, | ||
buildRouteInfoMetadata() { | ||
return { | ||
name: 'parent-child-page', | ||
title: model => `My Name is ${model.name}!!`, | ||
}; | ||
}, | ||
}) | ||
); | ||
|
||
return this.visit('/').then(() => { | ||
return this.visit('/child'); | ||
}); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters