Skip to content

Commit 1500b13

Browse files
test(view): Added tests for relative view targeting
1 parent 67955df commit 1500b13

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

test/stateSpec.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,3 +1659,83 @@ describe("state params", function() {
16591659
}));
16601660
});
16611661
});
1662+
1663+
describe("Targeted Views", function() {
1664+
var states, scope, $compile, $injector, $q, $state, elem, $controllerProvider;
1665+
beforeEach(module('ui.router', function(_$provide_, _$controllerProvider_,_$stateProvider_) {
1666+
$stateProvider = _$stateProvider_;
1667+
states.forEach($stateProvider.state.bind($stateProvider));
1668+
}));
1669+
1670+
beforeEach(inject(function ($rootScope, _$compile_, _$injector_, _$q_, _$state_) {
1671+
scope = $rootScope.$new();
1672+
$compile = _$compile_;
1673+
$injector = _$injector_;
1674+
$q = _$q_;
1675+
$state = _$state_;
1676+
elem = angular.element('<div>');
1677+
elem.append($compile('<div><ui-view></ui-view></div>')(scope));
1678+
}));
1679+
1680+
states = [
1681+
{ name: 'A', template: "<div ui-view id='A_default'></div> <div ui-view='named' id='named_A'></div>" },
1682+
{ name: 'A.a', template: "<div ui-view id='Aa_default'>mike</div>" },
1683+
{ name: 'A.a.i', views: {
1684+
"^.named": { template: "A.a.i" },
1685+
"$default": { template: "<div ui-view id='Aai_default'>asdf</div>"}
1686+
} },
1687+
{ name: 'A.a.i.1', views: {
1688+
"^.^.named": { template: "A.a.i.1" },
1689+
"": { template: "blarg"}
1690+
} },
1691+
{ name: 'A.a.i.2', views: {
1692+
"!$default": { template: "rooted!" }
1693+
} },
1694+
{ name: 'A.a.i.3', views: {
1695+
"!$default.$default.named": { template: "fhqwhgads" }
1696+
} },
1697+
1698+
{ name: 'A.b', template: "<div ui-view id='Ab'></div>" },
1699+
{ name: 'A.b.i', views: {
1700+
"named@A": { template: "A.b.i" },
1701+
"": { template: "<div ui-view id='Abi_default'></div>"}
1702+
} },
1703+
{ name: 'A.b.i.1', views: {
1704+
"named@A": { template: "A.b.i.1" },
1705+
"": { template: "<div ui-view id='Abi1_default'></div>"}
1706+
} }
1707+
];
1708+
1709+
1710+
describe("view targetting", function() {
1711+
it("should target the unnamed view in the parent context, when the view's name is '$default'", inject(function() {
1712+
$state.go("A.a.i"); $q.flush();
1713+
expect(elem[0].querySelector("#Aa_default").textContent).toBe("asdf");
1714+
}));
1715+
1716+
it("should target the unnamed view in the parent context, when the view's name is ''", inject(function() {
1717+
$state.go("A.a.i.1"); $q.flush();
1718+
expect(elem[0].querySelector("#Aai_default").textContent).toBe("blarg");
1719+
}));
1720+
1721+
it("should relatively target a view in the grandparent context, when the viewname starts with '^.'", inject(function() {
1722+
$state.go("A.a.i"); $q.flush();
1723+
expect(elem[0].querySelector("#named_A").textContent).toBe("A.a.i");
1724+
}));
1725+
1726+
it("should relatively target a view in the great-grandparent context, when the viewname starts with '^.^.'", inject(function() {
1727+
$state.go("A.a.i.1"); $q.flush();
1728+
expect(elem[0].querySelector("#named_A").textContent).toBe("A.a.i.1");
1729+
}));
1730+
1731+
it("should target the root view, when the view's name is '!$default'", inject(function() {
1732+
$state.go("A.a.i.2"); $q.flush();
1733+
expect(elem[0].textContent).toBe("rooted!");
1734+
}));
1735+
1736+
it("should target a view absolutely using the ui-view's FQN when the view name is preceded by the '!' character", inject(function() {
1737+
$state.go("A.a.i.3"); $q.flush();
1738+
expect(elem[0].querySelector("#named_A").textContent).toBe("fhqwhgads");
1739+
}));
1740+
});
1741+
});

0 commit comments

Comments
 (0)