1010 See the License for the specific language governing permissions and
1111 limitations under the License.
1212 */
13+ import { SimpleChange , SimpleChanges } from '@angular/core' ;
1314import { ComponentFixture , TestBed } from '@angular/core/testing' ;
15+ import { ChartPoint , ChartPoints } from '../model/chart-points' ;
1416
1517import { ScLineChartComponent } from './sc-line-chart.component' ;
1618
17- describe ( 'NgxSimpleChartsComponent ' , ( ) => {
19+ describe ( 'ScLineChartComponent ' , ( ) => {
1820 let component : ScLineChartComponent ;
1921 let fixture : ComponentFixture < ScLineChartComponent > ;
22+ const chartPoints : ChartPoints = { name : 'myChartPoints' , xScaleHeight : 250 , yScaleWidth : 250 ,
23+ chartPointList : [ ] } ;
24+ const myChartPointList : ChartPoint [ ] = [ { x : new Date ( 2021 , 0 , 1 ) , y : 50 } , { x : new Date ( 2021 , 0 , 2 ) , y : 75 } ] ;
25+
2026 beforeEach ( async ( ) => {
2127 await TestBed . configureTestingModule ( {
2228 declarations : [ ScLineChartComponent ]
2329 } )
2430 . compileComponents ( ) ;
2531 } ) ;
32+
2633 beforeEach ( ( ) => {
2734 fixture = TestBed . createComponent ( ScLineChartComponent ) ;
28- component = fixture . componentInstance ;
35+ component = fixture . componentInstance ;
2936 fixture . detectChanges ( ) ;
3037 } ) ;
38+
3139 it ( 'should create' , ( ) => {
3240 expect ( component ) . toBeTruthy ( ) ;
3341 } ) ;
42+
43+ it ( 'should create a chart' , ( ) => {
44+ const newChartPoints = JSON . parse ( JSON . stringify ( chartPoints ) ) ;
45+ newChartPoints . chartPointList . push ( ...JSON . parse ( JSON . stringify ( myChartPointList ) ) ) ;
46+ component . chartPoints = [ newChartPoints ] ;
47+ component . ngAfterViewInit ( ) ;
48+ fixture . detectChanges ( ) ;
49+ const myElement = component . d3Svg . selectAll ( 'path' ) . nodes ( )
50+ . filter ( myNode => ( myNode as Element ) . classList . contains ( 'line' ) ) [ 0 ] as Element ;
51+ expect ( myElement . getAttribute ( 'd' ) ?. split ( ',' ) . length ) . toBeGreaterThan ( 1 ) ;
52+ } ) ;
53+
54+ it ( 'should update a chart' , ( ) => {
55+ const newChartPoints = JSON . parse ( JSON . stringify ( chartPoints ) ) ;
56+ newChartPoints . chartPointList . push ( ...JSON . parse ( JSON . stringify ( myChartPointList ) ) ) ;
57+ newChartPoints . chartPointList . push ( { x : new Date ( 2021 , 0 , 3 ) , y : 100 } ) ;
58+ const myChanges : SimpleChanges = { chartPoints : { currentValue : [ newChartPoints ] , firstChange : false ,
59+ previousValue : [ chartPoints ] , isFirstChange : ( ) => false } as SimpleChange } ;
60+ component . chartPoints = [ newChartPoints ] ;
61+ component . ngOnChanges ( myChanges ) ;
62+ fixture . detectChanges ( ) ;
63+ const myElement = component . d3Svg . selectAll ( 'path' ) . nodes ( )
64+ . filter ( myNode => ( myNode as Element ) . classList . contains ( 'line' ) ) [ 0 ] as Element ;
65+ expect ( myElement . getAttribute ( 'd' ) ?. split ( ',' ) . length ) . toBeGreaterThan ( 2 ) ;
66+ } ) ;
3467} ) ;
0 commit comments