-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* registered with frontend * removed backend handler for the page * correspoding tests for the backend handler removed * removed the link to the old handler * added access validator class for diagnostic test player * added url for the validator * added test class for diagnostic test player * removed redundant mainpage file * added service on frontend to call access validators defined on backend * removed 'downgradeComponent' page component * corrected constant.ts reference to diagnostic test player, added root page ts file * added diagnostic test player root template * removed excess imports and ngbootstrap form dtp module * added routes within the module * added the page to the app routing module * removed the module from webpack config * fix linter errors * fixed linter error * fix linter errorrs * added frontend tests for root component and validator service method * fixed url reference to validation service * fixed pytype check error * fixed merge conflict * fixed linter error * fixed MyPy type checks * removed unnecessary auth guard for diagnostics test player * implemented conditional rendering of the page, based on the feature flag value set in backend * backent test error fixed * added backend test for DiagnosticTestPlayerAccessValidationHandler * removed unused import in the module * correct the component name being tested by the karma test * added unit test for diagnostic test player root component * fixed linter errors * reverted unwanted changes * linter check fixed * delegated error handling * fix linter errors * modified unit tests to match the code changes in component * ran prettier for code formatting * refactored code to include a route guard (instead of error 404 logic inside component) * minor typo fix * reverted relave paths to to alias-based paths for consistency
- Loading branch information
1 parent
985e84d
commit a2eaa0c
Showing
18 changed files
with
405 additions
and
195 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
117 changes: 117 additions & 0 deletions
117
...emplates/pages/diagnostic-test-player-page/diagnostic-test-player-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,117 @@ | ||
// Copyright 2024 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 DiagnosticTestPlayerPageAuthGuard | ||
*/ | ||
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 {DiagnosticTestPlayerPageAuthGuard} from './diagnostic-test-player-page-auth.guard'; | ||
import {AccessValidationBackendApiService} from 'pages/oppia-root/routing/access-validation-backend-api.service'; | ||
|
||
class MockAccessValidationBackendApiService { | ||
validateAccessToDiagnosticTestPlayerPage() { | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
class MockRouter { | ||
navigate(commands: string[]): Promise<boolean> { | ||
return Promise.resolve(true); | ||
} | ||
} | ||
|
||
describe('DiagnosticTestPlayerPageAuthGuard', () => { | ||
let guard: DiagnosticTestPlayerPageAuthGuard; | ||
let accessValidationBackendApiService: AccessValidationBackendApiService; | ||
let router: Router; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule], | ||
providers: [ | ||
DiagnosticTestPlayerPageAuthGuard, | ||
{ | ||
provide: AccessValidationBackendApiService, | ||
useClass: MockAccessValidationBackendApiService, | ||
}, | ||
{provide: Router, useClass: MockRouter}, | ||
Location, | ||
], | ||
}); | ||
|
||
guard = TestBed.inject(DiagnosticTestPlayerPageAuthGuard); | ||
accessValidationBackendApiService = TestBed.inject( | ||
AccessValidationBackendApiService | ||
); | ||
router = TestBed.inject(Router); | ||
}); | ||
|
||
it('should allow access if validation succeeds', fakeAsync(() => { | ||
const validateAccessSpy = spyOn( | ||
accessValidationBackendApiService, | ||
'validateAccessToDiagnosticTestPlayerPage' | ||
).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 404 page if validation fails', fakeAsync(() => { | ||
spyOn( | ||
accessValidationBackendApiService, | ||
'validateAccessToDiagnosticTestPlayerPage' | ||
).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}/404`, | ||
]); | ||
})); | ||
}); |
64 changes: 64 additions & 0 deletions
64
core/templates/pages/diagnostic-test-player-page/diagnostic-test-player-page-auth.guard.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,64 @@ | ||
// Copyright 2024 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 Guard that redirects user to 404 error page | ||
* if the diagnostic test player is not accessible to user. | ||
*/ | ||
|
||
import {Location} from '@angular/common'; | ||
import {Injectable} from '@angular/core'; | ||
import { | ||
ActivatedRouteSnapshot, | ||
CanActivate, | ||
Router, | ||
RouterStateSnapshot, | ||
} from '@angular/router'; | ||
|
||
import {AppConstants} from 'app.constants'; | ||
import {AccessValidationBackendApiService} from 'pages/oppia-root/routing/access-validation-backend-api.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class DiagnosticTestPlayerPageAuthGuard implements CanActivate { | ||
constructor( | ||
private accessValidationBackendApiService: AccessValidationBackendApiService, | ||
private router: Router, | ||
private location: Location | ||
) {} | ||
|
||
async canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot | ||
): Promise<boolean> { | ||
return new Promise<boolean>(resolve => { | ||
this.accessValidationBackendApiService | ||
.validateAccessToDiagnosticTestPlayerPage() | ||
.then(() => { | ||
resolve(true); | ||
}) | ||
.catch(err => { | ||
this.router | ||
.navigate([ | ||
`${AppConstants.PAGES_REGISTERED_WITH_FRONTEND.ERROR.ROUTE}/404`, | ||
]) | ||
.then(() => { | ||
this.location.replaceState(state.url); | ||
resolve(false); | ||
}); | ||
}); | ||
}); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...mplates/pages/diagnostic-test-player-page/diagnostic-test-player-page-root.component.html
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,18 @@ | ||
<oppia-angular-root> | ||
<oppia-base-content> | ||
<navbar-breadcrumb> | ||
<ul class="nav navbar-nav oppia-navbar-breadcrumb"> | ||
<li> | ||
<span class="oppia-navbar-breadcrumb-separator"></span> | ||
<span>Diagnostic Test Player</span> | ||
</li> | ||
</ul> | ||
</navbar-breadcrumb> | ||
|
||
<content> | ||
<oppia-diagnostic-test-player></oppia-diagnostic-test-player> | ||
</content> | ||
|
||
<page-footer></page-footer> | ||
</oppia-base-content> | ||
</oppia-angular-root> |
Oops, something went wrong.