-
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.
Showing
11 changed files
with
237 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ testem.log | |
Thumbs.db | ||
package-lock.json | ||
.editorconfig | ||
.scannerwork |
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
78 changes: 75 additions & 3 deletions
78
blogs-analyzer-ui/src/app/quality-check/quality-check.component.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 |
---|---|---|
@@ -1,28 +1,100 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { QualityCheckComponent } from './quality-check.component'; | ||
import { RouterTestingModule } from "@angular/router/testing"; | ||
import { HttpClientModule } from "@angular/common/http"; | ||
import { HeaderComponent } from "../dashboard/components/header/header.component"; | ||
import { MatIconModule } from "@angular/material/icon"; | ||
import { MatCardModule } from "@angular/material/card"; | ||
import { BlogService } from "../services/blog.service"; | ||
import { of, throwError } from 'rxjs'; | ||
|
||
describe('QualityCheckComponent', () => { | ||
let component: QualityCheckComponent; | ||
let fixture: ComponentFixture<QualityCheckComponent>; | ||
let blogService: BlogService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [QualityCheckComponent, HeaderComponent], | ||
imports: [RouterTestingModule, HttpClientModule, MatIconModule, MatCardModule] | ||
|
||
imports: [RouterTestingModule, HttpClientModule, MatIconModule, MatCardModule], | ||
providers: [BlogService] | ||
}); | ||
fixture = TestBed.createComponent(QualityCheckComponent); | ||
component = fixture.componentInstance; | ||
blogService = TestBed.inject(BlogService); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should call location.back on goBack', () => { | ||
const locationSpy = spyOn(component['location'], 'back'); | ||
component.goBack(); | ||
expect(locationSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call blogService.getBlogQuality with correct prompt on checkQuality', () => { | ||
component.postData = 'Sample blog content'; | ||
const expectedPrompt = `Review blog with the following content: Sample blog content | ||
Parameters include fields like: | ||
- Duplicate Content | ||
- Spelling Mistakes | ||
- Grammatical Errors | ||
- Overall SEO Report | ||
- Accuracy | ||
- Depth and Completeness | ||
- Clarity and Conciseness | ||
- Logical Flow | ||
- Technical Accuracy | ||
- Targeted Audience | ||
- Structure and Formatting | ||
- Code Examples and Illustrations | ||
- Links and References | ||
- Overall Feedback | ||
Display result in tabular view for respective percentages and accurate feedback;`; | ||
|
||
spyOn(blogService, 'getBlogQuality').and.returnValue(of('')); | ||
component.checkQuality(); | ||
expect(blogService.getBlogQuality).toHaveBeenCalledWith(expectedPrompt); | ||
}); | ||
|
||
it('should parse a valid response correctly', () => { | ||
const response = ` | ||
| Label | Percentage | Comment | | ||
| Duplicate Content | 10% | Some duplicate content | | ||
| Spelling Mistakes | 5% | Some spelling mistakes |`; | ||
const expectedResults = [ | ||
{ originalLabel: 'Duplicate Content', oppositeLabel: 'Original Content', value: 10, comment: 'Some duplicate content' }, | ||
{ originalLabel: 'Spelling Mistakes', oppositeLabel: 'Correct Spelling', value: 5, comment: 'Some spelling mistakes' } | ||
]; | ||
const results = component.parseResponse(response); | ||
expect(results).toEqual(expectedResults); | ||
}); | ||
|
||
it('should handle an empty response', () => { | ||
const response = ''; | ||
const results = component.parseResponse(response); | ||
expect(results).toEqual([]); | ||
}); | ||
|
||
it('should handle a response with partially valid rows', () => { | ||
const response = ` | ||
| Label | Percentage | Comment | | ||
| Duplicate Content | 10% | Some duplicate content | | ||
| Invalid Row`; | ||
const expectedResults = [ | ||
{ originalLabel: 'Duplicate Content', oppositeLabel: 'Original Content', value: 10, comment: 'Some duplicate content' } | ||
]; | ||
const results = component.parseResponse(response); | ||
expect(results).toEqual(expectedResults); | ||
}); | ||
|
||
it('should handle blogService.getBlogQuality error', () => { | ||
spyOn(blogService, 'getBlogQuality').and.returnValue(throwError('Error occurred')); | ||
const consoleSpy = spyOn(console, 'error'); | ||
component.checkQuality(); | ||
expect(consoleSpy).toHaveBeenCalledWith('Error:', 'Error occurred'); | ||
}); | ||
}); |
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
Oops, something went wrong.