setup.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {CyHttpMessages, RouteHandler} from 'cypress/types/net-stubbing';
  2. function parseUrl(url: string) {
  3. return `http://*${
  4. url.indexOf('/') === 0 ? '' : '/'
  5. }${url}${
  6. url.includes('*') ? '' : '*'
  7. }`;
  8. }
  9. export function normalIntercept(
  10. url: string,
  11. fixture: string,
  12. options?: Omit<RouteHandler, 'fixture'>,
  13. ) {
  14. return cy.intercept(
  15. parseUrl(url),
  16. {fixture, ...(options ?? {})},
  17. );
  18. }
  19. export function successIntercept(url: string) {
  20. return normalIntercept(
  21. url,
  22. 'success',
  23. {delay: 100},
  24. );
  25. }
  26. export function intercept(
  27. url: string,
  28. response: (e: CyHttpMessages.IncomingHttpRequest) => void,
  29. ) {
  30. cy.intercept(
  31. parseUrl(url),
  32. response,
  33. );
  34. }
  35. export function loginSetup() {
  36. cy.visit('/');
  37. cy.get('input[name="accountName"]').type('admin');
  38. cy.get('input[name="accountPassword"]').type('tld123');
  39. cy.getTestId('login_form').submit();
  40. }
  41. export function loginIntercept() {
  42. normalIntercept('/user/login', 'login').as('loginIntercept');
  43. }
  44. export function menuIntercept() {
  45. normalIntercept('/menu/getUserMenu', 'menu/basic')
  46. .as('menuIntercept');
  47. }
  48. export function optionsIntercept() {
  49. normalIntercept('/role/roleBefore', 'role/options');
  50. normalIntercept('/department/getDepartBefor', 'department/options');
  51. normalIntercept('/storage/getStorageAll', 'storage/options');
  52. }