-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
🍒 cherry pick from [#3141](#3141) [AB#2195574](https://dev.azure.com/blackbaud/Products/_boards/board/t/SKY%20UX%20Program/Stories/?workitem=2195574) --------- Co-authored-by: Sandhya Adhirvuh <[email protected]>
- Loading branch information
1 parent
fb9557f
commit 02caf83
Showing
19 changed files
with
524 additions
and
12 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
apps/code-examples/src/app/code-examples/toast/toast/basic/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,58 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { SkyToastType } from '@skyux/toast'; | ||
import { SkyToasterHarness } from '@skyux/toast/testing'; | ||
|
||
import { DemoComponent } from './demo.component'; | ||
|
||
describe('Basic toast demo', () => { | ||
let fixture: ComponentFixture<DemoComponent>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DemoComponent, NoopAnimationsModule], | ||
}); | ||
|
||
fixture = TestBed.createComponent(DemoComponent); | ||
loader = TestbedHarnessEnvironment.documentRootLoader(fixture); | ||
}); | ||
|
||
async function setupTest(): Promise<{ | ||
toasterHarness: SkyToasterHarness; | ||
}> { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
|
||
const toasterHarness: SkyToasterHarness = | ||
await loader.getHarness(SkyToasterHarness); | ||
|
||
return { toasterHarness }; | ||
} | ||
|
||
it('should open success toasts', async () => { | ||
const { toasterHarness } = await setupTest(); | ||
|
||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(toasterHarness.getNumberOfToasts()).toBeResolvedTo(2); | ||
|
||
const toast = await toasterHarness.getToastByMessage( | ||
'This is a sample toast message.', | ||
); | ||
|
||
await expectAsync(toast.getType()).toBeResolvedTo(SkyToastType.Success); | ||
}); | ||
|
||
it('should close all toasts', async () => { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
fixture.componentInstance.closeAll(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(loader.getHarness(SkyToasterHarness)).toBeRejected(); | ||
}); | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
.../code-examples/src/app/code-examples/toast/toast/custom-component/custom-toast-harness.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,9 @@ | ||
import { ComponentHarness } from '@angular/cdk/testing'; | ||
|
||
export class CustomToastHarness extends ComponentHarness { | ||
public static hostSelector = 'app-toast-content-demo'; | ||
|
||
public async getText(): Promise<string> { | ||
return await (await this.host()).text(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
apps/code-examples/src/app/code-examples/toast/toast/custom-component/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,56 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { SkyToastType } from '@skyux/toast'; | ||
import { SkyToasterHarness } from '@skyux/toast/testing'; | ||
|
||
import { CustomToastHarness } from './custom-toast-harness'; | ||
import { DemoComponent } from './demo.component'; | ||
|
||
describe('Custom component toast demo', () => { | ||
let fixture: ComponentFixture<DemoComponent>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DemoComponent, NoopAnimationsModule], | ||
}); | ||
|
||
fixture = TestBed.createComponent(DemoComponent); | ||
loader = TestbedHarnessEnvironment.documentRootLoader(fixture); | ||
}); | ||
|
||
async function setupTest(): Promise<{ | ||
toasterHarness: SkyToasterHarness; | ||
}> { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
|
||
const toasterHarness: SkyToasterHarness = | ||
await loader.getHarness(SkyToasterHarness); | ||
|
||
return { toasterHarness }; | ||
} | ||
|
||
it('should open custom component in toast', async () => { | ||
const { toasterHarness } = await setupTest(); | ||
|
||
const toasts = await toasterHarness.getToasts(); | ||
const customHarness = await toasts[0].queryHarness(CustomToastHarness); | ||
|
||
await expectAsync(toasts[0].getType()).toBeResolvedTo(SkyToastType.Success); | ||
await expectAsync(customHarness.getText()).toBeResolvedTo( | ||
'Custom message: This toast has embedded a custom component for its content.', | ||
); | ||
}); | ||
|
||
it('should close all toasts', async () => { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
fixture.componentInstance.closeAll(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(loader.getHarness(SkyToasterHarness)).toBeRejected(); | ||
}); | ||
}); |
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
58 changes: 58 additions & 0 deletions
58
libs/components/code-examples/src/lib/modules/toast/toast/basic/example.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,58 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { SkyToastType } from '@skyux/toast'; | ||
import { SkyToasterHarness } from '@skyux/toast/testing'; | ||
|
||
import { ToastBasicExampleComponent } from './example.component'; | ||
|
||
describe('Basic toast example', () => { | ||
let fixture: ComponentFixture<ToastBasicExampleComponent>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ToastBasicExampleComponent, NoopAnimationsModule], | ||
}); | ||
|
||
fixture = TestBed.createComponent(ToastBasicExampleComponent); | ||
loader = TestbedHarnessEnvironment.documentRootLoader(fixture); | ||
}); | ||
|
||
async function setupTest(): Promise<{ | ||
toasterHarness: SkyToasterHarness; | ||
}> { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
|
||
const toasterHarness: SkyToasterHarness = | ||
await loader.getHarness(SkyToasterHarness); | ||
|
||
return { toasterHarness }; | ||
} | ||
|
||
it('should open success toasts', async () => { | ||
const { toasterHarness } = await setupTest(); | ||
|
||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(toasterHarness.getNumberOfToasts()).toBeResolvedTo(2); | ||
|
||
const toast = await toasterHarness.getToastByMessage( | ||
'This is a sample toast message.', | ||
); | ||
|
||
await expectAsync(toast.getType()).toBeResolvedTo(SkyToastType.Success); | ||
}); | ||
|
||
it('should close all toasts', async () => { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
fixture.componentInstance.closeAll(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(loader.getHarness(SkyToasterHarness)).toBeRejected(); | ||
}); | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
...onents/code-examples/src/lib/modules/toast/toast/custom-component/custom-toast-harness.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,9 @@ | ||
import { ComponentHarness } from '@angular/cdk/testing'; | ||
|
||
export class CustomToastHarness extends ComponentHarness { | ||
public static hostSelector = 'app-toast-content-example'; | ||
|
||
public async getText(): Promise<string> { | ||
return await (await this.host()).text(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ents/code-examples/src/lib/modules/toast/toast/custom-component/example.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,56 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { SkyToastType } from '@skyux/toast'; | ||
import { SkyToasterHarness } from '@skyux/toast/testing'; | ||
|
||
import { CustomToastHarness } from './custom-toast-harness'; | ||
import { ToastCustomComponentExampleComponent } from './example.component'; | ||
|
||
describe('Custom component toast demo', () => { | ||
let fixture: ComponentFixture<ToastCustomComponentExampleComponent>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ToastCustomComponentExampleComponent, NoopAnimationsModule], | ||
}); | ||
|
||
fixture = TestBed.createComponent(ToastCustomComponentExampleComponent); | ||
loader = TestbedHarnessEnvironment.documentRootLoader(fixture); | ||
}); | ||
|
||
async function setupTest(): Promise<{ | ||
toasterHarness: SkyToasterHarness; | ||
}> { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
|
||
const toasterHarness: SkyToasterHarness = | ||
await loader.getHarness(SkyToasterHarness); | ||
|
||
return { toasterHarness }; | ||
} | ||
|
||
it('should open custom component in toast', async () => { | ||
const { toasterHarness } = await setupTest(); | ||
|
||
const toasts = await toasterHarness.getToasts(); | ||
const customHarness = await toasts[0].queryHarness(CustomToastHarness); | ||
|
||
await expectAsync(toasts[0].getType()).toBeResolvedTo(SkyToastType.Success); | ||
await expectAsync(customHarness.getText()).toBeResolvedTo( | ||
'Custom message: This toast has embedded a custom component for its content.', | ||
); | ||
}); | ||
|
||
it('should close all toasts', async () => { | ||
fixture.componentInstance.openToast(); | ||
fixture.detectChanges(); | ||
fixture.componentInstance.closeAll(); | ||
fixture.detectChanges(); | ||
|
||
await expectAsync(loader.getHarness(SkyToasterHarness)).toBeRejected(); | ||
}); | ||
}); |
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
4 changes: 2 additions & 2 deletions
4
libs/components/core/testing/src/modules/overlay/overlay-harness-filters.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { SkyHarnessFilters } from '../../shared/harness-filters'; | ||
import { BaseHarnessFilters } from '@angular/cdk/testing'; | ||
|
||
/** | ||
* A set of criteria that can be used to filter a list of SkyOverlayHarness instances. | ||
* @internal | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type | ||
export interface SkyOverlayHarnessFilters extends SkyHarnessFilters {} | ||
export interface SkyOverlayHarnessFilters extends BaseHarnessFilters {} |
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
12 changes: 12 additions & 0 deletions
12
libs/components/toast/testing/src/modules/toast-harness-filters.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,12 @@ | ||
import { BaseHarnessFilters } from '@angular/cdk/testing'; | ||
|
||
/** | ||
* A set of criteria that can be used to filter a list of `SkyToastHarness` instances. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type | ||
export interface SkyToastHarnessFilters extends BaseHarnessFilters { | ||
/** | ||
* Finds toasts with the matching text. | ||
*/ | ||
message?: string; | ||
} |
Oops, something went wrong.