-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.ts
60 lines (56 loc) · 1.87 KB
/
commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/// <reference types="../../src/interfaces/window" />
import { PermissionLevel } from '@graasp/sdk';
import '@testing-library/cypress/add-commands';
import { CURRENT_MEMBER, MEMBERS, MOCK_SERVER_ITEM } from '../../src/data/db';
import { MOCK_SERVER_API_HOST } from '../fixtures/appData';
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Cypress.Commands.add(
'setUpApi',
({ currentMember = CURRENT_MEMBER, database = {}, appContext } = {}) => {
// mock api and database
Cypress.on('window:before:load', (win) => {
// eslint-disable-next-line no-param-reassign
win.database = {
appData: [],
appSettings: [],
appActions: [],
items: [MOCK_SERVER_ITEM],
members: Object.values(MEMBERS),
...database,
};
// eslint-disable-next-line no-param-reassign
win.appContext = {
memberId: currentMember.id,
itemId: MOCK_SERVER_ITEM.id,
apiHost: Cypress.env('VITE_API_HOST') || MOCK_SERVER_API_HOST,
context: 'standalone',
permission: PermissionLevel.Read,
...appContext,
};
});
},
);