|
| 1 | +// @ts-nocheck |
| 2 | +import * as utils from '../../src/utils'; |
| 3 | +import { AppiumFlutterDriver } from '../../src/driver'; |
| 4 | +import { JWProxy } from 'appium/driver'; |
| 5 | +import sinon from 'sinon'; |
| 6 | + |
| 7 | + |
| 8 | +describe('attachAppLaunchArguments', function() { |
| 9 | + let driver; |
| 10 | + let chai, expect; |
| 11 | + let sandbox; |
| 12 | + |
| 13 | + beforeEach(async function() { |
| 14 | + chai = await import('chai'); |
| 15 | + const chaiAsPromised = await import('chai-as-promised'); |
| 16 | + |
| 17 | + chai.should(); |
| 18 | + chai.use(chaiAsPromised.default); |
| 19 | + |
| 20 | + expect = chai.expect; |
| 21 | + sandbox = sinon.createSandbox(); |
| 22 | + driver = new AppiumFlutterDriver(); |
| 23 | + driver.log; |
| 24 | + const debugStrub = sandbox.stub(driver._log, 'info'); |
| 25 | + sandbox.stub(Object.getPrototypeOf(driver), 'log').get(() => { |
| 26 | + return { info: sandbox.spy() }; |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(function() { |
| 31 | + sandbox.restore(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should attach flutter server port to processArguments for iOS platform', function() { |
| 35 | + const parsedCaps = { platformName: 'iOS', flutterSystemPort: '12345' }; |
| 36 | + const caps = [{}, { alwaysMatch: {}, firstMatch: [{}] }]; |
| 37 | + |
| 38 | + utils.attachAppLaunchArguments.call(driver, parsedCaps, ...caps); |
| 39 | + |
| 40 | + const expectedArgs = ['--flutter-server-port=12345']; |
| 41 | + expect(caps[1].alwaysMatch['appium:processArguments'].args).to.deep.equal(expectedArgs); |
| 42 | + |
| 43 | + }); |
| 44 | + |
| 45 | + it('should not modify caps if no W3C caps are passed', function() { |
| 46 | + const parsedCaps = { platformName: 'iOS', flutterSystemPort: '12345' }; |
| 47 | + const caps = [{}]; // No W3C caps |
| 48 | + |
| 49 | + utils.attachAppLaunchArguments.call(driver, parsedCaps, ...caps); |
| 50 | + |
| 51 | + expect(caps[0]).to.deep.equal({}); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should not modify caps if platform is not iOS', function() { |
| 55 | + const parsedCaps = { platformName: 'Android', flutterSystemPort: '12345' }; |
| 56 | + const caps = [{}, { alwaysMatch: {}, firstMatch: [{}] }]; |
| 57 | + |
| 58 | + utils.attachAppLaunchArguments.call(driver, parsedCaps, ...caps); |
| 59 | + |
| 60 | + expect(caps[1].firstMatch[0]).to.not.have.property('appium:processArguments'); |
| 61 | + }); |
| 62 | +}); |
| 63 | + |
| 64 | +describe('Utils Test', function() { |
| 65 | + let chai, expect; |
| 66 | + let sandbox: sinon.SinonSandbox; |
| 67 | + let driver: AppiumFlutterDriver; |
| 68 | + let proxy: JWProxy; |
| 69 | + before(async function () { |
| 70 | + chai = await import('chai'); |
| 71 | + const chaiAsPromised = await import('chai-as-promised'); |
| 72 | + |
| 73 | + chai.should(); |
| 74 | + chai.use(chaiAsPromised.default); |
| 75 | + |
| 76 | + expect = chai.expect; |
| 77 | + sandbox = sinon.createSandbox(); |
| 78 | + driver = new AppiumFlutterDriver(); |
| 79 | + proxy = new JWProxy({ server: '127.0.0.1', port: 4723 }); |
| 80 | + driver.proxy = function() {}; |
| 81 | + // Mocking proxydriver and its wda property |
| 82 | + driver.proxydriver = { |
| 83 | + wda: { |
| 84 | + jwproxy: { |
| 85 | + // Mock any methods of jwproxy that you need for your tests |
| 86 | + } |
| 87 | + } |
| 88 | + }; |
| 89 | + }); |
| 90 | + afterEach(function() { |
| 91 | + sandbox.restore(); |
| 92 | + }); |
| 93 | + it('should return the proxy for valid strategies', async function() { |
| 94 | + sandbox.stub(driver, 'proxy').value(proxy); |
| 95 | + const result = await utils.getProxyDriver.call(driver, 'key'); |
| 96 | + expect(result).to.equal(proxy); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should return true for valid W3C capabilities', function() { |
| 100 | + const caps = { |
| 101 | + alwaysMatch: { browserName: 'chrome' }, |
| 102 | + firstMatch: [{}], |
| 103 | + }; |
| 104 | + expect(utils.isW3cCaps(caps)).to.be.true; |
| 105 | + }); |
| 106 | + |
| 107 | + it('should return false for non-object values', function() { |
| 108 | + expect(utils.isW3cCaps(null)).to.be.false; |
| 109 | + expect(utils.isW3cCaps(undefined)).to.be.false; |
| 110 | + expect(utils.isW3cCaps(42)).to.be.false; |
| 111 | + expect(utils.isW3cCaps('string')).to.be.false; |
| 112 | + }); |
| 113 | + |
| 114 | + it('should return false for empty objects', function() { |
| 115 | + expect(utils.isW3cCaps({})).to.be.false; |
| 116 | + }); |
| 117 | + |
| 118 | + it('should return false for objects missing both alwaysMatch and firstMatch', function() { |
| 119 | + const caps = { browserName: 'chrome' }; |
| 120 | + expect(utils.isW3cCaps(caps)).to.be.false; |
| 121 | + }); |
| 122 | + |
| 123 | + it('should return true for objects with valid alwaysMatch and empty firstMatch', function() { |
| 124 | + const caps = { |
| 125 | + alwaysMatch: { platformName: 'iOS' }, |
| 126 | + firstMatch: [{}], |
| 127 | + }; |
| 128 | + expect(utils.isW3cCaps(caps)).to.be.true; |
| 129 | + }); |
| 130 | + |
| 131 | + it('should return true for objects with valid firstMatch and no alwaysMatch', function() { |
| 132 | + const caps = { |
| 133 | + firstMatch: [{ platformName: 'Android' }], |
| 134 | + }; |
| 135 | + expect(utils.isW3cCaps(caps)).to.be.true; |
| 136 | + }); |
| 137 | + |
| 138 | + it('should return false for objects with invalid firstMatch structure', function() { |
| 139 | + const caps = { |
| 140 | + firstMatch: 'invalid', |
| 141 | + }; |
| 142 | + expect(utils.isW3cCaps(caps)).to.be.false; |
| 143 | + }); |
| 144 | + |
| 145 | + it('should return false for objects with invalid alwaysMatch structure', function() { |
| 146 | + const caps = { |
| 147 | + alwaysMatch: 'invalid', |
| 148 | + }; |
| 149 | + expect(utils.isW3cCaps(caps)).to.be.false; |
| 150 | + }); |
| 151 | +}); |
0 commit comments