|
@@ -1,4 +1,41 @@
|
|
|
-export const NETWORK_URL = 'http://*';
|
|
|
+import {CyHttpMessages, RouteHandler} from 'cypress/types/net-stubbing';
|
|
|
+
|
|
|
+function parseUrl(url: string) {
|
|
|
+ return `http://*${
|
|
|
+ url.indexOf('/') === 0 ? '' : '/'
|
|
|
+ }${url}${
|
|
|
+ url.includes('*') ? '' : '*'
|
|
|
+ }`;
|
|
|
+}
|
|
|
+
|
|
|
+export function normalIntercept(
|
|
|
+ url: string,
|
|
|
+ fixture: string,
|
|
|
+ options?: Omit<RouteHandler, 'fixture'>,
|
|
|
+) {
|
|
|
+ return cy.intercept(
|
|
|
+ parseUrl(url),
|
|
|
+ {fixture, ...(options ?? {})},
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+export function successIntercept(url: string) {
|
|
|
+ return normalIntercept(
|
|
|
+ url,
|
|
|
+ 'success',
|
|
|
+ {delay: 100},
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+export function intercept(
|
|
|
+ url: string,
|
|
|
+ response: (e: CyHttpMessages.IncomingHttpRequest) => void,
|
|
|
+) {
|
|
|
+ cy.intercept(
|
|
|
+ parseUrl(url),
|
|
|
+ response,
|
|
|
+ );
|
|
|
+}
|
|
|
|
|
|
export function loginSetup() {
|
|
|
cy.visit('/');
|
|
@@ -10,17 +47,17 @@ export function loginSetup() {
|
|
|
}
|
|
|
|
|
|
export function loginIntercept() {
|
|
|
- cy.intercept(`${NETWORK_URL}/user/login*`, {fixture: 'login'}).as('loginIntercept');
|
|
|
+ normalIntercept('/user/login', 'login').as('loginIntercept');
|
|
|
}
|
|
|
|
|
|
export function menuIntercept() {
|
|
|
- cy.intercept(`${NETWORK_URL}/menu/getUserMenu*`, {fixture: 'menu/basic'})
|
|
|
+ normalIntercept('/menu/getUserMenu', 'menu/basic')
|
|
|
.as('menuIntercept');
|
|
|
}
|
|
|
|
|
|
export function optionsIntercept() {
|
|
|
- cy.intercept(`${NETWORK_URL}/role/roleBefore*`, {fixture: 'role/options'});
|
|
|
- cy.intercept(`${NETWORK_URL}/department/getDepartBefor*`, {fixture: 'department/options'});
|
|
|
- cy.intercept(`${NETWORK_URL}/storage/getStorageAll*`, {fixture: 'storage/options'});
|
|
|
+ normalIntercept('/role/roleBefore', 'role/options');
|
|
|
+ normalIntercept('/department/getDepartBefor', 'department/options');
|
|
|
+ normalIntercept('/storage/getStorageAll', 'storage/options');
|
|
|
}
|
|
|
|