mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
node tests: Add test() wrapper for channel.
This commit is contained in:
committed by
Steve Howell
parent
5288d57c19
commit
0014bc1549
@@ -46,7 +46,14 @@ function test_with_mock_ajax(test_params) {
|
|||||||
check_ajax_options(ajax_options);
|
check_ajax_options(ajax_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("post", () => {
|
function test(label, f) {
|
||||||
|
run_test(label, (override) => {
|
||||||
|
reload_state.clear_for_testing();
|
||||||
|
f(override);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test("post", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
run_code() {
|
run_code() {
|
||||||
channel.post({});
|
channel.post({});
|
||||||
@@ -63,7 +70,7 @@ run_test("post", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("patch", () => {
|
test("patch", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
run_code() {
|
run_code() {
|
||||||
channel.patch({});
|
channel.patch({});
|
||||||
@@ -81,7 +88,7 @@ run_test("patch", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("put", () => {
|
test("put", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
run_code() {
|
run_code() {
|
||||||
channel.put({});
|
channel.put({});
|
||||||
@@ -98,7 +105,7 @@ run_test("put", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("delete", () => {
|
test("delete", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
run_code() {
|
run_code() {
|
||||||
channel.del({});
|
channel.del({});
|
||||||
@@ -115,7 +122,7 @@ run_test("delete", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("get", () => {
|
test("get", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
run_code() {
|
run_code() {
|
||||||
channel.get({});
|
channel.get({});
|
||||||
@@ -132,7 +139,7 @@ run_test("get", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("normal_post", () => {
|
test("normal_post", () => {
|
||||||
const data = {
|
const data = {
|
||||||
s: "some_string",
|
s: "some_string",
|
||||||
num: 7,
|
num: 7,
|
||||||
@@ -177,7 +184,7 @@ run_test("normal_post", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("patch_with_form_data", () => {
|
test("patch_with_form_data", () => {
|
||||||
let appended;
|
let appended;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
@@ -208,7 +215,7 @@ run_test("patch_with_form_data", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("reload_on_403_error", () => {
|
test("reload_on_403_error", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
xhr: {
|
xhr: {
|
||||||
status: 403,
|
status: 403,
|
||||||
@@ -231,7 +238,7 @@ run_test("reload_on_403_error", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("unexpected_403_response", () => {
|
test("unexpected_403_response", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
xhr: {
|
xhr: {
|
||||||
status: 403,
|
status: 403,
|
||||||
@@ -249,7 +256,7 @@ run_test("unexpected_403_response", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("retry", () => {
|
test("retry", () => {
|
||||||
test_with_mock_ajax({
|
test_with_mock_ajax({
|
||||||
run_code() {
|
run_code() {
|
||||||
channel.post({
|
channel.post({
|
||||||
@@ -273,7 +280,7 @@ run_test("retry", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("too_many_pending", () => {
|
test("too_many_pending", () => {
|
||||||
channel.clear_for_tests();
|
channel.clear_for_tests();
|
||||||
$.ajax = () => {
|
$.ajax = () => {
|
||||||
const xhr = "stub";
|
const xhr = "stub";
|
||||||
@@ -291,7 +298,7 @@ run_test("too_many_pending", () => {
|
|||||||
channel.clear_for_tests();
|
channel.clear_for_tests();
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("xhr_error_message", () => {
|
test("xhr_error_message", () => {
|
||||||
let xhr = {
|
let xhr = {
|
||||||
status: "200",
|
status: "200",
|
||||||
responseText: "does not matter",
|
responseText: "does not matter",
|
||||||
@@ -307,7 +314,7 @@ run_test("xhr_error_message", () => {
|
|||||||
assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found");
|
assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("while_reloading", () => {
|
test("while_reloading", () => {
|
||||||
reload_state.set_state_to_in_progress();
|
reload_state.set_state_to_in_progress();
|
||||||
|
|
||||||
assert.equal(channel.get({ignore_reload: false}), undefined);
|
assert.equal(channel.get({ignore_reload: false}), undefined);
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ let reload_in_progress = false;
|
|||||||
let reload_pending = false;
|
let reload_pending = false;
|
||||||
export let csrf_failed_handler;
|
export let csrf_failed_handler;
|
||||||
|
|
||||||
|
export function clear_for_testing() {
|
||||||
|
reload_in_progress = false;
|
||||||
|
reload_pending = false;
|
||||||
|
csrf_failed_handler = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function is_pending() {
|
export function is_pending() {
|
||||||
return reload_pending;
|
return reload_pending;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user