1616import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
1717import { WorkflowsComponent } from './workflows.component' ;
1818import { provideMockStore } from '@ngrx/store/testing' ;
19- import { ProjectModelFactory } from '../../models/project.model' ;
19+ import { ProjectModelFactory , WorkflowIdentityModelFactory } from '../../models/project.model' ;
2020import { WorkflowModelFactory } from '../../models/workflow.model' ;
21+ import { RouterTestingModule } from '@angular/router/testing' ;
22+ import { Router , Routes } from '@angular/router' ;
2123
2224describe ( 'WorkflowsComponent' , ( ) => {
2325 let fixture : ComponentFixture < WorkflowsComponent > ;
2426 let underTest : WorkflowsComponent ;
27+ let router : Router ;
28+
29+ const routes = [ { path : 'workflows/show/:id' , component : { } } ] as Routes ;
2530
2631 const initialAppState = {
2732 workflows : {
@@ -42,7 +47,9 @@ describe('WorkflowsComponent', () => {
4247 TestBed . configureTestingModule ( {
4348 providers : [ provideMockStore ( { initialState : initialAppState } ) ] ,
4449 declarations : [ WorkflowsComponent ] ,
50+ imports : [ RouterTestingModule . withRoutes ( routes ) ] ,
4551 } ) . compileComponents ( ) ;
52+ router = TestBed . inject ( Router ) ;
4653 } ) ,
4754 ) ;
4855
@@ -65,4 +72,106 @@ describe('WorkflowsComponent', () => {
6572 } ) ;
6673 } ) ,
6774 ) ;
75+
76+ describe ( 'isWorkflowHighlighted' , ( ) => {
77+ it (
78+ 'should return true when url contains input id' ,
79+ waitForAsync ( ( ) => {
80+ const idMatching = 555 ;
81+ router . navigate ( [ 'workflows/show' , idMatching ] ) . then ( ( ) => {
82+ expect ( underTest . isWorkflowHighlighted ( idMatching ) ) . toBeTruthy ( ) ;
83+ } ) ;
84+ } ) ,
85+ ) ;
86+
87+ it (
88+ 'should return false when url does not contain input id' ,
89+ waitForAsync ( ( ) => {
90+ const idNonMatching = 5 ;
91+ router . navigate ( [ 'workflows/show' , 555 ] ) . then ( ( ) => {
92+ expect ( underTest . isWorkflowHighlighted ( idNonMatching ) ) . toBeFalse ( ) ;
93+ } ) ;
94+ } ) ,
95+ ) ;
96+ } ) ;
97+
98+ it (
99+ 'toggleProject() should toggle a project' ,
100+ waitForAsync ( ( ) => {
101+ const project = 'project' ;
102+ const projectOther = 'projectOther' ;
103+
104+ expect ( underTest . openedProjects . size ) . toEqual ( 0 ) ;
105+
106+ underTest . toggleProject ( project ) ;
107+ expect ( underTest . openedProjects . size ) . toEqual ( 1 ) ;
108+ expect ( underTest . openedProjects ) . toContain ( project ) ;
109+
110+ underTest . toggleProject ( projectOther ) ;
111+ expect ( underTest . openedProjects . size ) . toEqual ( 2 ) ;
112+ expect ( underTest . openedProjects ) . toContain ( project ) ;
113+ expect ( underTest . openedProjects ) . toContain ( projectOther ) ;
114+
115+ underTest . toggleProject ( project ) ;
116+ expect ( underTest . openedProjects . size ) . toEqual ( 1 ) ;
117+ expect ( underTest . openedProjects ) . toContain ( projectOther ) ;
118+
119+ underTest . toggleProject ( projectOther ) ;
120+ expect ( underTest . openedProjects . size ) . toEqual ( 0 ) ;
121+ } ) ,
122+ ) ;
123+
124+ describe ( 'isProjectClosed' , ( ) => {
125+ it (
126+ 'should return true if project is not in opened projects no workflow is highlighted' ,
127+ waitForAsync ( ( ) => {
128+ const id = 555 ;
129+ const otherId = 5 ;
130+ router . navigate ( [ 'workflows/show' , id ] ) . then ( ( ) => {
131+ expect ( underTest . openedProjects . size ) . toEqual ( 0 ) ;
132+ expect ( underTest . isWorkflowHighlighted ( otherId ) ) . toBeFalse ( ) ;
133+
134+ const result = underTest . isProjectClosed ( 'project' , [ WorkflowIdentityModelFactory . create ( otherId , 'name' ) ] ) ;
135+
136+ expect ( result ) . toBeTruthy ( ) ;
137+ } ) ;
138+ } ) ,
139+ ) ;
140+
141+ it (
142+ 'should return false if project is in opened projects' ,
143+ waitForAsync ( ( ) => {
144+ const id = 555 ;
145+ const otherId = 5 ;
146+ const projectName = 'project' ;
147+ underTest . openedProjects . add ( projectName ) ;
148+
149+ router . navigate ( [ 'workflows/show' , id ] ) . then ( ( ) => {
150+ expect ( underTest . openedProjects . size ) . toEqual ( 1 ) ;
151+ expect ( underTest . openedProjects ) . toContain ( projectName ) ;
152+ expect ( underTest . isWorkflowHighlighted ( otherId ) ) . toBeFalse ( ) ;
153+
154+ const result = underTest . isProjectClosed ( projectName , [ WorkflowIdentityModelFactory . create ( otherId , 'name' ) ] ) ;
155+
156+ expect ( result ) . toBeFalse ( ) ;
157+ } ) ;
158+ } ) ,
159+ ) ;
160+
161+ it (
162+ 'should return false if project workflow is highlighted' ,
163+ waitForAsync ( ( ) => {
164+ const id = 555 ;
165+ router . navigate ( [ 'workflows/show' , id ] ) . then ( ( ) => {
166+ expect ( underTest . openedProjects . size ) . toEqual ( 0 ) ;
167+ expect ( underTest . isWorkflowHighlighted ( id ) ) . toBeTruthy ( ) ;
168+
169+ const result = underTest . isProjectClosed ( 'project' , [ WorkflowIdentityModelFactory . create ( id , 'name' ) ] ) ;
170+
171+ expect ( underTest . openedProjects . size ) . toEqual ( 1 ) ;
172+ expect ( result ) . toBeFalse ( ) ;
173+ } ) ;
174+ } ) ,
175+ ) ;
176+ } ) ;
68177} ) ;
0 commit comments