puppeteer_tests: Use loop when testing changing policies for streams.

Previously, this logic copied code to test each individual case.
This commit is contained in:
Ganesh Pawar 2021-06-19 20:23:48 +05:30 committed by Tim Abbott
parent b3ef57657c
commit 66bd282d12
1 changed files with 25 additions and 46 deletions

View File

@ -99,46 +99,31 @@ async function submit_stream_permissions_change(page: Page): Promise<void> {
await test_permissions_change_save_worked(page); await test_permissions_change_save_worked(page);
} }
async function test_set_create_streams_to_admins_only(page: Page): Promise<void> { async function test_changing_create_streams_and_invite_to_stream_policies(
console.log("Test setting create streams policy to 'admins only'."); page: Page,
await page.waitForSelector("#id_realm_create_stream_policy", {visible: true}); ): Promise<void> {
await page.evaluate(() => $("#id_realm_create_stream_policy").val(2).trigger("change")); const policies = {
await submit_stream_permissions_change(page); "create stream": "#id_realm_create_stream_policy",
} "invite to stream": "#id_realm_invite_to_stream_policy",
};
const policy_values = {
"admins only": 2,
"members and admins": 1,
"full members": 3,
};
async function test_set_create_streams_to_members_and_admins(page: Page): Promise<void> { for (const [policy, selector] of Object.entries(policies)) {
console.log("Test setting create streams policy to 'members and admins'."); for (const [policy_value_name, policy_value] of Object.entries(policy_values)) {
await page.waitForSelector("#id_realm_create_stream_policy", {visible: true}); console.log(`Test setting ${policy} policy to '${policy_value_name}'.`);
await page.evaluate(() => $("#id_realm_create_stream_policy").val(1).trigger("change")); await page.waitForSelector(selector, {visible: true});
await submit_stream_permissions_change(page); await page.evaluate(
} (selector, policy_value) => $(selector).val(policy_value).trigger("change"),
selector,
async function test_set_create_streams_policy_to_full_members(page: Page): Promise<void> { policy_value,
console.log("Test setting create streams policy to 'full members'."); );
await page.waitForSelector("#id_realm_create_stream_policy", {visible: true}); await submit_stream_permissions_change(page);
await page.evaluate(() => $("#id_realm_create_stream_policy").val(3).trigger("change")); }
await submit_stream_permissions_change(page); }
}
async function test_set_invite_to_streams_policy_to_admins_only(page: Page): Promise<void> {
console.log("Test setting invite to streams policy to 'admins only'.");
await page.waitForSelector("#id_realm_invite_to_stream_policy", {visible: true});
await page.evaluate(() => $("#id_realm_invite_to_stream_policy").val(2).trigger("change"));
await submit_stream_permissions_change(page);
}
async function test_set_invite_to_streams_policy_to_members_and_admins(page: Page): Promise<void> {
console.log("Test setting invite to streams policy to 'members and admins'.");
await page.waitForSelector("#id_realm_invite_to_stream_policy", {visible: true});
await page.evaluate(() => $("#id_realm_invite_to_stream_policy").val(1).trigger("change"));
await submit_stream_permissions_change(page);
}
async function test_set_invite_to_streams_policy_to_full_members(page: Page): Promise<void> {
console.log("Test setting invite to streams policy to 'full members'.");
await page.waitForSelector("#id_realm_invite_to_stream_policy", {visible: true});
await page.evaluate(() => $("#id_realm_invite_to_stream_policy").val(3).trigger("change"));
await submit_stream_permissions_change(page);
} }
async function test_save_joining_organization_change_worked(page: Page): Promise<void> { async function test_save_joining_organization_change_worked(page: Page): Promise<void> {
@ -187,13 +172,7 @@ async function test_set_new_user_threshold_to_N_days(page: Page): Promise<void>
async function test_organization_permissions(page: Page): Promise<void> { async function test_organization_permissions(page: Page): Promise<void> {
await page.click("li[data-section='organization-permissions']"); await page.click("li[data-section='organization-permissions']");
await test_set_create_streams_to_admins_only(page); await test_changing_create_streams_and_invite_to_stream_policies(page);
await test_set_create_streams_to_members_and_admins(page);
await test_set_create_streams_policy_to_full_members(page);
await test_set_invite_to_streams_policy_to_admins_only(page);
await test_set_invite_to_streams_policy_to_members_and_admins(page);
await test_set_invite_to_streams_policy_to_full_members(page);
await test_set_new_user_threshold_to_three_days(page); await test_set_new_user_threshold_to_three_days(page);
await test_set_new_user_threshold_to_N_days(page); await test_set_new_user_threshold_to_N_days(page);