Skip to content

Commit 9b93ebd

Browse files
refactor: inject dependencies in CpsSchedulerComponent and remove constructor
1 parent 4518d32 commit 9b93ebd

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

cypress/e2e/cps-scheduler.cy.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ describe('CPS Scheduler Component', () => {
6363
cy.get('[data-cy="weekly-MON"]').click();
6464
cy.get('[data-cy="weekly-WED"]').click();
6565

66-
cy.wait(1000);
67-
6866
// Verify timezone selector appears
6967
cy.get('[data-cy="timezone-selector"]').should('be.visible');
7068

@@ -86,8 +84,6 @@ describe('CPS Scheduler Component', () => {
8684
cy.get('input[type="checkbox"]').check({ force: true });
8785
});
8886

89-
cy.wait(1000);
90-
9187
// Verify timezone selector appears
9288
cy.get('[data-cy="timezone-selector"]').should('be.visible');
9389

@@ -143,8 +139,10 @@ describe('CPS Scheduler Component', () => {
143139

144140
// Set custom time to 14:45 (2:45 PM)
145141
cy.get('[data-cy="monthly-weekday-timepicker"]').within(() => {
146-
cy.get('input').eq(1).clear().type('45');
147-
cy.get('input').first().clear().type('14');
142+
cy.get('input').eq(1).clear();
143+
cy.get('input').eq(1).type('45');
144+
cy.get('input').first().clear();
145+
cy.get('input').first().type('14');
148146
});
149147

150148
// Switch to Advanced to see generated cron
@@ -164,35 +162,30 @@ describe('CPS Scheduler Component', () => {
164162
it('should accept valid cron expressions', () => {
165163
const testCron = '0 30 14 ? * MON-FRI';
166164

165+
cy.get('[data-cy="advanced-cron-input"]').find('input, textarea').clear();
166+
167167
cy.get('[data-cy="advanced-cron-input"]')
168168
.find('input, textarea')
169-
.clear()
170169
.type(testCron);
171170

172-
cy.wait(1000);
173-
174171
// Verify input contains the cron
175172
cy.get('[data-cy="advanced-cron-input"]')
176173
.find('input, textarea')
177174
.should('have.value', testCron);
178175
});
179176

180177
it('should handle invalid cron expressions', () => {
178+
cy.get('[data-cy="advanced-cron-input"]').find('input, textarea').clear();
179+
181180
cy.get('[data-cy="advanced-cron-input"]')
182181
.find('input, textarea')
183-
.clear()
184182
.type('invalid cron');
185183

186-
cy.wait(1000);
187-
188184
// Component should not crash
189185
cy.get('[data-cy="advanced-cron-input"]').should('be.visible');
190186

191187
// Check validation state
192-
cy.get('body').then(($body) => {
193-
const hasError = $body.find('.ng-invalid, .error').length > 0;
194-
expect(hasError).to.be.true;
195-
});
188+
cy.get('.ng-invalid, .error').should('exist');
196189
});
197190
});
198191

@@ -202,8 +195,6 @@ describe('CPS Scheduler Component', () => {
202195
cy.get('[data-cy="schedule-type-toggle"]').contains('Weekly').click();
203196
cy.get('[data-cy="weekly-MON"]').click();
204197

205-
cy.wait(1000);
206-
207198
// Switch to Advanced to verify cron was generated
208199
cy.get('[data-cy="schedule-type-toggle"]').contains('Advanced').click();
209200
cy.get('[data-cy="advanced-cron-input"]')
@@ -220,8 +211,6 @@ describe('CPS Scheduler Component', () => {
220211
cy.get('[data-cy="schedule-type-toggle"]').contains('Weekly').click();
221212
cy.get('[data-cy="weekly-MON"]').click();
222213

223-
cy.wait(1000);
224-
225214
// Reset to Not set
226215
cy.get('[data-cy="schedule-type-toggle"]').contains('Not set').click();
227216

@@ -238,13 +227,12 @@ describe('CPS Scheduler Component', () => {
238227
it('should allow timezone filtering and show autocomplete options', () => {
239228
cy.get('[data-cy="schedule-type-toggle"]').contains('Advanced').click();
240229
// Type in the autocomplete to filter timezone options
230+
cy.get('[data-cy="timezone-select"]').find('input').clear();
231+
241232
cy.get('[data-cy="timezone-select"]')
242233
.find('input')
243-
.clear()
244234
.type('UTC', { force: true });
245235

246-
cy.wait(500);
247-
248236
// Verify that autocomplete dropdown appears with options
249237
cy.get('.cps-autocomplete-options, .cps-autocomplete-option').should(
250238
'exist'
@@ -260,13 +248,12 @@ describe('CPS Scheduler Component', () => {
260248
cy.get('[data-cy="schedule-type-toggle"]').contains('Advanced').click();
261249

262250
// Type a specific timezone
251+
cy.get('[data-cy="timezone-select"]').find('input').clear();
252+
263253
cy.get('[data-cy="timezone-select"]')
264254
.find('input')
265-
.clear()
266255
.type('Europe/London', { force: true });
267256

268-
cy.wait(500);
269-
270257
// Verify the text remains in the input
271258
cy.get('[data-cy="timezone-select"]')
272259
.find('input')
@@ -283,7 +270,6 @@ describe('CPS Scheduler Component', () => {
283270

284271
types.forEach((type) => {
285272
cy.get('[data-cy="schedule-type-toggle"]').contains(type).click();
286-
cy.wait(200);
287273
});
288274

289275
// Should end in valid state

projects/cps-ui-kit/src/lib/components/cps-scheduler/cps-scheduler.component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ChangeDetectorRef,
55
Component,
66
EventEmitter,
7+
inject,
78
Input,
89
OnChanges,
910
OnInit,
@@ -184,6 +185,10 @@ export class CpsSchedulerComponent implements OnInit, OnChanges {
184185
{ label: 'Advanced', value: 'Advanced' }
185186
];
186187

188+
private readonly _fb = inject(FormBuilder);
189+
private readonly _cdr = inject(ChangeDetectorRef);
190+
private readonly _cronValidationService = inject(CronValidationService);
191+
187192
activeScheduleType = 'Not set';
188193
selectOptions = this._getSelectOptions();
189194
timeZoneOptions = timeZones.map((tz) => ({ label: tz, value: tz }));
@@ -195,12 +200,6 @@ export class CpsSchedulerComponent implements OnInit, OnChanges {
195200
private _isDirty = false;
196201
private _minutesDefault = '0/1 * 1/1 * ? *';
197202

198-
constructor(
199-
private _fb: FormBuilder,
200-
private _cdr: ChangeDetectorRef,
201-
private _cronValidationService: CronValidationService
202-
) {}
203-
204203
ngOnInit(): void {
205204
this.state = this._getDefaultState();
206205

0 commit comments

Comments
 (0)