Skip to content
Snippets Groups Projects
Commit 23e92283 authored by Lewis Liu's avatar Lewis Liu
Browse files

Added admin user management tests

parent 1cbaf5c8
Branches
Tags
No related merge requests found
......@@ -88,12 +88,12 @@ export default class EditUserForm extends Component {
<div className="px4 pb2">
<FormField fieldName="first_name" formError={formError}>
<FormLabel title="First name" fieldName="first_name" formError={formError} offset={false}></FormLabel>
<input ref="firstName" className="Form-input full" name="name" defaultValue={(user) ? user.first_name : null} placeholder="Johnny" onChange={this.onChange.bind(this)} />
<input ref="firstName" className="Form-input full" name="firstName" defaultValue={(user) ? user.first_name : null} placeholder="Johnny" onChange={this.onChange.bind(this)} />
</FormField>
<FormField fieldName="last_name" formError={formError}>
<FormLabel title="Last name" fieldName="last_name" formError={formError} offset={false}></FormLabel>
<input ref="lastName" className="Form-input full" name="name" defaultValue={(user) ? user.last_name : null} placeholder="Appleseed" required onChange={this.onChange.bind(this)} />
<input ref="lastName" className="Form-input full" name="lastName" defaultValue={(user) ? user.last_name : null} placeholder="Appleseed" required onChange={this.onChange.bind(this)} />
</FormField>
<FormField fieldName="email" formError={formError}>
......
import path from "path";
import { isReady } from "../support/start-server";
import { setup, cleanup } from "../support/setup";
import { By, until } from "selenium-webdriver";
import {
waitForElement,
waitForElementRemoved,
findElement,
waitForAndClickElement,
waitForUrl,
screenshot,
loginMetabase
} from "../support/utils";
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
describe("admin/people", () => {
let server, sauceConnect, driver;
beforeAll(async () => {
({ server, sauceConnect, driver } = await setup());
});
it ("should start", async () => {
expect(await isReady(server.host)).toEqual(true);
});
describe("user management", () => {
it("should allow admin to create new users", async () => {
await driver.get(`${server.host}/`);
await loginMetabase(driver, "bob@metabase.com", "12341234");
await waitForUrl(driver, `${server.host}/`);
await driver.get(`${server.host}/admin/people`);
// click add person button
await waitForAndClickElement(driver, ".Button.Button--primary");
// fill in user info form
const addButton = findElement(driver, ".Modal .Button[disabled]");
await findElement(driver, "[name=firstName]").sendKeys('1234');
await findElement(driver, "[name=lastName]").sendKeys('1234');
await findElement(driver, "[name=email]").sendKeys('1234@1234.com');
expect(await addButton.isEnabled()).toBe(true);
await addButton.click();
// get password
await waitForAndClickElement(driver, ".Modal a.link");
const passwordInput = await waitForElement(driver, ".Modal input");
const password = await passwordInput.getAttribute("value");
await waitForAndClickElement(driver, ".Modal .Button.Button--primary");
// change user role
await waitForAndClickElement(driver, ".ContentTable tr:first-child .AdminSelectBorderless.text-brand");
await waitForAndClickElement(driver, ".UserRolePopover li:last-child>a");
expect(await driver.isElementPresent(By.css("tr:first-child .AdminSelectBorderless.text-purple"))).toEqual(true);
// edit user details
await waitForAndClickElement(driver, ".ContentTable tr:first-child td:last-child a");
await waitForAndClickElement(driver, ".UserActionsSelect li:first-child");
const saveButton = findElement(driver, ".Modal .Button[disabled]");
await findElement(driver, "[name=firstName]").clear();
await findElement(driver, "[name=firstName]").sendKeys('12345');
await findElement(driver, "[name=lastName]").clear();
await findElement(driver, "[name=lastName]").sendKeys('123456');
await findElement(driver, "[name=email]").clear();
await findElement(driver, "[name=email]").sendKeys('12345@1234.com');
expect(await saveButton.isEnabled()).toBe(true);
await saveButton.click();
expect(await findElement(driver, ".ContentTable tr:first-child td:first-child span:last-child").getText()).toEqual("12345 123456");
expect(await findElement(driver, ".ContentTable tr:first-child td:nth-child(3)").getText()).toEqual("12345@1234.com");
// reset user password
await waitForAndClickElement(driver, ".ContentTable tr:first-child td:last-child a");
await waitForAndClickElement(driver, ".UserActionsSelect li:nth-child(2)");
await waitForAndClickElement(driver, ".Modal .Button.Button--warning");
await waitForAndClickElement(driver, ".Modal a.link");
const newPasswordInput = await waitForElement(driver, ".Modal input");
const newPassword = await newPasswordInput.getAttribute("value");
expect(newPassword).not.toEqual(password);
//TODO: verify new user can sign in?
});
});
afterAll(async () => {
await cleanup({ server, sauceConnect, driver });
});
});
......@@ -2,19 +2,16 @@ import { isReady } from "../support/start-server";
import { setup, cleanup } from "../support/setup";
import { By, until } from "selenium-webdriver";
import { waitForUrl, screenshot } from "../support/utils";
import {
waitForUrl,
screenshot,
loginMetabase
} from "../support/utils";
import { delay } from '../../../src/metabase/lib/promise';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
async function loginMetabase(driver, username, password) {
await driver.wait(until.elementLocated(By.css("[name=email]")));
await driver.findElement(By.css("[name=email]")).sendKeys(username);
await driver.findElement(By.css("[name=password]")).sendKeys(password);
await driver.manage().timeouts().implicitlyWait(1000);
await driver.findElement(By.css(".Button.Button--primary")).click();
}
describe("auth/login", () => {
let server, sauceConnect, driver;
......
......@@ -6,13 +6,14 @@ import { By, until } from "selenium-webdriver";
import {
waitForElement,
waitForElementRemoved,
findElement,
waitForAndClickElement,
waitForUrl,
screenshot
} from "../support/utils";
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
describe("setup/signup", () => {
let server, sauceConnect, driver;
......@@ -37,7 +38,6 @@ describe("setup/signup", () => {
});
it("should allow you to sign up and add db", async () => {
await driver.manage().window().setSize(1024, 768);
await driver.get(`${server.host}/`);
await waitForUrl(driver, `${server.host}/setup`);
await waitForAndClickElement(driver, ".Button.Button--primary");
......@@ -95,7 +95,7 @@ describe("setup/signup", () => {
await waitForElement(driver, "img[src='/app/img/qb_tutorial/table.png']");
// a .Modal-backdrop element blocks clicks for a while during transition?
await driver.wait(async () => (await driver.findElements(By.css('.Modal-backdrop'))).length === 0);
await waitForElementRemoved(driver, '.Modal-backdrop');
await waitForAndClickElement(driver, ".GuiBuilder-data a");
// select sample dataset db
......
......@@ -9,6 +9,9 @@ export const findElement = (driver, selector) =>
export const waitForElement = async (driver, selector, timeout = 5000) =>
await driver.wait(until.elementLocated(By.css(selector)), timeout);
export const waitForElementRemoved = async (driver, selector, timeout = 5000) =>
await driver.wait(until.stalenessOf(findElement(driver, selector)), timeout);
export const clickElement = async (driver, selector) =>
await findElement(driver, selector).click();
......@@ -39,3 +42,11 @@ export const screenshot = async (driver, filename) => {
const image = await driver.takeScreenshot();
await fs.writeFile(filename, image, 'base64');
};
export const loginMetabase = async (driver, username, password) => {
await driver.wait(until.elementLocated(By.css("[name=email]")));
await driver.findElement(By.css("[name=email]")).sendKeys(username);
await driver.findElement(By.css("[name=password]")).sendKeys(password);
await driver.manage().timeouts().implicitlyWait(1000);
await driver.findElement(By.css(".Button.Button--primary")).click();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment