Skip to content

Commit

Permalink
[frameit] fix device detection that would match less specific devices…
Browse files Browse the repository at this point in the history
… first (#20642)

* fix

* fix tests
  • Loading branch information
guidev committed Oct 25, 2022
1 parent 950bb82 commit 7de28ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frameit/lib/frameit/device.rb
Expand Up @@ -51,7 +51,7 @@ def self.detect_device(path, platform)
found_device = nil
filename_device = nil
filename = Pathname.new(path).basename.to_s
Devices.constants.each do |c|
Devices.constants.sort_by(&:length).reverse_each do |c|
device = Devices.const_get(c)
next unless device.resolutions.include?(size)
# assign to filename_device if the filename contains the formatted name / id and its priority is higher than the current filename_device
Expand Down
4 changes: 2 additions & 2 deletions frameit/spec/device_spec.rb
Expand Up @@ -34,8 +34,8 @@ def expect_forced_screen_size(value)
end

it "should detect iPhone 13 in portrait and landscape based on priority" do
expect_screen_size_from_file("screenshot-Portrait{1170x2532}.jpg", Platform::IOS).to eq(Devices::IPHONE_13)
expect_screen_size_from_file("screenshot-Landscape{2532x1170}.jpg", Platform::IOS).to eq(Devices::IPHONE_13)
expect_screen_size_from_file("screenshot-Portrait{1170x2532}.jpg", Platform::IOS).to eq(Devices::IPHONE_13_PRO)
expect_screen_size_from_file("screenshot-Landscape{2532x1170}.jpg", Platform::IOS).to eq(Devices::IPHONE_13_PRO)
end

it "should detect iPhone X instead of iPhone XS because of the file name containing device name" do
Expand Down

0 comments on commit 7de28ca

Please sign in to comment.