Skip to content

Commit

Permalink
test: fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Krysiak authored and Wojciech Krysiak committed Sep 20, 2020
1 parent 3161436 commit 59eeb1b
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ src/frontend/assets/scripts
.adminbro
example-app/cypress/videos
example-app/cypress/screenshots
.env
4 changes: 4 additions & 0 deletions example-app/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POSTGRES_USER="adminbro"
POSTGRES_PASSWORD="adminbro"
POSTGRES_DATABASE="adminbro-e2e"
POSTGRES_HOST="localhost"
12 changes: 0 additions & 12 deletions example-app/cypress/integration/sign-in/layout.spec.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

module.exports = {
// up: () => Promise.resolve(true),
up: queryInterface => queryInterface.addConstraint('ExternalEmployees', ['email'], {
up: queryInterface => queryInterface.addConstraint('ExternalEmployees', {
fields: ['email'],
type: 'unique',
name: 'external_employees_email_unique_constraint',
}),

down: queryInterface => queryInterface.removeConstraint('ExternalEmployees', ['email']),
down: queryInterface => queryInterface.removeConstraint(
'ExternalEmployees', 'external_employees_email_unique_constraint',
),
}
2 changes: 1 addition & 1 deletion src/frontend/components/app/notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MessageBox } from '@admin-bro/design-system'

import { NoticeMessageInState, ReduxState } from '../../store/store'
import { dropNotice } from '../../store/actions/drop-notice'
import { setNoticeProgress } from '../../store/actions/set-Notice-progress'
import { setNoticeProgress } from '../../store/actions/set-notice-progress'

const TIME_TO_DISAPPEAR = 3

Expand Down
67 changes: 0 additions & 67 deletions src/frontend/components/app/records-table/no-records.spec.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/frontend/components/app/records-table/record-in-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const RecordInList: React.FC<Props> = (props) => {
} else if (actionPerformed) {
actionPerformed(actionResponse)
}
}, [actionPerformed])
}, [actionPerformed, record])

return (
<TableRow onClick={(event): void => handleClick(event)} data-id={record.id}>
Expand Down Expand Up @@ -100,8 +100,8 @@ const RecordInList: React.FC<Props> = (props) => {
<TableCell key="options">
{recordActions.length ? (
<DropDown stick="right">
<DropDownTrigger data-testid="actions-dropdown">
<Button variant="text" size="icon">
<DropDownTrigger>
<Button variant="text" size="icon" data-testid="actions-dropdown">
<Icon icon="OverflowMenuHorizontal" color="grey100" />
</Button>
</DropDownTrigger>
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/components/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import {
FormGroup,
Button,
Text,
H3,
MessageBox,
SoftwareBrothers,
} from '@admin-bro/design-system'
import { useTranslation } from '../../hooks'
import { ReduxState } from '../../store/store'
import SidebarBranding from '../app/sidebar/sidebar-branding'

const GlobalStyle = createGlobalStyle`
html, body, #app {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/property-type/array/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ItemRenderer: React.FC<Props & ItemRendererProps> = (props) => {
onClick={(event): false => onDelete(event)}
variant="danger"
>
<Icon icon="Delete" />
<Icon icon="TrashCan" />
</Button>
</Box>
</Box>
Expand Down
27 changes: 17 additions & 10 deletions src/frontend/hooks/use-action.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React, { useCallback } from 'react'
/* eslint-disable no-restricted-globals */
/* eslint-disable no-undef */
/* eslint-disable no-alert */
import { AxiosResponse } from 'axios'
import { useLocation, useHistory } from 'react-router'
import { useMemo } from 'react'

import ViewHelpers, {
BulkActionParams,
ResourceActionParams,
RecordActionParams,
} from '../../backend/utils/view-helpers'


import { appendForceRefresh } from '../../../lib/frontend/components/actions/utils/append-force-refresh'
import ApiClient from '../../../lib/frontend/utils/api-client'
import { appendForceRefresh } from '../../frontend/components/actions/utils/append-force-refresh'
import ApiClient from '../../frontend/utils/api-client'

import { ActionResponse } from '../../backend/actions/action.interface'

Expand Down Expand Up @@ -67,7 +68,7 @@ export function useAction<K extends ActionResponse>(
resourceId, recordId, recordIds,
} = params as MergedActionParams

const href: string = useMemo(() => {
const setHref = useCallback(() => {
if (isRecordAction(params, action)) {
return h.recordActionUrl({ ...params, actionName, search: location.search })
}
Expand All @@ -78,7 +79,9 @@ export function useAction<K extends ActionResponse>(
return h.resourceActionUrl({ resourceId, actionName, search: location.search })
}
throw new Error('"actionType" should be either record, resource or bulk')
}, [resourceId, recordId, recordIds, actionName, location.search])
}, [resourceId, location, action])

const href = setHref()

const callApi = (): Promise<AxiosResponse<K>> => {
const api = new ApiClient()
Expand All @@ -89,22 +92,23 @@ export function useAction<K extends ActionResponse>(
if (!recordId) {
throw new Error('You have to specify "recordId" for record action')
}
// TODO: change type from any - in general handle types for Action
promise = api.recordAction({
resourceId, actionName: action.name, recordId,
})
}) as any
break
case 'resource':
promise = api.resourceAction({
resourceId, actionName: action.name,
})
}) as any
break
case 'bulk':
if (!recordIds) {
throw new Error('You have to specify "recordIds" for bulk action')
}
promise = api.bulkAction({
resourceId, actionName: action.name, recordIds,
})
}) as any
break
default:
throw new Error('"actionType" should be either record, resource or bulk')
Expand All @@ -116,7 +120,8 @@ export function useAction<K extends ActionResponse>(
addNotice(data.notice)
}
if (data.redirectUrl && location.pathname !== data.redirectUrl) {
history.push(appendForceRefresh(data.redirectUrl))
const appended = appendForceRefresh(data.redirectUrl)
history.push(appended)
}
if (onActionCall) {
onActionCall(data)
Expand All @@ -129,13 +134,15 @@ export function useAction<K extends ActionResponse>(

const handleClick = (event: React.MouseEvent<HTMLElement>): void => {
event.preventDefault()
event.stopPropagation()
if (action.guard && !confirm(action.guard)) {
return
}
if (typeof action.component !== 'undefined' && action.component === false) {
callApi()
} else {
history.push(href)
}
history.push(href)
}

return {
Expand Down
16 changes: 11 additions & 5 deletions src/frontend/utils/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import axios, { AxiosResponse, AxiosInstance, AxiosRequestConfig } from 'axios'
import { ResourceActionParams, BulkActionParams, RecordActionParams } from '../../../lib/backend/utils/view-helpers'
import { ActionParams } from '../../backend/utils/view-helpers'
import {
ResourceActionParams,
BulkActionParams,
RecordActionParams,
ActionParams,
} from '../../backend/utils/view-helpers'

/* eslint-disable no-alert */
import RecordJSON from '../../backend/decorators/record-json.interface'
import { RecordActionResponse, ActionResponse, BulkActionResponse } from '../../backend/actions/action.interface'
Expand Down Expand Up @@ -55,8 +60,9 @@ export type ActionAPIParams = AxiosRequestConfig & ActionParams
* @memberof ApiClient
* @property {any} ... any property supported by {@link AxiosRequestConfig}
*/
export type ResourceActionAPIParams = AxiosRequestConfig & ResourceActionParams

export type ResourceActionAPIParams = AxiosRequestConfig & ResourceActionParams & {
query?: string;
}
/**
* Extends {@link ActionAPIParams}
*
Expand Down Expand Up @@ -196,7 +202,7 @@ class ApiClient {
const { resourceId, recordIds, actionName, data, ...axiosParams } = options

const params = new URLSearchParams()
params.set('recordIds', recordIds.join(','))
params.set('recordIds', (recordIds || []).join(','))

const response = await this.client.request({
url: `/api/resources/${resourceId}/bulk/${actionName}`,
Expand Down

0 comments on commit 59eeb1b

Please sign in to comment.