forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix part of oppia#19435: Learner group editor page migration (oppia#1…
…9761) * Fix part of oppia#19435: Migrate learner group editor page * complete migration * remove browser module * complete migration * fix linter * fix linter * added frontend test * add test * fix linter * fix test * fix linter * fix linter * fix root * fix linter * update comment * removed use of context service and fixed typo * fix test * fix test * fix test * fix test * fix test * remove max-len flag * use paramMap instead of windowRef * avoid using hard coded string * add script for passive event
- Loading branch information
Showing
22 changed files
with
472 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...templates/pages/learner-group-pages/edit-group/edit-learner-group-page-auth.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2023 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Tests for EditLearnerGroupPageAuthGuard | ||
*/ | ||
import { Location } from '@angular/common'; | ||
import { TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { AppConstants } from 'app.constants'; | ||
import { EditLearnerGroupPageAuthGuard } from './edit-learner-group-page-auth.guard'; | ||
import { AccessValidationBackendApiService } from 'pages/oppia-root/routing/access-validation-backend-api.service'; | ||
|
||
|
||
class MockAccessValidationBackendApiService { | ||
validateAccessToLearnerGroupEditorPage(learnerGroupId: string) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
class MockRouter { | ||
navigate(commands: string[]): Promise<boolean> { | ||
return Promise.resolve(true); | ||
} | ||
} | ||
|
||
describe('EditLearnerGroupPageAuthGuard', () => { | ||
let guard: EditLearnerGroupPageAuthGuard; | ||
let accessValidationBackendApiService: AccessValidationBackendApiService; | ||
let router: Router; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule], | ||
providers: [ | ||
EditLearnerGroupPageAuthGuard, | ||
{ provide: AccessValidationBackendApiService, | ||
useClass: MockAccessValidationBackendApiService }, | ||
{ provide: Router, useClass: MockRouter }, | ||
Location, | ||
], | ||
}); | ||
|
||
guard = TestBed.inject(EditLearnerGroupPageAuthGuard); | ||
accessValidationBackendApiService = TestBed.inject( | ||
AccessValidationBackendApiService | ||
); | ||
router = TestBed.inject(Router); | ||
}); | ||
|
||
it('should allow access if validation succeeds', fakeAsync(() => { | ||
const validateAccessSpy = spyOn( | ||
accessValidationBackendApiService, | ||
'validateAccessToLearnerGroupEditorPage') | ||
.and.returnValue(Promise.resolve()); | ||
const navigateSpy = spyOn(router, 'navigate') | ||
.and.returnValue(Promise.resolve(true)); | ||
|
||
let canActivateResult: boolean | null = null; | ||
|
||
guard.canActivate(new ActivatedRouteSnapshot(), {} as RouterStateSnapshot) | ||
.then((result) => { | ||
canActivateResult = result; | ||
}); | ||
|
||
tick(); | ||
|
||
expect(canActivateResult).toBeTrue(); | ||
expect(validateAccessSpy).toHaveBeenCalled(); | ||
expect(navigateSpy).not.toHaveBeenCalled(); | ||
})); | ||
|
||
it('should redirect to 401 page if validation fails', fakeAsync(() => { | ||
spyOn( | ||
accessValidationBackendApiService, | ||
'validateAccessToLearnerGroupEditorPage') | ||
.and.returnValue(Promise.reject()); | ||
const navigateSpy = spyOn(router, 'navigate') | ||
.and.returnValue(Promise.resolve(true)); | ||
|
||
let canActivateResult: boolean | null = null; | ||
|
||
guard.canActivate(new ActivatedRouteSnapshot(), {} as RouterStateSnapshot) | ||
.then((result) => { | ||
canActivateResult = result; | ||
}); | ||
|
||
tick(); | ||
|
||
expect(canActivateResult).toBeFalse(); | ||
expect(navigateSpy).toHaveBeenCalledWith( | ||
[`${AppConstants.PAGES_REGISTERED_WITH_FRONTEND.ERROR.ROUTE}/401`] | ||
); | ||
})); | ||
}); |
Oops, something went wrong.