From f60381d9d1308253d3a75a4c58adf92671bc995a Mon Sep 17 00:00:00 2001 From: JG Date: Mon, 23 May 2022 09:47:52 +0100 Subject: [PATCH] refactored the feature --- features/sign_in.feature | 7 ++++- features/step_definitions/sign_in_steps.rb | 32 ++++++++++++++++------ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/features/sign_in.feature b/features/sign_in.feature index 7555d7312..477a0691b 100644 --- a/features/sign_in.feature +++ b/features/sign_in.feature @@ -1,8 +1,13 @@ Feature: Sign in Scenario: Signing in - Given There is a user in the database + Given There is a "Data Coordinator" user in the database When I visit the sign in page And I fill in the sign in form And I click the sign in button Then I should see the logs page + + Scenario: Signing out + Given I am signed in as "Data Coordinator" + When I click the sign out button + Then I should see the root page diff --git a/features/step_definitions/sign_in_steps.rb b/features/step_definitions/sign_in_steps.rb index 78c741594..17a0df4a5 100644 --- a/features/step_definitions/sign_in_steps.rb +++ b/features/step_definitions/sign_in_steps.rb @@ -1,20 +1,34 @@ -Given('There is a user in the database') do - @user = create :user +When("I visit the sign in page") do + visit "/account/sign-in" end -When('I visit the sign in page') do - visit("/account/sign-in") -end - -When('I fill in the sign in form') do +When("I fill in the sign in form") do fill_in("user[email]", with: @user.email) fill_in("user[password]", with: @user.password) end -When('I click the sign in button') do +When("I click the sign in button") do click_button("Sign in") end -Then('I should see the logs page') do +Then("I should see the logs page") do expect(page).to have_current_path("/logs") end + +Then("I should see the root page") do +end + +Given("There is a {string} user in the database") do |role| + @user = create :user, role: role.parameterize(separator: "_") +end + +Given("I am signed in as {string}") do |role| + step "There is a \"#{role}\" user in the database" + step "I visit the sign in page" + step "I fill in the sign in form" + step "I click the sign in button" +end + +When("I click the sign out button") do + click_link("Sign out") +end