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.
Frontend Unit Tests(3): Cover multiple component files (oppia#13303)
* intial commit * minor fix
- Loading branch information
Showing
11 changed files
with
1,487 additions
and
10 deletions.
There are no files selected for viewing
411 changes: 411 additions & 0 deletions
411
...nsions/interactions/GraphInput/directives/oppia-interactive-graph-input.component.spec.ts
Large diffs are not rendered by default.
Oops, something went wrong.
136 changes: 136 additions & 0 deletions
136
extensions/interactions/GraphInput/directives/oppia-response-graph-input.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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2021 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 Unti tests for the GraphInput response. | ||
*/ | ||
|
||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { HtmlEscaperService } from 'services/html-escaper.service'; | ||
import { GraphDetailService } from './graph-detail.service'; | ||
import { ResponseGraphInput } from './oppia-response-graph-input.component'; | ||
|
||
describe('ResponseGraphInput', () => { | ||
let component: ResponseGraphInput; | ||
let fixture: ComponentFixture<ResponseGraphInput>; | ||
|
||
let mockHtmlEscaperService = { | ||
escapedJsonToObj: function(answer) { | ||
return JSON.parse(answer); | ||
} | ||
}; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ResponseGraphInput], | ||
providers: [GraphDetailService, | ||
{ | ||
provide: HtmlEscaperService, | ||
useValue: mockHtmlEscaperService | ||
}] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ResponseGraphInput); | ||
component = fixture.componentInstance; | ||
|
||
component.answer = '{' + | ||
' "isWeighted": false,' + | ||
' "edges": [' + | ||
' {' + | ||
' "src": 0,' + | ||
' "dst": 1,' + | ||
' "weight": 1' + | ||
' },' + | ||
' {' + | ||
' "src": 1,' + | ||
' "dst": 2,' + | ||
' "weight": 1' + | ||
' }' + | ||
' ],' + | ||
' "isDirected": false,' + | ||
' "vertices": [' + | ||
' {' + | ||
' "x": 150,' + | ||
' "y": 50,' + | ||
' "label": ""' + | ||
' },' + | ||
' {' + | ||
' "x": 200,' + | ||
' "y": 50,' + | ||
' "label": ""' + | ||
' },' + | ||
' {' + | ||
' "x": 150,' + | ||
' "y": 100,' + | ||
' "label": ""' + | ||
' }' + | ||
' ],' + | ||
' "isLabeled": false' + | ||
'}'; | ||
|
||
component.ngOnInit(); | ||
}); | ||
|
||
it('should create', () => { | ||
component.ngOnInit(); | ||
|
||
expect(component.graph).toEqual({ | ||
isWeighted: false, | ||
edges: [ | ||
{ | ||
src: 0, | ||
dst: 1, | ||
weight: 1 | ||
}, | ||
{ | ||
src: 1, | ||
dst: 2, | ||
weight: 1 | ||
} | ||
], | ||
isDirected: false, | ||
vertices: [ | ||
{ | ||
x: 150, | ||
y: 50, | ||
label: '' | ||
}, | ||
{ | ||
x: 200, | ||
y: 50, | ||
label: '' | ||
}, | ||
{ | ||
x: 150, | ||
y: 100, | ||
label: '' | ||
} | ||
], | ||
isLabeled: false | ||
}); | ||
expect(component.VERTEX_RADIUS).toBe(6); | ||
expect(component.EDGE_WIDTH).toBe(3); | ||
}); | ||
|
||
it('should return directed edge arrow points when called', () => { | ||
expect(component.getDirectedEdgeArrowPoints(0)) | ||
.toBe('196,50 186,45 186,55'); | ||
}); | ||
|
||
it('should return edge center when called', () => { | ||
expect(component.getEdgeCenter(0)).toEqual({ x: 175, y: 50 }); | ||
}); | ||
}); |
134 changes: 134 additions & 0 deletions
134
...ons/interactions/GraphInput/directives/oppia-short-response-graph-input.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 |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2021 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 Unit tests for the GraphInput short response. | ||
*/ | ||
|
||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { HtmlEscaperService } from 'services/html-escaper.service'; | ||
import { ShortResponseGraphInput } from './oppia-short-response-graph-input.component'; | ||
|
||
describe('ShortResponseGraphInput', () => { | ||
let component: ShortResponseGraphInput; | ||
let fixture: ComponentFixture<ShortResponseGraphInput>; | ||
|
||
let mockHtmlEscaperService = { | ||
escapedJsonToObj: function(answer) { | ||
return JSON.parse(answer); | ||
} | ||
}; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateModule.forRoot({ | ||
useDefaultLang: true, | ||
isolate: false, | ||
extend: false, | ||
defaultLanguage: 'en' | ||
}) | ||
], | ||
declarations: [ShortResponseGraphInput], | ||
providers: [ | ||
{ | ||
provide: HtmlEscaperService, | ||
useValue: mockHtmlEscaperService | ||
} | ||
], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ShortResponseGraphInput); | ||
component = fixture.componentInstance; | ||
|
||
component.answer = '{' + | ||
' "isWeighted": false,' + | ||
' "edges": [' + | ||
' {' + | ||
' "src": 0,' + | ||
' "dst": 1,' + | ||
' "weight": 1' + | ||
' },' + | ||
' {' + | ||
' "src": 1,' + | ||
' "dst": 2,' + | ||
' "weight": 1' + | ||
' }' + | ||
' ],' + | ||
' "isDirected": false,' + | ||
' "vertices": [' + | ||
' {' + | ||
' "x": 150,' + | ||
' "y": 50,' + | ||
' "label": ""' + | ||
' },' + | ||
' {' + | ||
' "x": 200,' + | ||
' "y": 50,' + | ||
' "label": ""' + | ||
' },' + | ||
' {' + | ||
' "x": 150,' + | ||
' "y": 100,' + | ||
' "label": ""' + | ||
' }' + | ||
' ],' + | ||
' "isLabeled": false' + | ||
'}'; | ||
}); | ||
|
||
it('should create', () => { | ||
component.ngOnInit(); | ||
|
||
expect(component.graph).toEqual({ | ||
isWeighted: false, | ||
edges: [ | ||
{ | ||
src: 0, | ||
dst: 1, | ||
weight: 1 | ||
}, | ||
{ | ||
src: 1, | ||
dst: 2, | ||
weight: 1 | ||
} | ||
], | ||
isDirected: false, | ||
vertices: [ | ||
{ | ||
x: 150, | ||
y: 50, | ||
label: '' | ||
}, | ||
{ | ||
x: 200, | ||
y: 50, | ||
label: '' | ||
}, | ||
{ | ||
x: 150, | ||
y: 100, | ||
label: '' | ||
} | ||
], | ||
isLabeled: false | ||
}); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
...nteractions/ImageClickInput/directives/oppia-response-image-click-input.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2021 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 Directive for the ImageClickInput response. | ||
*/ | ||
|
||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { HtmlEscaperService } from 'services/html-escaper.service'; | ||
import { ResponseImageClickInput } from './oppia-response-image-click-input.component'; | ||
|
||
describe('ResponseImageClickInput', () => { | ||
let component: ResponseImageClickInput; | ||
let fixture: ComponentFixture<ResponseImageClickInput>; | ||
let mockHtmlEscaperService = { | ||
escapedJsonToObj: function(answer) { | ||
return JSON.parse(answer); | ||
} | ||
}; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ResponseImageClickInput], | ||
providers: [ | ||
{ | ||
provide: HtmlEscaperService, | ||
useValue: mockHtmlEscaperService | ||
} | ||
] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ResponseImageClickInput); | ||
component = fixture.componentInstance; | ||
|
||
component.answer = '{' + | ||
'"clickPosition": [' + | ||
' 0.40913347791798105, ' + | ||
' 0.39177101967799643 ' + | ||
'],' + | ||
'"clickedRegions": ["Region1"]' + | ||
'}'; | ||
}); | ||
|
||
it('should initialise component when user submits answer', () => { | ||
component.ngOnInit(); | ||
|
||
expect(component.clickRegionLabel).toBe('(Clicks on \'Region1\')'); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
...tions/ImageClickInput/directives/oppia-short-response-image-click-input.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2021 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 Directive for the ImageClickInput response. | ||
*/ | ||
|
||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { HtmlEscaperService } from 'services/html-escaper.service'; | ||
import { ShortResponseImageClickInput } from './oppia-short-response-image-click-input.component'; | ||
|
||
describe('ShortResponseImageClickInput', () => { | ||
let component: ShortResponseImageClickInput; | ||
let fixture: ComponentFixture<ShortResponseImageClickInput>; | ||
let mockHtmlEscaperService = { | ||
escapedJsonToObj: function(answer) { | ||
return JSON.parse(answer); | ||
} | ||
}; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ShortResponseImageClickInput], | ||
providers: [ | ||
{ | ||
provide: HtmlEscaperService, | ||
useValue: mockHtmlEscaperService | ||
} | ||
] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ShortResponseImageClickInput); | ||
component = fixture.componentInstance; | ||
|
||
component.answer = '{' + | ||
'"clickPosition": [' + | ||
' 0.40913347791798105, ' + | ||
' 0.39177101967799643 ' + | ||
'],' + | ||
'"clickedRegions": ["Region1"]' + | ||
'}'; | ||
}); | ||
|
||
it('should initialise component when user submits answer', () => { | ||
component.ngOnInit(); | ||
|
||
expect(component.clickRegionLabel).toBe('(Clicks on \'Region1\')'); | ||
}); | ||
}); |
Oops, something went wrong.