1183
1387
as_owner: _constructCategory(),
1390
window.LP = { cache: { context: { web_link: '/' } },
1391
links: { me: '~' } };
1187
1393
// A node is returned containing two
1188
1394
// '.subscription-description' nodes.
1189
1395
var node = module._get_other_descriptions_node(info);
1190
1396
Y.Assert.areEqual(
1191
1397
2, node.all('.subscription-description').size());
1401
test_no_direct_has_structural_subscriptions: function() {
1402
// With no non-personal subscriptions, and a structural
1403
// subscription, the node is still constructed because
1404
// structural subscriptions go there as well.
1406
direct: _constructCategory([{ bug: {} }]),
1407
from_duplicate: _constructCategory(),
1408
as_assignee: _constructCategory(),
1409
as_owner: _constructCategory(),
1412
window.LP = { cache: { subscription_info: ['1'] } };
1413
Y.Assert.isNotUndefined(
1414
module._get_other_descriptions_node(info));
1418
test_header: function() {
1419
// There is a subscription on the duplicate bug.
1421
direct: _constructCategory(),
1422
from_duplicate: _constructCategory([{ bug: {id: 1} }]),
1423
as_assignee: _constructCategory(),
1424
as_owner: _constructCategory(),
1428
window.LP = { links: { me: '~' } };
1430
// A returned node contains the 'other-subscriptions-header'
1431
// div with the link.
1432
var node = module._get_other_descriptions_node(info);
1433
var header = node.one('#other-subscriptions-header');
1434
Y.Assert.isNotUndefined(header);
1435
var link = header.one('a');
1436
Y.Assert.areEqual('Other subscriptions', link.get('text'));
1441
test_header_slideout: function() {
1442
// Clicking on the header slides-out the box, and
1443
// clicking it again slides it back in.
1445
direct: _constructCategory(),
1446
from_duplicate: _constructCategory([{ bug: {id: 1} }]),
1447
as_assignee: _constructCategory(),
1448
as_owner: _constructCategory(),
1452
window.LP = { links: { me: '~' } };
1454
// A returned node contains the 'other-subscriptions-header'
1455
// div with the link.
1456
var node = module._get_other_descriptions_node(info);
1457
var link = node.one('#other-subscriptions-header a');
1458
var list = node.one('#other-subscriptions-list');
1460
// Initially, the list is hidden.
1461
Y.Assert.isTrue(link.hasClass('treeCollapsed'));
1462
Y.Assert.isTrue(list.hasClass('lazr-closed'));
1463
Y.Assert.areEqual('none', list.getStyle('display'));
1465
// Clicking the link slides out the list of other subscriptions.
1466
Y.Event.simulate(Y.Node.getDOMNode(link), 'click');
1467
this.wait(function() {
1468
Y.Assert.isFalse(link.hasClass('treeCollapsed'));
1469
Y.Assert.isTrue(link.hasClass('treeExpanded'));
1470
Y.Assert.isFalse(list.hasClass('lazr-closed'));
1471
Y.Assert.areNotEqual('none', list.getStyle('display'));
1473
// Clicking it again, slides it back in.
1474
// It has to be nested inside 'wait' because we need
1475
// to wait for the first click to "finish".
1476
Y.Event.simulate(Y.Node.getDOMNode(link), 'click');
1478
this.wait(function() {
1479
Y.Assert.isTrue(link.hasClass('treeCollapsed'));
1480
Y.Assert.isFalse(link.hasClass('treeExpanded'));
1481
Y.Assert.isTrue(list.hasClass('lazr-closed'));
1277
1573
Y.Assert.areEqual(
1279
1575
this.config.subscription_info.reference);
1582
* Test for helper method to construct actions text and subscriptions list
1583
* for duplicate subscriptions:
1584
* get_unsubscribe_duplicates_text_and_subscriptions()
1586
suite.add(new Y.Test.Case({
1587
name: 'Test duplicate actions text and subscriptions list.',
1591
test_multiple_teams_fails:
1592
new Error('We can only unsubscribe a single team from ' +
1593
'multiple duplicate bugs.')
1598
window.LP = { cache: { context: { web_link: 'http://test/' } },
1599
links: { me: '~' } };
1602
tearDown: function() {
1606
test_yourself_single_bug: function() {
1607
// There is a single duplicate bug you are subscribed to.
1608
var args = { bugs: [ { self: { self_link: 'http://bug/' } } ] };
1609
var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
1611
Y.Assert.areEqual('Unsubscribe yourself from the duplicate',
1613
Y.Assert.areEqual(1, data.subscriptions.length);
1614
var sub = data.subscriptions[0];
1615
Y.Assert.areEqual(window.LP.links.me, sub.subscriber);
1616
Y.Assert.areEqual('http://bug/', sub.bug);
1619
test_yourself_multiple_bug: function() {
1620
// There is a single duplicate bug you are subscribed to.
1621
var args = { bugs: [ { self: { self_link: 'http://bug1/' } },
1622
{ self: { self_link: 'http://bug2/' } }] };
1623
var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
1625
Y.Assert.areEqual('Unsubscribe yourself from all duplicates',
1627
Y.Assert.areEqual(2, data.subscriptions.length);
1628
var sub = data.subscriptions[0];
1629
Y.Assert.areEqual(window.LP.links.me, sub.subscriber);
1630
Y.Assert.areEqual('http://bug1/', sub.bug);
1632
sub = data.subscriptions[1];
1633
Y.Assert.areEqual(window.LP.links.me, sub.subscriber);
1634
Y.Assert.areEqual('http://bug2/', sub.bug);
1637
test_team_single_bug: function() {
1638
// There is a single duplicate bug you are subscribed to.
1639
var args = { bugs: [ { self: { self_link: 'http://bug/' } } ],
1640
teams: [ { self: { self_link: 'http://team/' } } ] };
1641
var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
1643
Y.Assert.areEqual('Unsubscribe this team from the duplicate',
1645
Y.Assert.areEqual(1, data.subscriptions.length);
1646
var sub = data.subscriptions[0];
1647
Y.Assert.areEqual('http://team/', sub.subscriber);
1648
Y.Assert.areEqual('http://bug/', sub.bug);
1651
test_team_multiple_bugs: function() {
1652
// There is a single duplicate bug you are subscribed to.
1653
var args = { bugs: [ { self: { self_link: 'http://bug1/' } },
1654
{ self: { self_link: 'http://bug2/' } }],
1655
teams: [ { self: { self_link: 'http://team/' } } ] };
1656
var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
1658
Y.Assert.areEqual('Unsubscribe this team from all duplicates',
1660
Y.Assert.areEqual(2, data.subscriptions.length);
1661
var sub = data.subscriptions[0];
1662
Y.Assert.areEqual('http://team/', sub.subscriber);
1663
Y.Assert.areEqual('http://bug1/', sub.bug);
1665
sub = data.subscriptions[1];
1666
Y.Assert.areEqual('http://team/', sub.subscriber);
1667
Y.Assert.areEqual('http://bug2/', sub.bug);
1670
test_multiple_teams_fails: function() {
1671
// There is a single duplicate bug you are subscribed to.
1672
var args = { bugs: [ { self: { self_link: 'http://bug/' } } ],
1673
teams: [ { self: { self_link: 'http://team1/' } },
1674
{ self: { self_link: 'http://team2/' } }] };
1675
var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
1682
* Test for helper method to get modified object links:
1683
* add_url_element_to_links()
1685
suite.add(new Y.Test.Case({
1686
name: 'Test add_url_element_to_links helper.',
1688
compare_object_links: function (first, second) {
1689
return first.title === second.title &&
1690
first.url === second.url &&
1691
first.self === second.self;
1694
test_single_link: function () {
1695
var self = 'object stand-in',
1698
url: 'http://example.net/kumquat',
1701
modified = module._add_url_element_to_links(
1702
[original], '/avocado');
1703
Y.ArrayAssert.itemsAreEquivalent(
1704
[{title: 'Rutebega',
1705
url: 'http://example.net/kumquat/avocado',
1708
this.compare_object_links);
1709
// The original was not modified.
1710
Y.Assert.areEqual(original.url, 'http://example.net/kumquat');
1713
test_multiple_link: function () {
1714
var self1 = 'object stand-in 1',
1717
url: 'http://example.net/kumquat',
1720
self2 = 'object stand-in 2',
1723
url: 'http://example.net/abracadabra',
1726
modified = module._add_url_element_to_links(
1727
[original1, original2], '/avocado');
1728
Y.ArrayAssert.itemsAreEquivalent(
1729
[{title: 'Rutebega',
1730
url: 'http://example.net/kumquat/avocado',
1733
url: 'http://example.net/abracadabra/avocado',
1736
this.compare_object_links);
1737
// The originals were not modified.
1738
Y.Assert.areEqual(original1.url, 'http://example.net/kumquat');
1739
Y.Assert.areEqual(original2.url, 'http://example.net/abracadabra');
1745
* Test for helper method to construct action "unsubscribe" node:
1746
* get_node_for_unsubscribing()
1748
suite.add(new Y.Test.Case({
1749
name: 'Test duplicate actions text and subscriptions list.',
1751
setUp: function () {
1752
module._lp_client = new LPClient();
1753
this.wrapper_node = Y.Node.create(
1754
'<div class="subscription-description"></div>');
1755
Y.one('body').appendChild(this.wrapper_node);
1758
tearDown: function () {
1759
delete module._lp_client;
1760
this.wrapper_node.remove();
1761
var error_overlay = Y.one('.yui3-lazr-formoverlay');
1762
if (Y.Lang.isValue(error_overlay)) {
1763
error_overlay.remove();
1767
get_subscriptions: function () {
1768
// Usually multiple subscriptions will share a subscriber. This
1769
// function under test does not actually care, so we make it possible
1770
// to distinguish between the first and the second.
1771
return [{subscriber: 'http://example.net/~person1',
1772
bug: 'http://example.net/firefox/bug/1'},
1773
{subscriber: 'http://example.net/~person2',
1774
bug: 'http://example.net/firefox/bug/2'}];
1777
test_node_basic: function () {
1778
var node = module._get_node_for_unsubscribing(
1779
'Rutebega', this.get_subscriptions());
1780
Y.Assert.areEqual(node.get('text'), 'Rutebega');
1781
Y.Assert.isTrue(node.hasClass('sprite'));
1782
Y.Assert.isTrue(node.hasClass('modify'));
1783
Y.Assert.isTrue(node.hasClass('remove'));
1786
test_one_subscription_success: function () {
1787
var subscriptions = this.get_subscriptions();
1788
subscriptions.pop();
1789
Y.Assert.areEqual(subscriptions.length, 1);
1790
var node = module._get_node_for_unsubscribing(
1791
'Rutebega', subscriptions);
1792
module._lp_client.named_post.args = [];
1793
module._lp_client.named_post.halt = true;
1794
Y.one('.subscription-description').appendChild(node);
1795
node.simulate('click');
1796
// Now it is as if we are waiting for the server to reply. The
1798
Y.Assert.isTrue(node.hasClass('spinner'));
1799
Y.Assert.isFalse(node.hasClass('remove'));
1800
// Now the server replies back with a success.
1801
module._lp_client.named_post.resume();
1802
// We have no spinner.
1803
Y.Assert.isTrue(node.hasClass('remove'));
1804
Y.Assert.isFalse(node.hasClass('spinner'));
1805
// The subscriptions array is empty.
1806
Y.Assert.areEqual(subscriptions.length, 0);
1807
// We called unsubscribe on the server once, with the right arguments.
1808
Y.Assert.areEqual(module._lp_client.received.length, 1);
1809
Y.Assert.areEqual(module._lp_client.received[0][0], 'named_post');
1810
var args = module._lp_client.received[0][1];
1811
Y.Assert.areEqual(args[0], 'http://example.net/firefox/bug/1');
1812
Y.Assert.areEqual(args[1], 'unsubscribe');
1813
Y.Assert.areEqual(args[2].parameters.person,
1814
'http://example.net/~person1');
1815
// The parent node is gone, after giving some time to collapse.
1818
Y.Assert.isNull(Y.one('.subscription-description'));
1824
test_two_subscriptions_success: function () {
1825
var subscriptions = this.get_subscriptions();
1826
Y.Assert.areEqual(subscriptions.length, 2);
1827
var node = module._get_node_for_unsubscribing(
1828
'Rutebega', subscriptions);
1829
module._lp_client.named_post.args = [];
1830
Y.one('.subscription-description').appendChild(node);
1831
node.simulate('click');
1832
// The subscriptions array is empty.
1833
Y.Assert.areEqual(subscriptions.length, 0);
1834
// We called unsubscribe on the server twice, once for each
1836
Y.Assert.areEqual(module._lp_client.received.length, 2);
1839
test_failure: function () {
1840
var subscriptions = this.get_subscriptions();
1841
var node = module._get_node_for_unsubscribing(
1842
'Rutebega', subscriptions);
1843
module._lp_client.named_post.fail = true;
1844
module._lp_client.named_post.args = [
1846
{status: 400, responseText: 'Rutebegas!'}];
1847
module._lp_client.named_post.halt = true;
1848
Y.one('.subscription-description').appendChild(node);
1849
node.simulate('click');
1850
// Right now, this is as if we are waiting for the server to
1851
// reply. The link is spinning.
1852
Y.Assert.isTrue(node.hasClass('spinner'));
1853
Y.Assert.isFalse(node.hasClass('remove'));
1854
// Now the server replies with an error.
1855
module._lp_client.named_post.resume();
1856
// We have no spinner.
1857
Y.Assert.isTrue(node.hasClass('remove'));
1858
Y.Assert.isFalse(node.hasClass('spinner'));
1859
// The page has rendered the error overlay.
1860
var error_box = Y.one('.yui3-lazr-formoverlay-errors');
1861
// The way the LP error display works now is that it flashes the
1862
// problem area red for 1 second (the lazr.anim default), and
1863
// *then* shows the overlay.
1867
"The following errors were encountered: Rutebegas!",
1868
error_box.get('text'));
1878
* Test for helper method to construct actions text and subscriptions list
1879
* for team subscriptions:
1880
* get_team_unsubscribe_text_and_subscriptions()
1882
suite.add(new Y.Test.Case({
1883
name: 'Test duplicate actions text and subscriptions list.',
1887
test_multiple_teams_fails:
1888
new Error('We can only unsubscribe a single team from ' +
1889
'multiple duplicate bugs.')
1894
window.LP = { cache: { context: { bug_link: 'http://bug/' } },
1895
links: { me: '~' } };
1898
tearDown: function() {
1902
test_single_team: function() {
1903
// There is a single team you admin that is subscribed to the bug.
1904
var args = { teams: [ { self: { self_link: 'http://team/' } } ] };
1905
var data = module._get_team_unsubscribe_text_and_subscriptions(args);
1906
Y.Assert.areEqual('Unsubscribe this team', data.text);
1907
Y.Assert.areEqual(1, data.subscriptions.length);
1908
var sub = data.subscriptions[0];
1909
Y.Assert.areEqual('http://team/', sub.subscriber);
1910
Y.Assert.areEqual('http://bug/', sub.bug);
1913
test_multiple_teams: function() {
1914
// There are multiple teams you admin that are subscribed to the bug.
1915
var args = { teams: [ { self: { self_link: 'http://team1/' } },
1916
{ self: { self_link: 'http://team2/' } }] };
1917
var data = module._get_team_unsubscribe_text_and_subscriptions(args);
1918
Y.Assert.areEqual('Unsubscribe all of these teams', data.text);
1919
Y.Assert.areEqual(2, data.subscriptions.length);
1920
var sub = data.subscriptions[0];
1921
Y.Assert.areEqual('http://team1/', sub.subscriber);
1922
Y.Assert.areEqual('http://bug/', sub.bug);
1924
sub = data.subscriptions[1];
1925
Y.Assert.areEqual('http://team2/', sub.subscriber);
1926
Y.Assert.areEqual('http://bug/', sub.bug);
1929
test_multiple_teams_fails: function() {
1930
// There is a single duplicate bug you are subscribed to.
1931
var args = { bugs: [ { self: { self_link: 'http://bug/' } } ],
1932
teams: [ { self: { self_link: 'http://team1/' } },
1933
{ self: { self_link: 'http://team2/' } }] };
1934
var data = module._get_unsubscribe_duplicates_text_and_subscriptions(
1941
* Test for actions node construction.
1943
suite.add(new Y.Test.Case({
1944
name: 'Test node construction for actions.',
1947
window.LP = { cache: { context: { web_link: 'http://test/' } },
1948
links: { me: '~' } };
1951
tearDown: function() {
1955
test_change_assignees: function() {
1956
// Change assignees action.
1957
var link = module._actions.CHANGE_ASSIGNEES();
1958
Y.Assert.areEqual('Change assignees for this bug', link.get('text'));
1959
Y.Assert.areEqual('http://test/', link.get('href'));
1962
test_unsubscribe_duplicates: function() {
1963
// There is a single duplicate bug you are subscribed to.
1964
var args = { bugs: [ { self: { self_link: 'http://bug/' } } ] };
1965
var node = module._actions.UNSUBSCRIBE_DUPLICATES(args);
1966
Y.Assert.areEqual('Unsubscribe yourself from the duplicate',
1968
Y.Assert.isTrue(node.hasClass('js-action'));
1969
Y.Assert.isTrue(node.hasClass('remove'));
1972
test_set_bug_supervisor: function() {
1973
// You are the pillar owner and can set the supervisor.
1974
var args = { pillar: { title: 'Project',
1975
web_link: 'http://pillar' } };
1976
var node = module._actions.SET_BUG_SUPERVISOR(args);
1977
Y.Assert.areEqual('Set the bug supervisor for Project',
1979
Y.Assert.areEqual('http://pillar/+bugsupervisor', node.get('href'));
1982
test_contact_teams: function() {
1983
// You are only a member of the subscribed team,
1984
// so you need to contact the team admin to unsubscribe.
1985
var args = { teams: [{ title: 'Team <1>',
1988
var node = module._actions.CONTACT_TEAMS(args);
1991
'<a href="http://team/+contactuser">Team <1></a>' +
1992
' to request the administrators make a change',
1993
node.get('innerHTML'));
1994
var link = node.one('a');
1995
Y.Assert.areEqual('http://team/+contactuser', link.get('href'));