123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
- const isAndroid = platformInfo.startsWith('android')
- const isIos = platformInfo.startsWith('ios')
- const isHarmony = platformInfo.startsWith('harmony')
- const isApp = isAndroid || isIos || isHarmony
- const isWeb = platformInfo.startsWith('web')
- const isMP = platformInfo.startsWith('mp')
- const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
- describe('showActionSheet', () => {
- let topSafeArea = 0;
- let page;
- let screenShotOptions = {};
- async function showActionSheet(page) {
- const btn = await page.$('#btn-action-sheet-show')
- await btn.tap()
- await page.waitFor(1000);
- }
- async function screenshot() {
- const image = await program.screenshot(screenShotOptions);
- expect(image).toSaveImageSnapshot();
- }
- beforeAll(async () => {
- page = await program.reLaunch('/pages/tabBar/API')
- await page.waitFor('view');
- const windowInfo = await program.callUniMethod('getWindowInfo');
- // android 端 app-webview 时顶部安全区高度为0,所以统一设置为60
- topSafeArea = windowInfo.safeAreaInsets.top;
- page = await program.navigateTo('/pages/API/show-action-sheet/show-action-sheet')
- await page.waitFor('view');
- if (isApp && !isAppWebView) {
- if(isAndroid || isIos){
- await page.callMethod('setThemeAuto')
- }
- screenShotOptions = {
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- },
- }
- } else if (isWeb){
- screenShotOptions = {
- fullPage: true
- }
- }
- });
- it("onload showActionSheet", async () => {
- await page.waitFor(isWeb ? 3000 : 1000);
- await screenshot();
- // 非交互关闭应触发 fail 回调
- if (!isMP) {
- const originLifeCycleNum = await page.callMethod('getLifeCycleNum');
- await program.navigateBack();
- await page.waitFor(1000);
- page = await program.navigateTo('/pages/API/show-action-sheet/show-action-sheet')
- const newLifeCycleNum = await page.callMethod('getLifeCycleNum');
- expect(newLifeCycleNum).toBe(originLifeCycleNum + 2);
- }
- })
- it("有标题", async () => {
- await page.setData({
- showErrorToast:false,
- current: 0,
- })
- await showActionSheet(page);
- await screenshot();
- })
- it("有标题 长内容", async () => {
- await page.setData({
- itemContentLarge:true,
- })
- await showActionSheet(page);
- await screenshot();
- })
- it("有标题 超过6个item", async () => {
- await page.setData({
- itemContentLarge:false,
- itemNumLargeSelect:true,
- })
- await showActionSheet(page);
- await screenshot();
- })
- it("有标题 长内容 自定义 itemColor", async () => {
- await page.setData({
- itemContentLarge: true,
- itemNumLargeSelect: false,
- itemColorCustom: true,
- })
- await showActionSheet(page);
- await screenshot();
- })
- it("无标题", async () => {
- await page.setData({
- current: 1,
- itemContentLarge:false,
- itemColorCustom:false,
- })
- await showActionSheet(page);
- await screenshot();
- })
- it("长标题", async () => {
- await page.setData({
- current: 2,
- })
- await showActionSheet(page);
- await screenshot();
- })
- if (!isMP) {
- it("custom titleColor cancelText cancelColor backgroundColor", async () => {
- await page.setData({
- titleColorCustom: true,
- cancelTextCustom: true,
- cancelColorCustom: true,
- backgroundColorCustom: true,
- })
- await showActionSheet(page);
- await page.waitFor(1000)
- await screenshot();
- })
- }
- it("showActionSheet 并在回调中再次 showActionSheet", async () => {
- await page.callMethod('showActionSheetAndShowAgainInCallback')
- await page.waitFor(1000);
- await screenshot();
- if (isApp) {
- await program.tap({
- x: 200,
- y: 700,
- })
- } else if (isWeb) {
- await page.callMethod('closeWebActionSheet')
- }
- await page.waitFor(1000);
- await screenshot();
- })
- if (!isMP) {
- it("hideActionSheet", async () => {
- await page.callMethod('hideActionSheet')
- await page.waitFor(1000);
- await screenshot();
- })
- }
- afterAll(async () => {
- if(isApp && !isAppWebView){
- await page.callMethod('resetTheme')
- }
- });
- });
|