Merge lp:~benji/launchpad/add-edit-tests-2 into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 12781
Proposed branch: lp:~benji/launchpad/add-edit-tests-2
Merge into: lp:launchpad
Prerequisite: lp:~benji/launchpad/ss-test-refactorings
Diff against target: 320 lines (+269/-9)
2 files modified
lib/lp/registry/javascript/structural-subscription.js (+12/-1)
lib/lp/registry/javascript/tests/test_structural_subscription.js (+257/-8)
To merge this branch: bzr merge lp:~benji/launchpad/add-edit-tests-2
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+56832@code.launchpad.net

Commit message

[r=jcsackett][no-qa] add tests for structural subscriptions subscribe/edit/unsubscribe workflow

Description of the change

This branch adds workflow tests for adding bug notification
subscriptions, editing them, and unsubscribing from them. The intent is
to test the basic workflow in each scenario as well as provide a good
framework for more tests in the future.

The tests can be run by loading
lib/lp/registry/javascript/tests/test_structural_subscription.html in a
browser.

There is not lint reported for the added/changed lines but there is
quite a bit for the pre-existing lines. Fixes for those are in a
forthcoming branch in order to keep this branch sane.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/registry/javascript/structural-subscription.js'
--- lib/lp/registry/javascript/structural-subscription.js 2011-04-07 14:16:39 +0000
+++ lib/lp/registry/javascript/structural-subscription.js 2011-04-08 13:43:45 +0000
@@ -1050,6 +1050,17 @@
1050 };1050 };
1051}1051}
10521052
1053// If set, this will be used instead of Y.io. This is for testing.
1054namespace._Y_io_hook = null;
1055
1056function do_io(link, config) {
1057 var yio = Y.io;
1058 if (namespace._Y_io_hook) {
1059 yio = namespace._Y_io_hook;
1060 }
1061 yio(link, config);
1062}
1063
1053/**1064/**
1054 * Construct a handler for an unsubscribe link.1065 * Construct a handler for an unsubscribe link.
1055 */1066 */
@@ -1082,7 +1093,7 @@
1082 failure: error_handler.getFailureHandler()1093 failure: error_handler.getFailureHandler()
1083 }1094 }
1084 };1095 };
1085 Y.io(filter.self_link, y_config);1096 do_io(filter.self_link, y_config);
1086 };1097 };
1087}1098}
10881099
10891100
=== modified file 'lib/lp/registry/javascript/tests/test_structural_subscription.js'
--- lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-07 23:44:25 +0000
+++ lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-08 13:43:45 +0000
@@ -5,7 +5,7 @@
5 filter: 'raw',5 filter: 'raw',
6 combine: false,6 combine: false,
7 fetchCSS: false7 fetchCSS: false
8 }).use('test', 'console', 'node', 'lp.client',8 }).use('test', 'console', 'node', 'node-event-simulate', 'lp.client',
9 'lp.registry.structural_subscription', function(Y) {9 'lp.registry.structural_subscription', function(Y) {
1010
11 var suite = new Y.Test.Suite("Structural subscription overlay tests");11 var suite = new Y.Test.Suite("Structural subscription overlay tests");
@@ -41,13 +41,16 @@
41 }41 }
4242
43 function create_test_node(include_listing) {43 function create_test_node(include_listing) {
44 return Y.Node.create(44 var test_node = Y.Node.create('<div id="test-content">')
45 '<div id="test-content">' +45 .append(Y.Node.create('<div></div>')
46 ' <div id="' + content_box_name + '"></div>' +46 .set('id', content_box_name))
47 (include_listing47
48 ? (' <div id="' + subscription_listing_name + '"></div>')48 if (include_listing) {
49 : '') +49 test_node.append(Y.Node.create('<div style="width: 50%"></div>')
50 '</div>');50 .set('id', subscription_listing_name));
51 }
52
53 return test_node;
51 }54 }
5255
53 function remove_test_node() {56 function remove_test_node() {
@@ -846,6 +849,252 @@
846 }));849 }));
847850
848 suite.add(new Y.Test.Case({851 suite.add(new Y.Test.Case({
852<<<<<<< TREE
853 name: 'Structural Subscription: add subcription workflow',
854
855 _should: {error: {}},
856
857 setUp: function() {
858 var TestBugFilter = function() {};
859 TestBugFilter.prototype = {
860 'getAttrs': function () {
861 return {};
862 }
863 };
864 // We need an lp_client that will appear to succesfully create the
865 // bug filter.
866 var TestClient = function() {};
867 TestClient.prototype = {
868 named_post: function (uri, operation_name, config) {
869 config.on.success(new TestBugFilter());
870 this.post_called = true;
871 },
872 patch: function(uri, representation, config, headers) {
873 config.on.success();
874 this.patch_called = true;
875 },
876 post_called: false,
877 patch_called: false
878 };
879
880 this.original_lp = monkeypatch_LP();
881
882 this.configuration = {
883 content_box: content_box_id,
884 lp_client: new TestClient()
885 };
886 this.content_node = create_test_node();
887 Y.one('body').appendChild(this.content_node);
888 },
889
890 tearDown: function() {
891 window.LP = this.original_lp;
892 remove_test_node();
893 delete this.content_node;
894 },
895
896 test_simple_add_workflow: function() {
897 // Clicking on the "Subscribe to bug mail" link and then clicking
898 // on the overlay form's "OK" button results in a filter being
899 // created and PATCHed.
900 module.setup(this.configuration);
901 Y.one('a.menu-link-subscribe_to_bug_mail').simulate('click');
902 Assert.isFalse(module.lp_client.post_called);
903 Assert.isFalse(module.lp_client.patch_called);
904 var button = Y.one('.yui3-lazr-formoverlay-actions button');
905 Assert.areEqual(button.get('text'), 'OK');
906 button.simulate('click');
907 Assert.isTrue(module.lp_client.post_called);
908 Assert.isTrue(module.lp_client.patch_called);
909 },
910
911 test_simple_add_workflow_cancled: function() {
912 // Clicking on the "Subscribe to bug mail" link and then clicking
913 // on the overlay form's cancel button results in no filter being
914 // created or PATCHed.
915 module.setup(this.configuration);
916 Y.one('a.menu-link-subscribe_to_bug_mail').simulate('click');
917 Assert.isFalse(module.lp_client.post_called);
918 Assert.isFalse(module.lp_client.patch_called);
919 var button = Y.one(
920 '.yui3-lazr-formoverlay-actions button+button');
921 Assert.areEqual(button.get('text'), 'Cancel');
922 button.simulate('click');
923 Assert.isFalse(module.lp_client.post_called);
924 Assert.isFalse(module.lp_client.patch_called);
925 }
926
927 }));
928
929 suite.add(new Y.Test.Case({
930 name: 'Structural Subscription: edit subcription workflow',
931
932 _should: {error: {}},
933
934 setUp: function() {
935 var TestBugFilter = function(data) {
936 if (data !== undefined) {
937 this._data = data;
938 } else {
939 this._data = {};
940 }
941 };
942 TestBugFilter.prototype = {
943 'getAttrs': function () {
944 return this._data;
945 }
946 };
947 // We need an lp_client that will appear to succesfully create the
948 // bug filter.
949 var TestClient = function() {
950 this.post_called = false;
951 this.patch_called = false;
952 };
953 TestClient.prototype = {
954 named_post: function (uri, operation_name, config) {
955 config.on.success(new TestBugFilter());
956 this.post_called = true;
957 },
958 patch: function(uri, representation, config, headers) {
959 config.on.success(new TestBugFilter(representation));
960 this.patch_called = true;
961 }
962 };
963
964 this.original_lp = monkeypatch_LP();
965
966 LP.cache.subscription_info = [{
967 target_url: 'http://example.com',
968 target_title:'Example project',
969 filters: [{
970 filter: {
971 description: 'DESCRIPTION',
972 statuses: [],
973 importances: [],
974 tags: [],
975 find_all_tags: true,
976 bug_notification_level: 'Discussion',
977 self_link: 'http://example.com/a_filter'
978 },
979 can_mute: true,
980 is_muted: false,
981 subscriber_is_team: false,
982 subscriber_url: 'http://example.com/subscriber',
983 subscriber_title: 'Thidwick',
984 user_is_team_admin: false
985 }]
986 }];
987
988
989 this.configuration = {
990 content_box: content_box_id,
991 lp_client: new TestClient()
992 };
993 this.content_node = create_test_node(true);
994 Y.one('body').appendChild(this.content_node);
995 },
996
997 tearDown: function() {
998 window.LP = this.original_lp;
999 remove_test_node();
1000 delete this.content_node;
1001 },
1002
1003 test_simple_edit_workflow: function() {
1004 module.setup_bug_subscriptions(this.configuration);
1005
1006 // Editing a value via the edit link and dialog causes the
1007 // subscription list to reflect the new value.
1008 var label = Y.one('.filter-name span').get('text');
1009 Assert.isTrue(label.indexOf('DESCRIPTION') !== -1);
1010
1011 // No PATCHing has happened yet.
1012 Assert.isFalse(module.lp_client.patch_called);
1013
1014 // Click the edit link.
1015 Y.one('a.edit-subscription').simulate('click');
1016
1017 // Set a new name (description) and click OK.
1018 Y.one('input[name="name"]').set('value', 'NEW VALUE');
1019 var button = Y.one('.yui3-lazr-formoverlay-actions button');
1020 Assert.areEqual(button.get('text'), 'OK');
1021 button.simulate('click');
1022
1023 // Clicking OK resulted in the bug filter being PATCHed.
1024 Assert.isTrue(module.lp_client.patch_called);
1025 // And the new value is reflected in the subscription listing.
1026 label = Y.one('.filter-name span').get('text');
1027 Assert.isTrue(label.indexOf('NEW VALUE') !== -1);
1028 }
1029
1030 }));
1031
1032 suite.add(new Y.Test.Case({
1033 name: 'Structural Subscription: unsubscribing',
1034
1035 _should: {error: {}},
1036
1037 setUp: function() {
1038 var TestClient = function() {};
1039 this.original_lp = monkeypatch_LP();
1040
1041 LP.cache.subscription_info = [{
1042 target_url: 'http://example.com',
1043 target_title:'Example project',
1044 filters: [{
1045 filter: {
1046 description: 'DESCRIPTION',
1047 statuses: [],
1048 importances: [],
1049 tags: [],
1050 find_all_tags: true,
1051 bug_notification_level: 'Discussion',
1052 self_link: 'http://example.com/a_filter'
1053 },
1054 can_mute: true,
1055 is_muted: false,
1056 subscriber_is_team: false,
1057 subscriber_url: 'http://example.com/subscriber',
1058 subscriber_title: 'Thidwick',
1059 user_is_team_admin: false
1060 }]
1061 }];
1062
1063 this.configuration = {
1064 content_box: content_box_id,
1065 lp_client: new TestClient()
1066 };
1067 this.content_node = create_test_node(true);
1068 Y.one('body').appendChild(this.content_node);
1069 },
1070
1071 tearDown: function() {
1072 window.LP = this.original_lp;
1073 remove_test_node();
1074 delete this.content_node;
1075 },
1076
1077 test_simple_unsubscribe: function() {
1078 // Clicking on the unsubscribe link will result in a DELETE being
1079 // sent and the filter description being removed.
1080
1081 var DELETE_performed = false;
1082 // Fake a DELETE that succeeds.
1083 module._Y_io_hook = function (link, config) {
1084 DELETE_performed = true;
1085 config.on.success();
1086 };
1087
1088 module.setup_bug_subscriptions(this.configuration);
1089 Y.one('a.delete-subscription').simulate('click');
1090 Assert.isTrue(DELETE_performed);
1091 }
1092
1093 }));
1094
1095 suite.add(new Y.Test.Case({
1096=======
1097>>>>>>> MERGE-SOURCE
849 name: 'Add a subscription from +subscriptions page',1098 name: 'Add a subscription from +subscriptions page',
8501099
851 setUp: function() {1100 setUp: function() {