This commit is contained in:
Jannis Mattheis 2021-06-17 19:31:52 +02:00
parent 819a881557
commit a2d44968e5
5 changed files with 91 additions and 88 deletions

View File

@ -23,13 +23,15 @@ export interface StoreMapping {
export type AllStores = Extract<keyof StoreMapping, string>; export type AllStores = Extract<keyof StoreMapping, string>;
export type Stores<T extends AllStores> = Pick<StoreMapping, T>; export type Stores<T extends AllStores> = Pick<StoreMapping, T>;
export const inject =
<I extends AllStores>(...stores: I[]) =>
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
export const inject = <I extends AllStores>(...stores: I[]) => <P extends {}>( <P extends {}>(
node: React.ComponentType<P> node: React.ComponentType<P>
): React.ComponentType<Pick<P, Exclude<keyof P, I>>> => ): React.ComponentType<Pick<P, Exclude<keyof P, I>>> =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
mobxInject(...stores)(node) as any; mobxInject(...stores)(node) as any;
export const InjectProvider: React.SFC<{stores: StoreMapping}> = ({children, stores}) => ( export const InjectProvider: React.FC<{stores: StoreMapping}> = ({children, stores}) => (
<Provider {...stores}>{children}</Provider> <Provider {...stores}>{children}</Provider>
); );

View File

@ -26,20 +26,17 @@ const hiddenToken = '•••••••••••••••';
const $table = selector.table('#app-table'); const $table = selector.table('#app-table');
const $dialog = selector.form('#app-dialog'); const $dialog = selector.form('#app-dialog');
const hasApp = ( const hasApp =
name: string, (name: string, description: string, row: number): (() => Promise<void>) =>
description: string, async () => {
row: number
): (() => Promise<void>) => async () => {
expect(await innerText(page, $table.cell(row, Col.Name))).toBe(name); expect(await innerText(page, $table.cell(row, Col.Name))).toBe(name);
expect(await innerText(page, $table.cell(row, Col.Token))).toBe(hiddenToken); expect(await innerText(page, $table.cell(row, Col.Token))).toBe(hiddenToken);
expect(await innerText(page, $table.cell(row, Col.Description))).toBe(description); expect(await innerText(page, $table.cell(row, Col.Description))).toBe(description);
}; };
const updateApp = ( const updateApp =
id: number, (id: number, data: {name?: string; description?: string}): (() => Promise<void>) =>
data: {name?: string; description?: string} async () => {
): (() => Promise<void>) => async () => {
await page.click($table.cell(id, Col.EditUpdate, '.edit')); await page.click($table.cell(id, Col.EditUpdate, '.edit'));
await page.waitForSelector($dialog.selector()); await page.waitForSelector($dialog.selector());
if (data.name) { if (data.name) {
@ -56,7 +53,9 @@ const updateApp = (
await waitToDisappear(page, $dialog.selector()); await waitToDisappear(page, $dialog.selector());
}; };
const createApp = (name: string, description: string): (() => Promise<void>) => async () => { const createApp =
(name: string, description: string): (() => Promise<void>) =>
async () => {
await page.click('#create-app'); await page.click('#create-app');
await page.waitForSelector($dialog.selector()); await page.waitForSelector($dialog.selector());
await page.type($dialog.input('.name'), name); await page.type($dialog.input('.name'), name);

View File

@ -21,11 +21,15 @@ enum Col {
Delete = 4, Delete = 4,
} }
const hasClient = (name: string, row: number): (() => Promise<void>) => async () => { const hasClient =
(name: string, row: number): (() => Promise<void>) =>
async () => {
expect(await innerText(page, $table.cell(row, Col.Name))).toBe(name); expect(await innerText(page, $table.cell(row, Col.Name))).toBe(name);
}; };
const updateClient = (id: number, data: {name?: string}): (() => Promise<void>) => async () => { const updateClient =
(id: number, data: {name?: string}): (() => Promise<void>) =>
async () => {
await page.click($table.cell(id, Col.Edit, '.edit')); await page.click($table.cell(id, Col.Edit, '.edit'));
await page.waitForSelector($dialog.selector()); await page.waitForSelector($dialog.selector());
if (data.name) { if (data.name) {
@ -53,7 +57,9 @@ describe('Client', () => {
expect(await count(page, $table.rows())).toBe(1); expect(await count(page, $table.rows())).toBe(1);
}); });
describe('create clients', () => { describe('create clients', () => {
const createClient = (name: string): (() => Promise<void>) => async () => { const createClient =
(name: string): (() => Promise<void>) =>
async () => {
await page.click('#create-client'); await page.click('#create-client');
await page.waitForSelector($dialog.selector()); await page.waitForSelector($dialog.selector());
await page.type($dialog.input('.name'), name); await page.type($dialog.input('.name'), name);

View File

@ -205,9 +205,9 @@ describe('Messages', () => {
it('deletes a windows message', async () => { it('deletes a windows message', async () => {
await navigate('Windows'); await navigate('Windows');
await page.evaluate(() => await page.evaluate(() =>
(document.querySelectorAll( (
'#messages .message .delete' document.querySelectorAll('#messages .message .delete')[1] as HTMLButtonElement
)[1] as HTMLButtonElement).click() ).click()
); );
await expectMessages({ await expectMessages({
all: [linux2, windows3, backup1, linux1, windows1], all: [linux2, windows3, backup1, linux1, windows1],

View File

@ -35,11 +35,9 @@ describe('User', () => {
expect(await count(page, $table.rows())).toBe(1); expect(await count(page, $table.rows())).toBe(1);
}); });
describe('create users', () => { describe('create users', () => {
const createUser = ( const createUser =
name: string, (name: string, password: string, isAdmin: boolean): (() => Promise<void>) =>
password: string, async () => {
isAdmin: boolean
): (() => Promise<void>) => async () => {
await page.click('#create-user'); await page.click('#create-user');
await page.waitForSelector($dialog.selector()); await page.waitForSelector($dialog.selector());
await page.type($dialog.input('.name'), name); await page.type($dialog.input('.name'), name);
@ -54,11 +52,9 @@ describe('User', () => {
it('jmattheis', createUser('jmattheis', 'noice', true)); it('jmattheis', createUser('jmattheis', 'noice', true));
it('dude', createUser('dude', '1', false)); it('dude', createUser('dude', '1', false));
}); });
const hasUser = ( const hasUser =
name: string, (name: string, isAdmin: boolean, row: number): (() => Promise<void>) =>
isAdmin: boolean, async () => {
row: number
): (() => Promise<void>) => async () => {
expect(await innerText(page, $table.cell(row, Col.Name))).toBe(name); expect(await innerText(page, $table.cell(row, Col.Name))).toBe(name);
expect(await innerText(page, $table.cell(row, Col.Admin))).toBe(isAdmin ? 'Yes' : 'No'); expect(await innerText(page, $table.cell(row, Col.Admin))).toBe(isAdmin ? 'Yes' : 'No');
}; };