Skip to content

Commit

Permalink
[PUI] Add quick login via url (#7022)
Browse files Browse the repository at this point in the history
* add login with URL params

* use login function for faster tests

* reduce timeout possiblities in job

* remove unused imports

* remove debug
  • Loading branch information
matmair committed Apr 17, 2024
1 parent 9435a4c commit 500f63d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 94 deletions.
15 changes: 13 additions & 2 deletions src/frontend/src/pages/Auth/Login.tsx
Expand Up @@ -2,7 +2,7 @@ import { Trans, t } from '@lingui/macro';
import { Center, Container, Paper, Text } from '@mantine/core';
import { useDisclosure, useToggle } from '@mantine/hooks';
import { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';

import { setApiDefaults } from '../../App';
import { AuthFormOptions } from '../../components/forms/AuthFormOptions';
Expand All @@ -13,7 +13,7 @@ import {
} from '../../components/forms/AuthenticationForm';
import { InstanceOptions } from '../../components/forms/InstanceOptions';
import { defaultHostKey } from '../../defaults/defaultHostList';
import { checkLoginState } from '../../functions/auth';
import { checkLoginState, doBasicLogin } from '../../functions/auth';
import { useServerApiState } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';

Expand All @@ -33,6 +33,7 @@ export default function Login() {
const [loginMode, setMode] = useDisclosure(true);
const navigate = useNavigate();
const location = useLocation();
const [searchParams] = useSearchParams();

// Data manipulation functions
function ChangeHost(newHost: string): void {
Expand All @@ -48,6 +49,16 @@ export default function Login() {
}

checkLoginState(navigate, location?.state?.redirectFrom, true);

// check if we got login params (login and password)
if (searchParams.has('login') && searchParams.has('password')) {
doBasicLogin(
searchParams.get('login') ?? '',
searchParams.get('password') ?? ''
).then(() => {
navigate(location?.state?.redirectFrom ?? '/home');
});
}
}, []);

// Fetch server data on mount if no server data is present
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/tests/defaults.ts
Expand Up @@ -4,3 +4,8 @@ export const user = {
username: 'allaccess',
password: 'nolimits'
};

export const adminuser = {
username: 'admin',
password: 'inventree'
};
27 changes: 10 additions & 17 deletions src/frontend/tests/pui_command.spec.ts
Expand Up @@ -2,13 +2,10 @@ import { expect, systemKey, test } from './baseFixtures.js';
import { user } from './defaults.js';

test('PUI - Quick Command', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.goto('./platform/');

await expect(page).toHaveTitle('InvenTree');
Expand Down Expand Up @@ -48,18 +45,14 @@ test('PUI - Quick Command', async ({ page }) => {
});

test('PUI - Quick Command - no keys', async ({ page }) => {
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');

await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform');
// wait for the page to load - 0.5s
await page.waitForTimeout(500);
// wait for the page to load
await page.waitForTimeout(200);

// Open Spotlight with Button
await page.getByRole('button', { name: 'Open spotlight' }).click();
Expand Down
89 changes: 34 additions & 55 deletions src/frontend/tests/pui_general.spec.ts
@@ -1,14 +1,11 @@
import { expect, test } from './baseFixtures.js';
import { user } from './defaults.js';
import { test } from './baseFixtures.js';
import { adminuser, user } from './defaults.js';

test('PUI - Parts', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.goto('./platform/home');

await page.getByRole('tab', { name: 'Parts' }).click();
Expand Down Expand Up @@ -39,13 +36,10 @@ test('PUI - Parts', async ({ page }) => {
});

test('PUI - Parts - Manufacturer Parts', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');

await page.goto('./platform/part/84/manufacturers');
await page.getByRole('tab', { name: 'Manufacturers' }).click();
Expand All @@ -57,13 +51,10 @@ test('PUI - Parts - Manufacturer Parts', async ({ page }) => {
});

test('PUI - Parts - Supplier Parts', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');

await page.goto('./platform/part/15/suppliers');
await page.getByRole('tab', { name: 'Suppliers' }).click();
Expand All @@ -75,13 +66,10 @@ test('PUI - Parts - Supplier Parts', async ({ page }) => {
});

test('PUI - Sales', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');

await page.goto('./platform/sales/');
await page.waitForURL('**/platform/sales/**');
Expand Down Expand Up @@ -131,13 +119,11 @@ test('PUI - Sales', async ({ page }) => {
});

test('PUI - Scanning', async ({ page }) => {
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');

await page.getByLabel('Homenav').click();
await page.getByRole('button', { name: 'System Information' }).click();
Expand All @@ -158,13 +144,11 @@ test('PUI - Scanning', async ({ page }) => {
});

test('PUI - Admin', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.goto(
`./platform/login/?login=${adminuser.username}&password=${adminuser.password}`
);
await page.waitForURL('**/platform/*');
await page.getByLabel('username').fill('admin');
await page.getByLabel('password').fill('inventree');
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto('./platform/');

// User settings
await page.getByRole('button', { name: 'admin' }).click();
Expand Down Expand Up @@ -213,13 +197,11 @@ test('PUI - Admin', async ({ page }) => {
});

test('PUI - Language / Color', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto('./platform/');

await page.getByRole('button', { name: 'Ally Access' }).click();
await page.getByRole('menuitem', { name: 'Logout' }).click();
Expand Down Expand Up @@ -253,13 +235,10 @@ test('PUI - Language / Color', async ({ page }) => {
});

test('PUI - Company', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');

await page.goto('./platform/company/1/details');
await page
Expand Down
33 changes: 13 additions & 20 deletions src/frontend/tests/pui_stock.spec.ts
@@ -1,14 +1,11 @@
import { expect, test } from './baseFixtures.js';
import { test } from './baseFixtures.js';
import { user } from './defaults.js';

test('PUI - Stock', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');

await page.goto('./platform/stock');
await page.waitForURL('**/platform/stock/location/index/details');
Expand All @@ -24,13 +21,11 @@ test('PUI - Stock', async ({ page }) => {
});

test('PUI - Build', async ({ page }) => {
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');

await page.getByRole('tab', { name: 'Build' }).click();
await page.getByText('Widget Assembly Variant').click();
Expand All @@ -44,13 +39,11 @@ test('PUI - Build', async ({ page }) => {
});

test('PUI - Purchasing', async ({ page }) => {
await page.goto(
`./platform/login/?login=${user.username}&password=${user.password}`
);
await page.waitForURL('**/platform/*');
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree');
await page.waitForURL('**/platform/');
await page.getByLabel('username').fill(user.username);
await page.getByLabel('password').fill(user.password);
await page.getByRole('button', { name: 'Log in' }).click();
await page.waitForURL('**/platform');

await page.getByRole('tab', { name: 'Purchasing' }).click();
await page.getByRole('cell', { name: 'PO0012' }).click();
Expand Down

0 comments on commit 500f63d

Please sign in to comment.