Skip to content

Commit afd65c6

Browse files
committed
Adpat tests to new page structure on MyAccount > security
1 parent d509e32 commit afd65c6

13 files changed

Lines changed: 104 additions & 87 deletions

File tree

modules/two_factor_authentication/app/components/two_factor_authentication/devices/row_component.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def make_default_button
5959
tag: :button,
6060
size: :small,
6161
type: :submit,
62+
test_selector: "two-factor--make-default-button",
6263
"aria-label": I18n.t(:button_make_default)
6364
)
6465
)
@@ -80,6 +81,7 @@ def delete_button
8081
size: :small,
8182
type: :submit,
8283
disabled: deletion_blocked?,
84+
test_selector: "two-factor--delete-button",
8385
"aria-label": if deletion_blocked?
8486
I18n.t("two_factor_authentication.devices.is_default_cannot_delete")
8587
else

modules/two_factor_authentication/app/components/two_factor_authentication/my/security_section_component.html.erb

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
<%= render(Primer::Beta::Subhead.new(my: 3)) do |subhead|
2-
subhead.with_heading(tag: :h3, size: :medium) { t "two_factor_authentication.label_devices" }
3-
end %>
2+
subhead.with_heading(tag: :h3, size: :medium) { t "two_factor_authentication.label_devices" }
3+
end %>
44

55
<% if @has_remember_token_for_user %>
6-
<%= render(Primer::Alpha::Banner.new(scheme: :default, dismiss_scheme: :none, mb: 3,
7-
id: "two_factor_authentication_remember_cookie")) do |banner|
8-
banner.with_action_button(tag: :a,
9-
href: helpers.my_2fa_remember_cookie_path,
10-
data: { turbo_method: :delete }) do
6+
<%= render(
7+
Primer::Alpha::Banner.new(
8+
scheme: :default, dismiss_scheme: :none, mb: 3,
9+
id: "two_factor_authentication_remember_cookie"
10+
)
11+
) do |banner|
12+
banner.with_action_button(
13+
tag: :a,
14+
href: helpers.my_2fa_remember_cookie_path,
15+
test_selector: "two-factor-authentication--remove-remember-cookie-link",
16+
data: { turbo_method: :delete }
17+
) do
1118
t("two_factor_authentication.remember.clear_cookie")
1219
end
1320

1421
if @remember_token
15-
t("two_factor_authentication.remember.active_session_notice",
16-
expires_on: helpers.format_date(@remember_token.expires_on))
22+
t(
23+
"two_factor_authentication.remember.active_session_notice",
24+
expires_on: helpers.format_date(@remember_token.expires_on)
25+
)
1726
else
1827
t("two_factor_authentication.remember.other_active_session_notice")
1928
end
@@ -25,35 +34,37 @@ end %>
2534
<%= render ::TwoFactorAuthentication::Devices::TableComponent.new(rows: @two_factor_devices, admin_table: false) %>
2635

2736
<%= render(Primer::Alpha::ActionMenu.new(anchor_align: :end)) do |menu|
28-
menu.with_show_button(
29-
test_selector: "two_factor_authentication_devices_button",
30-
aria: { label: t("two_factor_authentication.label_device") },
31-
mt: 3
32-
) do |button|
33-
button.with_leading_visual_icon(icon: :plus)
34-
button.with_trailing_visual_icon(icon: :"triangle-down")
35-
t("two_factor_authentication.label_device")
36-
end
37+
menu.with_show_button(
38+
test_selector: "two_factor_authentication_devices_button",
39+
aria: { label: t("two_factor_authentication.label_device") },
40+
mt: 3
41+
) do |button|
42+
button.with_leading_visual_icon(icon: :plus)
43+
button.with_trailing_visual_icon(icon: :"triangle-down")
44+
t("two_factor_authentication.label_device")
45+
end
3746

38-
@available_devices.each_key do |key|
39-
menu.with_item(
40-
label: t("two_factor_authentication.devices.#{key}.title"),
41-
href: helpers.new_my_2fa_device_path(type: key),
42-
test_selector: "two_factor_authentication_devices_#{key}"
43-
) do |item|
44-
item.with_description.with_content(t("two_factor_authentication.devices.#{key}.description"))
45-
end
46-
end
47-
end %>
47+
@available_devices.each_key do |key|
48+
menu.with_item(
49+
label: t("two_factor_authentication.devices.#{key}.title"),
50+
href: helpers.new_my_2fa_device_path(type: key),
51+
test_selector: "two_factor_authentication_devices_#{key}"
52+
) do |item|
53+
item.with_description.with_content(t("two_factor_authentication.devices.#{key}.description"))
54+
end
55+
end
56+
end %>
4857

4958
<%= render(Primer::Beta::Subhead.new(mt: 5)) do |subhead|
5059
subhead.with_heading(tag: :h3, size: :medium) { t "two_factor_authentication.backup_codes.plural" }
5160
subhead.with_description do
52-
safe_join([
53-
t("two_factor_authentication.backup_codes.overview_description"),
54-
tag.br,
55-
tag.strong(t("two_factor_authentication.backup_codes.generate.regenerate_warning"))
56-
])
61+
safe_join(
62+
[
63+
t("two_factor_authentication.backup_codes.overview_description"),
64+
tag.br,
65+
tag.strong(t("two_factor_authentication.backup_codes.generate.regenerate_warning"))
66+
]
67+
)
5768
end
5869
end %>
5970

modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def request_token_for_device(device, locals)
9898
default_message = t("two_factor_authentication.devices.confirm_send_failed")
9999
flash[:error] = "#{default_message} #{error}"
100100

101-
redirect_to action: :index
101+
redirect_to index_path
102102
end
103103
end
104104

modules/two_factor_authentication/app/views/two_factor_authentication/two_factor_devices/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<% if device_form_class %>
2525
<%= settings_primer_form_with(
2626
model: @device,
27-
as: :device,
27+
scope: :device,
2828
url: { action: :register },
2929
autocomplete: "off",
3030
data: {

modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
describe "accessing" do
3131
before do
32-
get :index
32+
get :new
3333
end
3434

3535
context "when not logged in" do
@@ -38,7 +38,7 @@
3838

3939
it "does not give access" do
4040
expect(response).to be_redirect
41-
expect(response).to redirect_to signin_path(back_url: my_2fa_devices_url)
41+
expect(response).to redirect_to signin_path(back_url: new_my_2fa_device_url)
4242
end
4343
end
4444

@@ -51,9 +51,9 @@
5151
context "when logged in and active strategies" do
5252
let(:active_strategies) { [:developer] }
5353

54-
it "renders the index page" do
54+
it "renders the new type selection page" do
5555
expect(response).to be_successful
56-
expect(response).to render_template "index"
56+
expect(response).to render_template "new_type"
5757
end
5858
end
5959
end
@@ -149,7 +149,7 @@
149149
.and_return(ServiceResult.failure)
150150

151151
get :confirm, params: { device_id: device.id }
152-
expect(response).to redirect_to action: :index
152+
expect(response).to redirect_to my_security_path
153153
expect(flash[:error]).to include I18n.t("two_factor_authentication.devices.confirm_send_failed")
154154
end
155155
end
@@ -167,7 +167,7 @@
167167

168168
it "renders a 400 on missing token" do
169169
post :confirm, params: { device_id: device.id }
170-
expect(response).to redirect_to action: :index
170+
expect(response).to redirect_to my_security_path
171171
end
172172

173173
it "redirects to the confirmation on faulty entry" do
@@ -192,7 +192,7 @@
192192
.and_return(ServiceResult.success)
193193

194194
post :confirm, params: { device_id: device.id, otp: "1234" }
195-
expect(response).to redirect_to action: :index
195+
expect(response).to redirect_to my_security_path
196196
expect(flash[:notice]).to include I18n.t("two_factor_authentication.devices.registration_complete")
197197
device.reload
198198
expect(device.active).to be true
@@ -212,7 +212,7 @@
212212
# rubocop:enable RSpec/AnyInstance
213213

214214
post :confirm, params: { device_id: device.id, otp: "1234" }
215-
expect(response).to redirect_to action: :index
215+
expect(response).to redirect_to my_security_path
216216
expect(flash[:notice]).to include I18n.t("two_factor_authentication.devices.registration_complete")
217217
device.reload
218218
expect(device.active).to be true
@@ -241,7 +241,7 @@
241241

242242
it "deletes it" do
243243
delete :destroy, params: { device_id: device.id }
244-
expect(response).to redirect_to action: :index
244+
expect(response).to redirect_to my_security_path
245245
expect(user.otp_devices.reload).to eq []
246246
end
247247
end
@@ -251,7 +251,7 @@
251251

252252
it "deletes it" do
253253
delete :destroy, params: { device_id: device.id }
254-
expect(response).to redirect_to action: :index
254+
expect(response).to redirect_to my_security_path
255255
expect(user.otp_devices.reload).to eq []
256256
end
257257
end

modules/two_factor_authentication/spec/features/admin_delete_two_factor_device_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828

2929
expect(page).to have_css(".mobile-otp--two-factor-device-row", count: 1)
3030

31-
find(".two-factor--delete-button").click
31+
find_test_selector("two-factor--delete-button").click
3232
dialog.confirm_flow_with(admin_password)
3333

34-
expect(page).to have_css(".generic-table--empty-row")
34+
expect(page).to have_css(".blankslate")
3535
expect(other_user.otp_devices.reload).to be_empty
3636
end
3737
end

modules/two_factor_authentication/spec/features/admin_edit_two_factor_devices_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@
2222
visit edit_user_path(admin, tab: :two_factor_authentication)
2323
expect(page).to have_css(".on-off-status.-disabled")
2424

25-
expect(page).to have_no_css(".generic-table--empty-row", wait: 1)
25+
expect(page).to have_no_css(".blankslate", wait: 1)
2626

2727
click_link "Two-factor authentication on your account page"
2828

29-
expect(page).to have_css(".generic-table--empty-row")
29+
expect(page).to have_css(".blankslate")
3030
expect(page).to have_current_path my_security_path
3131
end
3232

3333
it "allows 2FA device management of the user" do
3434
visit edit_user_path(other_user, tab: :two_factor_authentication)
3535

3636
# Visit empty index
37-
expect(page).to have_css(".generic-table--empty-row",
37+
expect(page).to have_css(".blankslate",
3838
text: I18n.t("two_factor_authentication.admin.no_devices_for_user"))
3939
expect(page).to have_css(".on-off-status.-disabled")
4040

4141
# Visit inline create
42-
find(".button", text: I18n.t("two_factor_authentication.admin.button_register_mobile_phone_for_user")).click
42+
find(".Button", text: I18n.t("two_factor_authentication.admin.button_register_mobile_phone_for_user")).click
4343

4444
SeleniumHubWaiter.wait
4545
# Try to save with invalid phone number
@@ -53,13 +53,13 @@
5353
fill_in "device_phone_number", with: "+49 123456789"
5454
click_button I18n.t(:button_continue)
5555

56-
expect(page).to have_css(".mobile-otp--two-factor-device-row td", text: "Mobile phone (bob) (+49 123456789)")
57-
expect(page).to have_css(".mobile-otp--two-factor-device-row td .icon-yes", count: 2)
56+
expect(page).to have_css(".mobile-otp--two-factor-device-row", text: "Mobile phone (bob) (+49 123456789)")
57+
expect(page).to have_css(".mobile-otp--two-factor-device-row .octicon-check", count: 2)
5858
expect(page).to have_css(".on-off-status.-enabled")
5959

6060
SeleniumHubWaiter.wait
6161
# Delete the one
62-
find(".two-factor--delete-button").click
62+
find_test_selector("two-factor--delete-button").click
6363
dialog.confirm_flow_with user_password, should_fail: false
6464

6565
expect(page).to have_css(".mobile-otp--two-factor-device-row", count: 0)
@@ -75,11 +75,11 @@
7575
visit edit_user_path(other_user, tab: :two_factor_authentication)
7676
expect(page).to have_css(".mobile-otp--two-factor-device-row", count: 2)
7777
expect(page).to have_css(".on-off-status.-enabled")
78-
find(".button", text: I18n.t("two_factor_authentication.admin.button_delete_all_devices")).click
78+
find(".Button", text: I18n.t("two_factor_authentication.admin.button_delete_all_devices")).click
7979

8080
page.driver.browser.switch_to.alert.accept
8181

82-
expect(page).to have_css(".generic-table--empty-row",
82+
expect(page).to have_css(".blankslate",
8383
text: I18n.t("two_factor_authentication.admin.no_devices_for_user"), wait: 20)
8484
expect(page).to have_css(".on-off-status.-disabled")
8585
end

modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
end
3030

3131
# Confirm with wrong password
32-
expect(page).to have_css("h2", text: I18n.t("two_factor_authentication.backup_codes.plural"))
32+
expect(page).to have_css(".Subhead-heading", text: I18n.t("two_factor_authentication.backup_codes.plural"))
3333
click_on I18n.t("two_factor_authentication.backup_codes.generate.title")
3434
dialog.confirm_flow_with "wrong_password", should_fail: true
3535

3636
# Confirm with correct password
37-
expect(page).to have_css("h2", text: I18n.t("two_factor_authentication.backup_codes.plural"))
37+
expect(page).to have_css(".Subhead-heading", text: I18n.t("two_factor_authentication.backup_codes.plural"))
3838
click_on I18n.t("two_factor_authentication.backup_codes.generate.title")
3939
dialog.confirm_flow_with user_password, should_fail: false
4040

modules/two_factor_authentication/spec/features/my_two_factor_devices_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
it "allows 2FA device management" do
2626
# Visit empty index
2727
visit my_security_path
28-
expect(page).to have_css(".generic-table--empty-row", text: I18n.t("two_factor_authentication.devices.not_existing"))
28+
expect(page).to have_css(".blankslate", text: I18n.t("two_factor_authentication.devices.not_existing"))
2929
expect(page).to have_css(".on-off-status.-disabled")
3030

3131
# Select SMS
@@ -69,8 +69,8 @@
6969
click_button I18n.t(:button_continue)
7070

7171
# Assert that it exists and is default
72-
expect(page).to have_css(".mobile-otp--two-factor-device-row td", text: "Mobile phone (bob) (+49 123456789)")
73-
expect(page).to have_css(".mobile-otp--two-factor-device-row td .icon-yes", count: 2)
72+
expect(page).to have_css(".mobile-otp--two-factor-device-row", text: "Mobile phone (bob) (+49 123456789)")
73+
expect(page).to have_css(".mobile-otp--two-factor-device-row .octicon-check", count: 2)
7474
expect(page).to have_css(".on-off-status.-enabled")
7575

7676
# Create another one as totp
@@ -104,46 +104,46 @@
104104

105105
expect(page).to have_css(".mobile-otp--two-factor-device-row", count: 2)
106106
rows = page.all(".mobile-otp--two-factor-device-row")
107-
expect(rows[0]).to have_css(".mobile-otp--two-factor-device-row td .icon-yes", count: 2)
108-
expect(rows[1]).to have_css(".mobile-otp--two-factor-device-row td", text: "custom identifier")
109-
expect(rows[1]).to have_css(".mobile-otp--two-factor-device-row td .icon-yes", count: 1)
107+
expect(rows[0]).to have_css(".octicon-check", count: 2)
108+
expect(rows[1]).to have_text("custom identifier")
109+
expect(rows[1]).to have_css(".octicon-check", count: 1)
110110

111111
device.reload
112112
expect(device.active).to be_truthy
113113
expect(device.default).to be_falsey
114114

115115
# Make the second one the default
116116
# Confirm the password wrongly
117-
find(".two-factor--mark-default-button").click
117+
page.find_test_selector("two-factor--make-default-button").click
118118
dialog.confirm_flow_with "wrong_password", should_fail: true
119119

120120
# Confirm again
121-
find(".two-factor--mark-default-button").click
121+
page.find_test_selector("two-factor--make-default-button").click
122122
dialog.confirm_flow_with user_password, should_fail: false
123123

124124
expect_and_dismiss_flash(message: "Successful update")
125125

126126
expect(page).to have_css(".mobile-otp--two-factor-device-row", count: 2)
127127
rows = page.all(".mobile-otp--two-factor-device-row")
128-
expect(rows[0]).to have_css(".mobile-otp--two-factor-device-row td .icon-yes", count: 1)
129-
expect(rows[1]).to have_css(".mobile-otp--two-factor-device-row td .icon-yes", count: 2)
128+
expect(rows[0]).to have_css(".octicon-check", count: 1)
129+
expect(rows[1]).to have_css(".octicon-check", count: 2)
130130

131131
device.reload
132132
expect(device.default).to be_truthy
133133

134134
# Delete the sms device
135-
rows[0].find(".two-factor--delete-button").click
135+
rows[0].find("[data-test-selector='two-factor--delete-button']").click
136136
dialog.confirm_flow_with user_password, should_fail: false
137137

138138
expect(page).to have_css(".mobile-otp--two-factor-device-row", count: 1)
139139
expect(page).to have_css(".on-off-status.-enabled")
140140
expect(user.otp_devices.count).to eq 1
141141

142142
# Delete the totp device
143-
find(".two-factor--delete-button").click
143+
page.find_test_selector("two-factor--delete-button").click
144144
dialog.confirm_flow_with user_password, should_fail: false
145145

146-
expect(page).to have_css(".generic-table--empty-row", text: I18n.t("two_factor_authentication.devices.not_existing"))
146+
expect(page).to have_css(".blankslate", text: I18n.t("two_factor_authentication.devices.not_existing"))
147147
expect(page).to have_css(".on-off-status.-disabled")
148148
expect(user.otp_devices.count).to eq 0
149149
end

modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def expect_no_autologin
6565
login_with_cookie
6666
visit my_security_path
6767

68-
find(".two-factor-authentication--remove-remember-cookie-link").click
68+
find_test_selector("two-factor-authentication--remove-remember-cookie-link").click
6969
expect_flash(message: I18n.t("two_factor_authentication.remember.cookie_removed"))
70-
expect(page).to have_no_css(".two-factor-authentication--remove-remember-cookie-link")
70+
expect(page).to have_no_test_selector("two-factor-authentication--remove-remember-cookie-link")
7171

7272
# Log out and in again
7373
visit "/logout"

0 commit comments

Comments
 (0)