<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.test.ui.appwithinminutes;

import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.xwiki.appwithinminutes.test.po.UserClassFieldEditPane;
import org.xwiki.test.ui.po.InlinePage;
import org.xwiki.test.ui.po.editor.UserPicker;
import org.xwiki.test.ui.po.editor.UserPicker.UserElement;
import org.xwiki.xclass.test.po.ClassSheetPage;

/**
 * Special class editor tests that address only the User class field type.
 * 
 * @version $Id$
 * @since 4.5
 */
public class UserClassFieldTest extends AbstractClassEditorTest
{
    @BeforeClass
    public static void setUpClass() throws Exception
    {
        // Create 2 users.
        getUtil().createUserAndLogin("tmortagne", "tmortagne", "first_name", "Thomas", "last_name", "Mortagne",
            "avatar", "tmortagne.png");
        getUtil().attachFile("XWiki", "tmortagne", "tmortagne.png",
            UserClassFieldTest.class.getResourceAsStream("/appwithinminutes/tmortagne.png"), false);
        getUtil().createUserAndLogin("Enygma2002", "Enygma2002", "first_name", "Eduard", "last_name", "Moraru",
            "avatar", "Enygma2002.png");
        getUtil().attachFile("XWiki", "Enygma2002", "Enygma2002.png",
            UserClassFieldTest.class.getResourceAsStream("/appwithinminutes/Enygma2002.png"), false);
    }

    @Test
    public void testSuggestions()
    {
        UserPicker userPicker = new UserClassFieldEditPane(editor.addField("User").getName()).getUserPicker();

        // The suggestions should be case-insensitive. Match the last name.
        List<UserElement> suggestions = userPicker.sendKeys("mOr").waitForSuggestions().getSuggestions();
        Assert.assertEquals(2, suggestions.size());
        assertUserElement(suggestions.get(0), "<NAME>", "Enygma2002");
        assertUserElement(suggestions.get(1), "<NAME>");

        // Match the first name.
        suggestions = userPicker.sendKeys(Keys.BACK_SPACE, Keys.BACK_SPACE, "As").waitForSuggestions().getSuggestions();
        Assert.assertEquals(1, suggestions.size());
        assertUserElement(suggestions.get(0), "<NAME>");

        // Match the alias.
        suggestions = userPicker.sendKeys(Keys.BACK_SPACE, "20").waitForSuggestions().getSuggestions();
        Assert.assertEquals(1, suggestions.size());
        assertUserElement(suggestions.get(0), "<NAME>", "Enygma2002");

        // The guest user shouldn't be suggested.
        suggestions = userPicker.clear().sendKeys("guest").waitForSuggestions().getSuggestions();
        Assert.assertEquals(1, suggestions.size());
        Assert.assertEquals("User not found", suggestions.get(0).getText());
<commit_msg>Fix test<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.test.ui.appwithinminutes;

import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.xwiki.appwithinminutes.test.po.UserClassFieldEditPane;
import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.InlinePage;
import org.xwiki.test.ui.po.editor.UserPicker;
import org.xwiki.test.ui.po.editor.UserPicker.UserElement;
import org.xwiki.xclass.test.po.ClassSheetPage;

/**
 * Special class editor tests that address only the User class field type.
 * 
 * @version $Id$
 * @since 4.5
 */
public class UserClassFieldTest extends AbstractClassEditorTest
{
    @BeforeClass
    public static void setUpClass() throws Exception
    {
        // Create 2 users.
        getUtil().createUserAndLogin("tmortagne", "tmortagne", "first_name", "Thomas", "last_name", "Mortagne",
            "avatar", "tmortagne.png");
        getUtil().attachFile("XWiki", "tmortagne", "tmortagne.png",
            UserClassFieldTest.class.getResourceAsStream("/appwithinminutes/tmortagne.png"), false,
            TestUtils.ADMIN_CREDENTIALS);
        getUtil().createUserAndLogin("Enygma2002", "Enygma2002", "first_name", "Eduard", "last_name", "Moraru",
            "avatar", "Enygma2002.png");
        getUtil().attachFile("XWiki", "Enygma2002", "Enygma2002.png",
            UserClassFieldTest.class.getResourceAsStream("/appwithinminutes/Enygma2002.png"), false,
            TestUtils.ADMIN_CREDENTIALS);
    }

    @Test
    public void testSuggestions()
    {
        UserPicker userPicker = new UserClassFieldEditPane(editor.addField("User").getName()).getUserPicker();

        // The suggestions should be case-insensitive. Match the last name.
        List<UserElement> suggestions = userPicker.sendKeys("mOr").waitForSuggestions().getSuggestions();
        Assert.assertEquals(2, suggestions.size());
        assertUserElement(suggestions.get(0), "<NAME>", "Enygma2002");
        assertUserElement(suggestions.get(1), "<NAME>");

        // Match the first name.
        suggestions = userPicker.sendKeys(Keys.BACK_SPACE, Keys.BACK_SPACE, "As").waitForSuggestions().getSuggestions();
        Assert.assertEquals(1, suggestions.size());
        assertUserElement(suggestions.get(0), "<NAME>");

        // Match the alias.
        suggestions = userPicker.sendKeys(Keys.BACK_SPACE, "20").waitForSuggestions().getSuggestions();
        Assert.assertEquals(1, suggestions.size());
        assertUserElement(suggestions.get(0), "<NAME>", "Enygma2002");

        // The guest user shouldn't be suggested.
        suggestions = userPicker.clear().sendKeys("guest").waitForSuggestions().getSuggestions();
        Assert.assertEquals(1, suggestions.size());
        Assert.assertEquals("User not found", suggestions.get(0).getText());

{'fraction_non_alphanumeric': 0.1195840554592721, 'fraction_numerical': 0.01573123583522197, 'mean_word_length': 3.8841145833333335, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1572215', 'n_tokens_mistral': 2236, 'n_tokens_neox': 2107, 'n_words': 571}