|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +require 'test_helper' |
| 16 | +require 'webmock/minitest' |
| 17 | + |
| 18 | +# $ rake test:unit TEST=test/unit/android/device/mjsonwp/event_test.rb |
| 19 | +class AppiumLibCoreTest |
| 20 | + module Android |
| 21 | + module Device |
| 22 | + module MJSONWP |
| 23 | + class EventTest < Minitest::Test |
| 24 | + include AppiumLibCoreTest::Mock |
| 25 | + |
| 26 | + def setup |
| 27 | + @core ||= ::Appium::Core.for(Caps.android) |
| 28 | + @driver ||= android_mock_create_session |
| 29 | + end |
| 30 | + |
| 31 | + def test_log_event |
| 32 | + stub_request(:post, "#{SESSION}/appium/log_event") |
| 33 | + .with(body: { vendor: 'appium', event: 'customEvent' }.to_json) |
| 34 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 35 | + |
| 36 | + @driver.logs.event vendor: 'appium', event: 'customEvent' |
| 37 | + |
| 38 | + assert_requested(:post, "#{SESSION}/appium/log_event", times: 1) |
| 39 | + end |
| 40 | + |
| 41 | + def test_log_event_equal |
| 42 | + stub_request(:post, "#{SESSION}/appium/log_event") |
| 43 | + .with(body: { vendor: 'appium', event: 'customEvent' }.to_json) |
| 44 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 45 | + |
| 46 | + @driver.logs.event = { vendor: 'appium', event: 'customEvent' } |
| 47 | + |
| 48 | + assert_requested(:post, "#{SESSION}/appium/log_event", times: 1) |
| 49 | + end |
| 50 | + |
| 51 | + def test_log_events |
| 52 | + stub_request(:post, "#{SESSION}/appium/events") |
| 53 | + .with(body: {}.to_json) |
| 54 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 55 | + |
| 56 | + @driver.logs.events |
| 57 | + |
| 58 | + assert_requested(:post, "#{SESSION}/appium/events", times: 1) |
| 59 | + end |
| 60 | + |
| 61 | + def test_log_events_with_type |
| 62 | + stub_request(:post, "#{SESSION}/appium/events") |
| 63 | + .with(body: { type: 'commands' }.to_json) |
| 64 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 65 | + |
| 66 | + @driver.logs.events('commands') |
| 67 | + |
| 68 | + assert_requested(:post, "#{SESSION}/appium/events", times: 1) |
| 69 | + end |
| 70 | + end # class EventTest |
| 71 | + end # module MJSONWP |
| 72 | + end # module Device |
| 73 | + end # module Android |
| 74 | +end # class AppiumLibCoreTest |
0 commit comments