<commit_before>/*
 * Copyright @ 2018 8x8 Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jitsi.meet.test;

import org.jitsi.meet.test.pageobjects.web.*;
import org.jitsi.meet.test.util.*;
import org.jitsi.meet.test.web.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
import org.testng.*;
import org.testng.annotations.*;

import static org.testng.Assert.*;

/**
 * Lobby room tests.
 */
public class LobbyTest
    extends WebTestBase
{
    /**
     * Javascript to check whether lobby is enabled and supported on tested environment.
     */
    public static final String IS_LOBBY_SUPPORTED_CHECK_SCRIPT =
        "return APP.conference._room.isLobbySupported()";

    @Override
    public void setupClass()
    {
        super.setupClass();

        ensureOneParticipant();
        if (!TestUtils.executeScriptAndReturnBoolean(getParticipant1().getDriver(), IS_LOBBY_SUPPORTED_CHECK_SCRIPT))
        {
            cleanupClass();
            throw new SkipException("Skip Lobby tests as it is not enabled.");
        }
    }

    /**
     * Checks if the info dialog shows the current conference URL.
     */
    @Test
    public void testEnableLobby()
    {
        ensureTwoParticipants();

        enableLobby();
    }

    /**
     * This requires at least two participants in the room.
     */
    private void enableLobby()
    {
        WebParticipant participant1 = getParticipant1();

        // we set the name so we can check it on the notifications
        participant1.setDisplayName(participant1.getName());

        SecurityDialog securityDialog1 = participant1.getSecurityDialog();
        securityDialog1.open();

        assertFalse(securityDialog1.isLobbyEnabled());

        securityDialog1.toggleLobby();
        waitForLobbyEnabled(participant1, true);

        WebParticipant participant2 = getParticipant2();
        String notificationEnabled2 = participant2.getNotifications().getLobbyEnabledText();

        assertNotNull(notificationEnabled2);
        assertTrue(notificationEnabled2.contains(participant1.getName()));

        participant2.getNotifications().closeLobbyEnabled();

        SecurityDialog securityDialog2 = participant2.getSecurityDialog();
        securityDialog2.open();

        // lobby is visible to moderators only, this depends whether deployment is all moderators or not
        if (participant2.isModerator())
        {
            waitForLobbyEnabled(participant2, true);
        }
        else
        {
            assertFalse(securityDialog2.isLobbySectionPresent());
        }

        // let's close the security dialog or we will not be able to click
        // on popups for allow/deny participants
        securityDialog1.close();
        securityDialog2.close();
    }

    /**
     * Waits for lobby to be enabled or disabled.
     *
     * @param participant the participants drive to check.
     */
    public static void waitForLobbyEnabled(WebParticipant participant, boolean enabled)
    {
        SecurityDialog securityDialog = participant.getSecurityDialog();
        securityDialog.open();

        TestUtils.waitForCondition(
            participant.getDriver(),
            5,
            (ExpectedCondition<Boolean>) d -> {
                boolean currentState = securityDialog.isLobbyEnabled();

                return enabled ? currentState : !currentState;
            });
    }

    /**
     * Expects that lobby is enabled for the room we will try to join.
     * Lobby UI is shown, enter display name and join.
     * Checks Lobby UI and also that when joining the moderator sees corresponding notifications.
     *
     * @param moderator The participant that is moderator in the meeting.
     * @param enterDisplayName whether to enter display name. We need to enter display name only the first time when
     * a participant sees the lobby screen, next time visiting the page display name will be pre-filled
     * from local storage.
     * @return the participant from the moderator's knocking participant list.
     */
    private KnockingParticipantList.Participant enterLobby(WebParticipant moderator, boolean enterDisplayName)
    {
        joinThirdParticipant();

        WebParticipant participant3 = getParticipant3();
        LobbyScreen lobbyScreen = participant3.getLobbyScreen();

        // participant 3 should be now on pre-join screen
        lobbyScreen.waitForLoading();
<commit_msg>fix: Give more time for lobby to be enabled switch to toggle.<commit_after>/*
 * Copyright @ 2018 8x8 Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jitsi.meet.test;

import org.jitsi.meet.test.pageobjects.web.*;
import org.jitsi.meet.test.util.*;
import org.jitsi.meet.test.web.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
import org.testng.*;
import org.testng.annotations.*;

import static org.testng.Assert.*;

/**
 * Lobby room tests.
 */
public class LobbyTest
    extends WebTestBase
{
    /**
     * Javascript to check whether lobby is enabled and supported on tested environment.
     */
    public static final String IS_LOBBY_SUPPORTED_CHECK_SCRIPT =
        "return APP.conference._room.isLobbySupported()";

    @Override
    public void setupClass()
    {
        super.setupClass();

        ensureOneParticipant();
        if (!TestUtils.executeScriptAndReturnBoolean(getParticipant1().getDriver(), IS_LOBBY_SUPPORTED_CHECK_SCRIPT))
        {
            cleanupClass();
            throw new SkipException("Skip Lobby tests as it is not enabled.");
        }
    }

    /**
     * Checks if the info dialog shows the current conference URL.
     */
    @Test
    public void testEnableLobby()
    {
        ensureTwoParticipants();

        enableLobby();
    }

    /**
     * This requires at least two participants in the room.
     */
    private void enableLobby()
    {
        WebParticipant participant1 = getParticipant1();

        // we set the name so we can check it on the notifications
        participant1.setDisplayName(participant1.getName());

        SecurityDialog securityDialog1 = participant1.getSecurityDialog();
        securityDialog1.open();

        assertFalse(securityDialog1.isLobbyEnabled());

        securityDialog1.toggleLobby();
        waitForLobbyEnabled(participant1, true);

        WebParticipant participant2 = getParticipant2();
        String notificationEnabled2 = participant2.getNotifications().getLobbyEnabledText();

        assertNotNull(notificationEnabled2);
        assertTrue(notificationEnabled2.contains(participant1.getName()));

        participant2.getNotifications().closeLobbyEnabled();

        SecurityDialog securityDialog2 = participant2.getSecurityDialog();
        securityDialog2.open();

        // lobby is visible to moderators only, this depends whether deployment is all moderators or not
        if (participant2.isModerator())
        {
            waitForLobbyEnabled(participant2, true);
        }
        else
        {
            assertFalse(securityDialog2.isLobbySectionPresent());
        }

        // let's close the security dialog or we will not be able to click
        // on popups for allow/deny participants
        securityDialog1.close();
        securityDialog2.close();
    }

    /**
     * Waits for lobby to be enabled or disabled.
     *
     * @param participant the participants drive to check.
     */
    public static void waitForLobbyEnabled(WebParticipant participant, boolean enabled)
    {
        SecurityDialog securityDialog = participant.getSecurityDialog();
        securityDialog.open();

        TestUtils.waitForCondition(
            participant.getDriver(),
            10,
            (ExpectedCondition<Boolean>) d -> {
                boolean currentState = securityDialog.isLobbyEnabled();

                return enabled ? currentState : !currentState;
            });
    }

    /**
     * Expects that lobby is enabled for the room we will try to join.
     * Lobby UI is shown, enter display name and join.
     * Checks Lobby UI and also that when joining the moderator sees corresponding notifications.
     *
     * @param moderator The participant that is moderator in the meeting.
     * @param enterDisplayName whether to enter display name. We need to enter display name only the first time when
     * a participant sees the lobby screen, next time visiting the page display name will be pre-filled
     * from local storage.
     * @return the participant from the moderator's knocking participant list.
     */
    private KnockingParticipantList.Participant enterLobby(WebParticipant moderator, boolean enterDisplayName)
    {
        joinThirdParticipant();

        WebParticipant participant3 = getParticipant3();
        LobbyScreen lobbyScreen = participant3.getLobbyScreen();

        // participant 3 should be now on pre-join screen
        lobbyScreen.waitForLoading();

{'fraction_non_alphanumeric': 0.08061111669514524, 'fraction_numerical': 0.008543572218313398, 'mean_word_length': 2.787590407308717, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '927993', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2462, 'n_words': 825}