Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(code-examples): move spec that uses SkyConfirmTestingController t…
…o another code example (#2227)
- Loading branch information
1 parent
b0b554f
commit 2ba3bff
Showing
8 changed files
with
130 additions
and
87 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...xamples/src/app/code-examples/modals/confirm/basic-with-controller/demo.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,57 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { | ||
SkyConfirmTestingController, | ||
SkyConfirmTestingModule, | ||
} from '@skyux/modals/testing'; | ||
|
||
import { DemoComponent } from './demo.component'; | ||
|
||
describe('Testing with SkyConfirmTestingController', () => { | ||
async function setupTest(): Promise<{ | ||
confirmController: SkyConfirmTestingController; | ||
fixture: ComponentFixture<DemoComponent>; | ||
}> { | ||
const confirmController = TestBed.inject(SkyConfirmTestingController); | ||
const fixture = TestBed.createComponent(DemoComponent); | ||
|
||
return { confirmController, fixture }; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [SkyConfirmTestingModule, DemoComponent], | ||
}); | ||
}); | ||
|
||
it('should click "OK" on a confirmation dialog', async () => { | ||
const { confirmController, fixture } = await setupTest(); | ||
|
||
fixture.componentInstance.launchConfirm(); | ||
fixture.detectChanges(); | ||
|
||
confirmController.expectOpen({ | ||
message: 'Are you sure?', | ||
}); | ||
|
||
confirmController.ok(); | ||
confirmController.expectNone(); | ||
|
||
expect(fixture.componentInstance.selectedAction).toEqual('ok'); | ||
}); | ||
|
||
it('should cancel the confirmation dialog', async () => { | ||
const { confirmController, fixture } = await setupTest(); | ||
|
||
fixture.componentInstance.launchConfirm(); | ||
fixture.detectChanges(); | ||
|
||
confirmController.expectOpen({ | ||
message: 'Are you sure?', | ||
}); | ||
|
||
confirmController.cancel(); | ||
confirmController.expectNone(); | ||
|
||
expect(fixture.componentInstance.selectedAction).toEqual('cancel'); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
...ode-examples/src/app/code-examples/modals/confirm/basic-with-controller/demo.component.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,30 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { SkyConfirmService } from '@skyux/modals'; | ||
|
||
@Component({ | ||
imports: [], | ||
standalone: true, | ||
template: `<button | ||
aria-haspopup="dialog" | ||
class="sky-btn sky-btn-default" | ||
type="button" | ||
(click)="launchConfirm()" | ||
> | ||
Open confirm | ||
</button>`, | ||
}) | ||
export class DemoComponent { | ||
public selectedAction: string | undefined; | ||
|
||
readonly #confirmSvc = inject(SkyConfirmService); | ||
|
||
public launchConfirm(): void { | ||
const dialog = this.#confirmSvc.open({ | ||
message: 'Are you sure?', | ||
}); | ||
|
||
dialog.closed.subscribe((args) => { | ||
this.selectedAction = args.action; | ||
}); | ||
} | ||
} |
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
66 changes: 0 additions & 66 deletions
66
apps/code-examples/src/app/code-examples/modals/confirm/demo-controller.spec.ts
This file was deleted.
Oops, something went wrong.
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