From decdb6896246599de5b37e4754f9198012633904 Mon Sep 17 00:00:00 2001 From: gbochora Date: Mon, 26 Sep 2022 10:30:14 -0400 Subject: [PATCH 1/4] Add lhs refresh on follow/unfollow --- webapp/src/components/backstage/lhs_run_dot_menu.tsx | 3 +++ .../backstage/playbook_runs/playbook_run/rhs_info_overview.tsx | 2 ++ 2 files changed, 5 insertions(+) diff --git a/webapp/src/components/backstage/lhs_run_dot_menu.tsx b/webapp/src/components/backstage/lhs_run_dot_menu.tsx index fba4f01203..8999ffc466 100644 --- a/webapp/src/components/backstage/lhs_run_dot_menu.tsx +++ b/webapp/src/components/backstage/lhs_run_dot_menu.tsx @@ -18,6 +18,7 @@ import {useLeaveRun} from './playbook_runs/playbook_run/context_menu'; import {useFollowers} from './playbook_runs/playbook_run/playbook_run'; import {CopyRunLinkMenuItem, FavoriteRunMenuItem, FollowRunMenuItem, LeaveRunMenuItem} from './playbook_runs/playbook_run/controls'; import {DotMenuButtonStyled} from './shared'; +import { useLHSRefresh } from './lhs_navigation'; interface Props { playbookRunId: string; @@ -33,6 +34,7 @@ export const LHSRunDotMenu = ({playbookRunId, isFavorite, ownerUserId, participa const {add: addToast} = useToaster(); const updateRun = useUpdateRun(playbookRunId); const currentUser = useSelector(getCurrentUser); + const refreshLHS = useLHSRefresh(); const followState = useFollowers(followerIDs); const {isFollowing, followers, setFollowers} = followState; @@ -50,6 +52,7 @@ export const LHSRunDotMenu = ({playbookRunId, isFavorite, ownerUserId, participa .then(() => { const newFollowers = isFollowing ? followers.filter((userId) => userId !== currentUser.id) : [...followers, currentUser.id]; setFollowers(newFollowers); + refreshLHS(); }) .catch(() => { addToast(formatMessage({defaultMessage: 'It was not possible to {isFollowing, select, true {unfollow} other {follow}} the run'}, {isFollowing}), ToastType.Failure); diff --git a/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx b/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx index 4130e706ed..602116250d 100644 --- a/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx +++ b/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx @@ -47,6 +47,7 @@ export const useFollow = (runID: string, followState: FollowState) => { const addToast = useToaster().add; const {isFollowing, followers, setFollowers} = followState; const currentUser = useSelector(getCurrentUser); + const refreshLHS = useLHSRefresh(); const toggleFollow = () => { const action = isFollowing ? unfollowPlaybookRun : followPlaybookRun; @@ -54,6 +55,7 @@ export const useFollow = (runID: string, followState: FollowState) => { .then(() => { const newFollowers = isFollowing ? followers.filter((userId) => userId !== currentUser.id) : [...followers, currentUser.id]; setFollowers(newFollowers); + refreshLHS(); }) .catch(() => { addToast(formatMessage({defaultMessage: 'It was not possible to {isFollowing, select, true {unfollow} other {follow}} the run'}, {isFollowing}), ToastType.Failure); From cf7d265b057c5eb7c4c5d6b08e1a6b9aae76f2df Mon Sep 17 00:00:00 2001 From: gbochora Date: Mon, 26 Sep 2022 10:31:18 -0400 Subject: [PATCH 2/4] Fix style issue --- webapp/src/components/backstage/lhs_run_dot_menu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/components/backstage/lhs_run_dot_menu.tsx b/webapp/src/components/backstage/lhs_run_dot_menu.tsx index 8999ffc466..88a7d8d452 100644 --- a/webapp/src/components/backstage/lhs_run_dot_menu.tsx +++ b/webapp/src/components/backstage/lhs_run_dot_menu.tsx @@ -18,7 +18,7 @@ import {useLeaveRun} from './playbook_runs/playbook_run/context_menu'; import {useFollowers} from './playbook_runs/playbook_run/playbook_run'; import {CopyRunLinkMenuItem, FavoriteRunMenuItem, FollowRunMenuItem, LeaveRunMenuItem} from './playbook_runs/playbook_run/controls'; import {DotMenuButtonStyled} from './shared'; -import { useLHSRefresh } from './lhs_navigation'; +import {useLHSRefresh} from './lhs_navigation'; interface Props { playbookRunId: string; From e5e53d72738cf518732468488b25a589ce4468a1 Mon Sep 17 00:00:00 2001 From: gbochora Date: Mon, 26 Sep 2022 11:24:38 -0400 Subject: [PATCH 3/4] Add e2e tests --- tests-e2e/cypress/integration/lhs_spec.js | 20 +++++++++++++++++++ .../playbook_run/rhs_info_overview.tsx | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests-e2e/cypress/integration/lhs_spec.js b/tests-e2e/cypress/integration/lhs_spec.js index 677010723a..997f5d21d2 100644 --- a/tests-e2e/cypress/integration/lhs_spec.js +++ b/tests-e2e/cypress/integration/lhs_spec.js @@ -112,6 +112,26 @@ describe('lhs', () => { }); }); + it('lhs refresh on follow/unfollow', () => { + cy.apiLogin(testViewerUser).then(() => { + // # Visit the playbook run + cy.visit(`/playbooks/runs/${playbookRun.id}`); + + // # Follow the run + cy.findByTestId('rdp-rhs-follow-button').click(); + cy.wait(3000); + + // * Verify that the run was added to the lhs + cy.findByTestId('Runs').findByTestId(playbookRun.name).should('exist'); + + // # Click on unfollow menu item + getRunDropdownItemByText('Runs', playbookRun.name, 'Unfollow').click().then(() => { + // * Verify that the run is removed lhs + cy.findByTestId('Runs').findByTestId(playbookRun.name).should('not.exist'); + }); + }); + }); + it('leave run', () => { // # Add viewer user to the channel cy.apiAddUserToChannel(playbookRun.channel_id, testViewerUser.id); diff --git a/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx b/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx index 602116250d..4e68d2828b 100644 --- a/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx +++ b/webapp/src/components/backstage/playbook_runs/playbook_run/rhs_info_overview.tsx @@ -72,7 +72,10 @@ export const useFollow = (runID: string, followState: FollowState) => { } return ( - + {formatMessage({defaultMessage: 'Follow'})} ); From f00172f009946dd8402217465f88f68f85bef839 Mon Sep 17 00:00:00 2001 From: gbochora Date: Mon, 26 Sep 2022 16:35:38 -0400 Subject: [PATCH 4/4] Fix e2e test --- tests-e2e/cypress/integration/lhs_spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests-e2e/cypress/integration/lhs_spec.js b/tests-e2e/cypress/integration/lhs_spec.js index 997f5d21d2..8d44b9d3e4 100644 --- a/tests-e2e/cypress/integration/lhs_spec.js +++ b/tests-e2e/cypress/integration/lhs_spec.js @@ -119,6 +119,8 @@ describe('lhs', () => { // # Follow the run cy.findByTestId('rdp-rhs-follow-button').click(); + + // # Wait to lhs refresh cy.wait(3000); // * Verify that the run was added to the lhs @@ -126,6 +128,9 @@ describe('lhs', () => { // # Click on unfollow menu item getRunDropdownItemByText('Runs', playbookRun.name, 'Unfollow').click().then(() => { + // # Wait to lhs refresh + cy.wait(3000); + // * Verify that the run is removed lhs cy.findByTestId('Runs').findByTestId(playbookRun.name).should('not.exist'); });