phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6k stars 906 forks source link

Fix `Phoenix.LiveViewTest.file_input/4` ignoring `last_modified` option #3254

Closed ggcampinho closed 1 month ago

ggcampinho commented 2 months ago

Phoenix.LiveViewTest.file_input/4 is ignoring the option last_modified, so it's impossible to populate entry.client_last_modified with this test function as the documentation says.

Before

[test/phoenix_live_view/upload/external_test.exs:233: Phoenix.LiveView.UploadExternalTest."test consume_uploaded_entries"/1]
file_input(lv, "form", :avatar, [
  %{name: "foo.jpeg", content: String.duplicate("ok", 100), last_modified: 1_594_171_879_000}
]) #=> #Phoenix.LiveViewTest.Upload<
  selector: nil,
  entries: [
    %{
      "content" => "okokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokok",
      "name" => "foo.jpeg",
      "ref" => "9417",
      "relative_path" => nil,
      "size" => 200,
      "type" => "image/jpeg"
    }
  ],
  ...
>

[test/phoenix_live_view/upload/external_test.exs:239: Phoenix.LiveView.UploadExternalTest."test consume_uploaded_entries"/1]
entry #=> %Phoenix.LiveView.UploadEntry{
  progress: 100,
  preflighted?: true,
  upload_config: :avatar,
  upload_ref: "phx-F9CfhwGDfrW4fgdD",
  ref: "1924",
  uuid: "d3bd3c54-cb47-4e41-a40a-6b4ecbf9e294",
  valid?: true,
  done?: true,
  cancelled?: false,
  client_name: "foo.jpeg",
  client_relative_path: nil,
  client_size: 200,
  client_type: "image/jpeg",
  client_last_modified: nil,
  client_meta: nil
}

After

[test/phoenix_live_view/upload/external_test.exs:233: Phoenix.LiveView.UploadExternalTest."test consume_uploaded_entries"/1]
file_input(lv, "form", :avatar, [
  %{name: "foo.jpeg", content: String.duplicate("ok", 100), last_modified: 1_594_171_879_000}
]) #=> #Phoenix.LiveViewTest.Upload<
  selector: nil,
  entries: [
    %{
      "content" => "okokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokok",
      "last_modified" => 1594171879000,
      "name" => "foo.jpeg",
      "ref" => "4354",
      "relative_path" => nil,
      "size" => 200,
      "type" => "image/jpeg"
    }
  ],
  ...
>

[test/phoenix_live_view/upload/external_test.exs:239: Phoenix.LiveView.UploadExternalTest."test consume_uploaded_entries"/1]
entry #=> %Phoenix.LiveView.UploadEntry{
  progress: 100,
  preflighted?: true,
  upload_config: :avatar,
  upload_ref: "phx-F9CffrMSpNMdjAdC",
  ref: "1923",
  uuid: "61511cac-9568-4e5d-8bed-ede46331ce4c",
  valid?: true,
  done?: true,
  cancelled?: false,
  client_name: "foo.jpeg",
  client_relative_path: nil,
  client_size: 200,
  client_type: "image/jpeg",
  client_last_modified: 1594171879000,
  client_meta: nil
}
josevalim commented 1 month ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: