Skip to content

Commit

Permalink
Move & Reimplement Skipped CredentialLive Tests (#1061)
Browse files Browse the repository at this point in the history
* Move tests to workflow_live/edit_tests.exs and make them fail

* Update CHANGELOG.md

* Change tests target elements to new ones

* Use CredentialLiveHelpers module

* Remove unused imports
  • Loading branch information
elias-ba authored Aug 30, 2023
1 parent a4f5ae3 commit ffabb1c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 128 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to
[#961](https://github.com/OpenFn/Lightning/issues/961)
- Show that the jobs' body is invalid
[#957](https://github.com/OpenFn/Lightning/issues/957)
- Reimplement skipped CredentialLive tests
[#962](https://github.com/OpenFn/Lightning/issues/962)

### Changed

Expand Down
129 changes: 1 addition & 128 deletions test/lightning_web/live/credential_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ defmodule LightningWeb.CredentialLiveTest do
import Phoenix.LiveViewTest
import LightningWeb.CredentialLiveHelpers

import Lightning.{
JobsFixtures,
CredentialsFixtures
}
import Lightning.CredentialsFixtures

alias Lightning.CredentialsFixtures
alias Lightning.Credentials
Expand Down Expand Up @@ -429,130 +426,6 @@ defmodule LightningWeb.CredentialLiveTest do
end
end

@tag skip: true
describe "New credential from project context " do
setup %{project: project} do
%{job: job} = workflow_job_fixture(project_id: project.id)
%{job: job}
end

test "open credential modal from the job inspector (edit_job)", %{
conn: conn,
project: project,
job: job
} do
{:ok, view, _html} =
live(conn, ~p"/projects/#{project.id}/w/#{job.workflow_id}?s=#{job.id}")

assert has_element?(view, "#builder-#{job.id}")

# open the new credential modal

assert view
|> element("#new-credential-launcher", "New credential")
|> render_click()

# assertions

assert has_element?(view, "#credential-type-picker")
view |> select_credential_type("http")
view |> click_continue()

refute has_element?(view, "#project_list")
end

@tag skip: true
test "create new credential from job inspector and update the job form", %{
conn: conn,
project: project,
job: job
} do
{:ok, view, _html} =
live(conn, ~p"/projects/#{project.id}/w/#{job.workflow_id}?s=#{job.id}")

# open the new credential modal

assert view
|> element("#new-credential-launcher", "New credential")
|> render_click()

# fill the modal and save
view |> select_credential_type("raw")
view |> click_continue()

view
|> form("#credential-form",
credential: %{
name: "newly created credential",
body: Jason.encode!(%{"a" => 1})
}
)
|> render_submit()

# assertions

refute has_element?(view, "#credential-form")

assert view
|> element(
~S{#job-form select#credentialField option[selected=selected]}
)
|> render() =~ "newly created credential",
"Should have the project credential selected"
end

@tag skip: true
test "create new credential from edit job form and update the job form", %{
conn: conn,
project: project,
job: job
} do
{:ok, view, _html} =
live(conn, ~p"/projects/#{project.id}/w/#{job.workflow_id}?s=#{job.id}")

# change the job name so we can assert that the form state had been
# kept after saving the new credential
view
|> form("#job-form", job_form: %{name: "last typed name"})
|> render_change()

# open the new credential modal
assert view
|> element("#new-credential-launcher", "New credential")
|> render_click()

# fill the modal and save

view |> select_credential_type("raw")
view |> click_continue()

view
|> form("#credential-form",
credential: %{
name: "newly created credential",
body: Jason.encode!(%{"a" => 1})
}
)
|> render_submit()

# assertions

refute has_element?(view, "#credential-form")

assert view
|> element(
~S{#job-form select#credentialField option[selected=selected]}
)
|> render() =~ "newly created credential",
"Should have the project credential selected"

assert view
|> element(~S{#job-form input#job-form_name})
|> render() =~ "last typed name",
"Should have kept the job form state after saving the new credential"
end
end

describe "googlesheets credential" do
setup do
bypass = Bypass.open()
Expand Down
63 changes: 63 additions & 0 deletions test/lightning_web/live/workflow_live/edit_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,75 @@ defmodule LightningWeb.WorkflowLive.EditTest do
import Phoenix.LiveViewTest
import Lightning.WorkflowLive.Helpers
import Lightning.WorkflowsFixtures
import Lightning.JobsFixtures

alias LightningWeb.CredentialLiveHelpers

setup :register_and_log_in_user
setup :create_project_for_current_user

describe "New credential from project context " do
setup %{project: project} do
%{job: job} = workflow_job_fixture(project_id: project.id)
%{job: job}
end

test "open credential modal from the job inspector (edit_job)", %{
conn: conn,
project: project,
job: job
} do
{:ok, view, _html} =
live(conn, ~p"/projects/#{project.id}/w/#{job.workflow_id}?s=#{job.id}")

assert has_element?(view, "#job-pane-#{job.id}")

assert view
|> element("#new-credential-launcher", "New credential")
|> render_click()

assert has_element?(view, "#credential-type-picker")
view |> CredentialLiveHelpers.select_credential_type("http")
view |> CredentialLiveHelpers.click_continue()

refute has_element?(view, "#project_list")
end

test "create new credential from job inspector and update the job form", %{
conn: conn,
project: project,
job: job
} do
{:ok, view, _html} =
live(conn, ~p"/projects/#{project.id}/w/#{job.workflow_id}?s=#{job.id}")

assert view
|> element("#new-credential-launcher", "New credential")
|> render_click()

view |> CredentialLiveHelpers.select_credential_type("raw")
view |> CredentialLiveHelpers.click_continue()

view
|> form("#credential-form",
credential: %{
name: "newly created credential",
body: Jason.encode!(%{"a" => 1})
}
)
|> render_submit()

refute has_element?(view, "#credential-form")

assert view
|> element(
~S{[name='workflow[jobs][0][project_credential_id]'] option[selected="selected"]}
)
|> render() =~ "newly created credential",
"Should have the project credential selected"
end
end

describe "new" do
test "builds a new workflow", %{conn: conn, project: project} do
{:ok, view, _html} = live(conn, ~p"/projects/#{project.id}/w/new")
Expand Down

0 comments on commit ffabb1c

Please sign in to comment.