第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Cypress 中測試拖動傳單地圖

在 Cypress 中測試拖動傳單地圖

幕布斯7119047 2022-06-09 17:08:32
我有一個非常簡單的用例:我想在更改傳單地圖視口時通過抓取它來測試數(shù)據(jù)獲取。但是,我不知道如何編寫測試。這是代碼:      cy.visit("/map");      // wait for data      cy.get(".leaflet-interactive.multilinestring");      // simulate map moving      cy.get(".leaflet-container")        .trigger("mousedown", "center")        .trigger("mousemove", 30, 30);        .trigger("mouseup");      // map should be loading      cy.get(".leaflet-container.leaflet-loading");它似乎沒有移動地圖。我試圖在觸發(fā)調(diào)用之間添加等待,因為我認(rèn)為可能會有關(guān)于事件觸發(fā)速度的警衛(wèi),但沒有運(yùn)氣。知道如何測試這個。
查看完整描述

1 回答

?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗 獲得超5個贊

似乎cy.trigger()我們需要使用原生事件而不是使用 ,以使 Leaflet 認(rèn)為地圖正在拖動。


我們編寫了一個自定義 Cypress 命令dragMapFromCenter,使用它看起來像這樣:


cy.get('#map-canvas').dragMapFromCenter({

  // Go 1/6 of map container width to the right (negative direction)

  xMoveFactor: -1 / 6,

  // Go 1/3 of map container height to the top (positive direction)

  yMoveFactor: 1 / 3

});


// We need to wait for something to happen after map starts moving

cy.get(".leaflet-container.leaflet-loading");

這是dragMapFromCenter. 將其放入cypress/support/commands.js以便能夠在測試中使用它。


// # cy.get('#map-canvas').dragMapFromCenter({ xMoveFactor: 0.25, yMoveFactor: -0.5 })

//

// Allows dragging a Leaflet map by the given amounts. A factor of 1 means the map

// will be dragged the whole width of the map canvas in X direction and the whole

// height of the map canvas in Y direction.

Cypress.Commands.add(

  'dragMapFromCenter',

  { prevSubject: 'element' },

  (element, { xMoveFactor, yMoveFactor }) => {

    // Get the raw HTML element from jQuery wrapper

    const canvas = element.get(0);

    const rect = canvas.getBoundingClientRect();

    const center = {

      x: rect.left + rect.width / 2,

      y: rect.top + rect.height / 2

    };


    // Start dragging from the center of the map

    cy.log('mousedown', {

      clientX: center.x,

      clientY: center.y

    });

    canvas.dispatchEvent(

      new MouseEvent('mousedown', {

        clientX: center.x,

        clientY: center.y

      })

    );


    // Let Leaflet know the mouse has started to move. The diff between

    // mousedown and mousemove event needs to be large enough so that Leaflet

    // will really think the mouse is moving and not that it was a click where

    // the mouse moved just a tiny amount.

    cy.log('mousemove', {

      clientX: center.x,

      clientY: center.y + 5

    });

    canvas.dispatchEvent(

      new MouseEvent('mousemove', {

        clientX: center.x,

        clientY: center.y + 5,

        bubbles: true

      })

    );


    // After Leaflet knows mouse is moving, we move the mouse as depicted by the options.

    cy.log('mousemove', {

      clientX: center.x + rect.width * xMoveFactor,

      clientY: center.y + rect.height * yMoveFactor

    });

    canvas.dispatchEvent(

      new MouseEvent('mousemove', {

        clientX: center.x + rect.width * xMoveFactor,

        clientY: center.y + rect.height * yMoveFactor,

        bubbles: true

      })

    );


    // Now when we "release" the mouse, Leaflet will fire a "dragend" event and

    // the search should register that the drag has stopped and run callbacks.

    cy.log('mouseup', {

      clientX: center.x + rect.width * xMoveFactor,

      clientY: center.y + rect.height * yMoveFactor

    });

    requestAnimationFrame(() => {

      canvas.dispatchEvent(

        new MouseEvent('mouseup', {

          clientX: center.x + rect.width * xMoveFactor,

          clientY: center.y + rect.height * yMoveFactor,

          bubbles: true

        })

      );

    });

  }

);



查看完整回答
反對 回復(fù) 2022-06-09
  • 1 回答
  • 0 關(guān)注
  • 333 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號