Skip to content

Commit

Permalink
test: fix tests to work with dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Oct 4, 2021
1 parent 542cdb7 commit 1823b80
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cypress/fixtures/apps/apps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// eslint-disable-next-line import/prefer-default-export
export const APPS_LIST = [
{
name: "test",
url: "http://localhost.com:3333",
extra:{
image: "https://pbs.twimg.com/profile_images/1300707321262346240/IsQAyu7q_400x400.jpg"
}
}
];
4 changes: 4 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MODE_LIST_BUTTON_ID,
} from '../../src/config/selectors';
import {
mockGetAppListRoute,
mockCopyItem,
mockCopyItems,
mockDeleteItem,
Expand Down Expand Up @@ -65,6 +66,7 @@ import './commands/item';
import './commands/navigation';
import { CURRENT_USER, MEMBERS } from '../fixtures/members';
import { SAMPLE_FLAGS } from '../fixtures/flags';
import { APPS_LIST } from '../fixtures/apps/apps';

Cypress.Commands.add(
'setUpApi',
Expand Down Expand Up @@ -106,6 +108,8 @@ Cypress.Commands.add(
const cachedMembers = JSON.parse(JSON.stringify(members));
const allItems = [...cachedItems, ...recycledItems];

mockGetAppListRoute(APPS_LIST);

mockGetOwnItems(cachedItems);

mockGetSharedItems({ items: cachedItems, member: currentMember });
Expand Down
5 changes: 2 additions & 3 deletions cypress/support/commands/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ Cypress.Commands.add(
({ name = '', extra = {} }, { confirm = true } = {}) => {
cy.fillBaseItemModal({ name }, { confirm: false });

cy.get(`#${ITEM_FORM_APP_URL_ID}`).type(
`{selectall}${getAppExtra(extra)?.url}`,
);
cy.get(`#${ITEM_FORM_APP_URL_ID}`).click();
cy.get(`[data-value="${getAppExtra(extra)?.url}"]`).click();

if (confirm) {
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click();
Expand Down
14 changes: 14 additions & 0 deletions cypress/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from '../fixtures/apps';

const {
buildAppListRoute,
buildCopyItemRoute,
buildDeleteItemRoute,
buildEditItemRoute,
Expand Down Expand Up @@ -96,6 +97,19 @@ export const redirectionReply = {
body: null,
};

export const mockGetAppListRoute = (apps) => {
cy.intercept(
{
method: DEFAULT_GET.method,
url: `${API_HOST}/${buildAppListRoute}`,
},
(req) => {
req.reply(apps);
},
).as('useApps');
};


export const mockGetCurrentMember = (
currentMember = MEMBERS.ANNA,
shouldThrowError = false,
Expand Down
2 changes: 2 additions & 0 deletions src/components/item/form/AppForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { InputLabel, Select, MenuItem, FormControl, makeStyles } from '@material
import BaseItemForm from './BaseItemForm';
import { buildAppExtra, getAppExtra } from '../../../utils/itemExtra';
import { hooks } from '../../../config/queryClient';
import { ITEM_FORM_APP_URL_ID } from '../../../config/selectors';

const useStyles = makeStyles((theme) => ({
img: {
Expand Down Expand Up @@ -47,6 +48,7 @@ const AppForm = ({ onChange, item }) => {
<FormControl fullWidth>
<InputLabel>{t('App url')}</InputLabel>
<Select
id={ITEM_FORM_APP_URL_ID}
margin="dense"
label={t('App url')}
value={url}
Expand Down

0 comments on commit 1823b80

Please sign in to comment.