Quellcode durchsuchen

add more tests for night_mode

Christopher Mullins vor 6 Jahren
Ursprung
Commit
c0ded15bfb
2 geänderte Dateien mit 26 neuen und 12 gelöschten Zeilen
  1. 1 0
      test/remote/helpers/state_helpers.rb
  2. 25 12
      test/remote/spec/state_spec.rb

+ 1 - 0
test/remote/helpers/state_helpers.rb

@@ -1,4 +1,5 @@
 module StateHelpers
+  ALL_REMOTE_TYPES = %w(rgb rgbw rgb_cct cct fut089 fut091)
   def states_are_equal(desired_state, retrieved_state)
     expect(retrieved_state).to include(*desired_state.keys)
     expect(retrieved_state.select { |x| desired_state.include?(x) } ).to eq(desired_state)

+ 25 - 12
test/remote/spec/state_spec.rb

@@ -34,20 +34,33 @@ RSpec.describe 'State' do
   end
 
   context 'night mode command' do
-    it 'should affect state when bulb is off' do
-      state = @client.patch_state({'command' => 'night_mode'}, @id_params)
-
-      expect(state['bulb_mode']).to eq('night')
-      expect(state['effect']).to    eq('night_mode')
+    StateHelpers::ALL_REMOTE_TYPES
+      .reject { |x| %w(rgb).include?(x) } # Night mode not supported for these types
+      .each do |type|
+      it "should affect state when bulb is OFF for #{type}" do
+        params = @id_params.merge(type: type)
+        @client.delete_state(params)
+        state = @client.patch_state({'command' => 'night_mode'}, params)
+
+        expect(state['bulb_mode']).to eq('night')
+        expect(state['effect']).to    eq('night_mode')
+      end
     end
 
-    it 'should affect state when bulb is on' do
-      @client.patch_state({'status' => 'ON'}, @id_params)
-      state = @client.patch_state({'command' => 'night_mode'}, @id_params)
-
-      expect(state['status']).to    eq('ON')
-      expect(state['bulb_mode']).to eq('night')
-      expect(state['effect']).to    eq('night_mode')
+    StateHelpers::ALL_REMOTE_TYPES
+      .reject { |x| %w(rgb).include?(x) } # Night mode not supported for these types
+      .each do |type|
+      it "should affect state when bulb is ON for #{type}" do
+        params = @id_params.merge(type: type)
+        @client.delete_state(params)
+        @client.patch_state({'status' => 'ON'}, params)
+        state = @client.patch_state({'command' => 'night_mode'}, params)
+
+        # RGBW bulbs have to be OFF in order for night mode to take affect
+        expect(state['status']).to    eq('ON') if type != 'rgbw'
+        expect(state['bulb_mode']).to eq('night')
+        expect(state['effect']).to    eq('night_mode')
+      end
     end
 
     it 'should revert to previous mode when status is toggled' do