Skip to content

Commit

Permalink
redirection should not open modal again
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashpatil78 committed Jun 20, 2024
1 parent d6ad679 commit 125278f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/app/core/guards/opt-in.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('OptInGuard', () => {
});

describe('canActivate():', () => {
it('should return true if the current route includes "my_expenses;redirected_from_add_expense=true" and the next route does not include "add_edit" and canShowOptIn is false', (done) => {
const currentRoute = 'my_expenses;redirected_from_add_expense=true';
it('should return true if the current route includes "my_expenses" and the next route does not include "add_edit" and canShowOptIn is false', (done) => {
const currentRoute = 'my_expenses';
const nextRoute = 'my_dashboard';
const canShowOptIn = false;
const canShowOptInModal = true;
Expand All @@ -60,8 +60,8 @@ describe('OptInGuard', () => {
});
});

it('should return true if the current route includes "my_expenses;redirected_from_add_expense=true" and the next route does not include "add_edit" and canShowOptIn is true', (done) => {
const currentRoute = 'my_expenses;redirected_from_add_expense=true';
it('should return true if the current route includes "my_expenses" and the next route does not include "add_edit" and canShowOptIn is true', (done) => {
const currentRoute = 'my_expenses';
const nextRoute = 'my_dashboard';
const canShowOptIn = true;
const canShowOptInModal = true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/guards/opt-in.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class OptInGuard implements CanActivate {
const currentRoute = this.router.routerState.snapshot.url;
const nextRoute = state.url;

if (currentRoute.includes('my_expenses;redirected_from_add_expense=true') && !nextRoute.includes('add_edit')) {
if (currentRoute.includes('my_expenses') && !nextRoute.includes('add_edit')) {
const canShowOptInPostExpenseCreation = this.utilityService.canShowOptInAfterExpenseCreation();

if (!canShowOptInPostExpenseCreation) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ export class AddEditExpensePage implements OnInit {
this.navController.back();
} else {
if (this.mode === 'add') {
this.router.navigate(['/', 'enterprise', 'my_expenses', { redirected_from_add_expense: true }]);
this.router.navigate(['/', 'enterprise', 'my_expenses'], {
queryParams: { redirected_from_add_expense: true },
});
} else {
this.router.navigate(['/', 'enterprise', 'my_expenses']);
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/fyle/my-expenses/my-expenses.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe('MyExpensesPage', () => {
params: {
navigateBack: false,
},
queryParams: {},
},
};
const transactionOutboxServiceSpy = jasmine.createSpyObj('TransactionOutboxService', [
Expand Down Expand Up @@ -539,7 +540,7 @@ describe('MyExpensesPage', () => {
utilityService.canShowOptInModal.and.returnValue(of(true));
spyOn(component, 'setModalDelay');
spyOn(component, 'setNavigationSubscription');
activatedRoute.snapshot.params.redirected_from_add_expense = 'true';
activatedRoute.snapshot.queryParams.redirected_from_add_expense = 'true';
component.simpleSearchInput = getElementRef(fixture, '.my-expenses--simple-search-input');
inputElement = component.simpleSearchInput.nativeElement;
});
Expand Down Expand Up @@ -3286,7 +3287,7 @@ describe('MyExpensesPage', () => {
spyOn(component, 'showPromoteOptInModal');
const navigationEvent = new NavigationStart(1, 'my_expenses');
utilityService.canShowOptInModal.and.returnValue(of(true));
activatedRoute.snapshot.params.redirected_from_add_expense = 'true';
activatedRoute.snapshot.queryParams.redirected_from_add_expense = 'true';
utilityService.canShowOptInAfterExpenseCreation.and.returnValue(true);
Object.defineProperty(router, 'events', { value: of(navigationEvent) });

Expand Down
5 changes: 3 additions & 2 deletions src/app/fyle/my-expenses/my-expenses.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ export class MyExpensesPage implements OnInit {
key: 'OPT_IN_POPUP_SHOWN_COUNT',
};

const isRedirectedFromAddExpense = this.activatedRoute.snapshot.params.redirected_from_add_expense as string;
const isRedirectedFromAddExpense = this.activatedRoute.snapshot.queryParams.redirected_from_add_expense as string;

this.utilityService.canShowOptInModal(optInModalPostExpenseCreationFeatureConfig).subscribe((canShowOptInModal) => {
if (canShowOptInModal && isRedirectedFromAddExpense) {
Expand Down Expand Up @@ -804,7 +804,8 @@ export class MyExpensesPage implements OnInit {
key: 'OPT_IN_POPUP_SHOWN_COUNT',
};

const isRedirectedFromAddExpense = this.activatedRoute.snapshot.params.redirected_from_add_expense as string;
const isRedirectedFromAddExpense = this.activatedRoute.snapshot.queryParams
.redirected_from_add_expense as string;

this.utilityService.canShowOptInModal(optInModalPostExpenseCreationFeatureConfig).subscribe((isAttemptLeft) => {
const canShowOptInModal = this.utilityService.canShowOptInAfterExpenseCreation();
Expand Down

0 comments on commit 125278f

Please sign in to comment.