-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-disabled-vertical-tab-to-playground
- Loading branch information
Showing
44 changed files
with
1,165 additions
and
231 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
apps/code-examples/src/app/code-examples/pages/action-hub/demo.component.html
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
110 changes: 110 additions & 0 deletions
110
apps/code-examples/src/app/code-examples/pages/action-hub/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,110 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { ApplicationRef } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { | ||
SkyModalTestingController, | ||
SkyModalTestingModule, | ||
} from '@skyux/modals/testing'; | ||
import { SkyActionHubHarness } from '@skyux/pages/testing'; | ||
|
||
import { DemoComponent } from './demo.component'; | ||
import { SettingsModalComponent } from './settings-modal.component'; | ||
|
||
describe('Action hub', () => { | ||
async function setupTest(): Promise<{ | ||
actionHubHarness: SkyActionHubHarness; | ||
fixture: ComponentFixture<DemoComponent>; | ||
loader: HarnessLoader; | ||
}> { | ||
const fixture = TestBed.createComponent(DemoComponent); | ||
const loader = TestbedHarnessEnvironment.loader(fixture); | ||
const actionHubHarness = await loader.getHarness( | ||
SkyActionHubHarness.with({ | ||
dataSkyId: 'action-hub', | ||
}), | ||
); | ||
|
||
return { actionHubHarness, fixture, loader }; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DemoComponent, SkyModalTestingModule], | ||
}); | ||
}); | ||
|
||
it('should have correct page title', async () => { | ||
const { actionHubHarness } = await setupTest(); | ||
|
||
expect(await actionHubHarness.getTitle()).toBe('Active accounts'); | ||
}); | ||
|
||
it('should show needs-attention items', async () => { | ||
const { actionHubHarness } = await setupTest(); | ||
|
||
expect( | ||
await actionHubHarness | ||
.getNeedsAttentionItems() | ||
.then( | ||
async (items) => | ||
await Promise.all(items.map((item) => item.getText())), | ||
), | ||
).toEqual([ | ||
'9 updates from portal', | ||
'8 new messages from online donation', | ||
'7 possible duplicates from constituent lists', | ||
'6 updates from portal', | ||
'5 new messages from online donation', | ||
'4 possible duplicates from constituent lists', | ||
'3 update from portal', | ||
'2 new messages from online donation', | ||
'1 possible duplicate from constituent lists', | ||
]); | ||
}); | ||
|
||
it('should show recent links', async () => { | ||
const { actionHubHarness } = await setupTest(); | ||
|
||
const linkListHarness = await actionHubHarness.getRecentLinks(); | ||
const listItems = await linkListHarness.getListItems(); | ||
expect(await Promise.all(listItems.map((item) => item.getText()))).toEqual([ | ||
'Recent 1', | ||
'Recent 2', | ||
'Recent 3', | ||
'Recent 4', | ||
'Recent 5', | ||
]); | ||
}); | ||
|
||
it('should show related links', async () => { | ||
const { actionHubHarness } = await setupTest(); | ||
|
||
const linkListHarness = await actionHubHarness.getRelatedLinks(); | ||
const listItems = await linkListHarness.getListItems(); | ||
expect(await Promise.all(listItems.map((item) => item.getText()))).toEqual([ | ||
'Link 1', | ||
'Link 2', | ||
'Link 3', | ||
]); | ||
}); | ||
|
||
it('should show settings links', async () => { | ||
const { actionHubHarness } = await setupTest(); | ||
|
||
const linkListHarness = await actionHubHarness.getSettingsLinks(); | ||
const listItems = await linkListHarness.getListItems(); | ||
expect(await Promise.all(listItems.map((item) => item.getText()))).toEqual([ | ||
'Number', | ||
'Color', | ||
]); | ||
const modalController = TestBed.inject(SkyModalTestingController); | ||
modalController.expectNone(); | ||
await listItems[0].click(); | ||
const app = TestBed.inject(ApplicationRef); | ||
app.tick(); | ||
await app.whenStable(); | ||
modalController.expectCount(1); | ||
modalController.expectOpen(SettingsModalComponent); | ||
}); | ||
}); |
66 changes: 29 additions & 37 deletions
66
apps/code-examples/src/app/code-examples/pages/action-hub/settings-modal.component.html
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,49 +1,41 @@ | ||
<sky-modal [headingText]="title"> | ||
<sky-modal-content> | ||
<form [formGroup]="formGroup" (submit)="modalInstance.save()"> | ||
<form [formGroup]="formGroup" (submit)="modalInstance.save()"> | ||
<sky-modal data-sky-id="settings-modal" [headingText]="title"> | ||
<sky-modal-content> | ||
@for (field of fields; track field) { | ||
<ng-container class="row"> | ||
@switch (title) { | ||
@case ('Color') { | ||
<div class="sky-margin-stacked-sm"> | ||
<label class="sky-control-label" [for]="input.id">{{ | ||
field | ||
}}</label> | ||
<sky-colorpicker #colorPicker> | ||
<input | ||
#input="skyId" | ||
skyId | ||
type="text" | ||
[formControlName]="field" | ||
[skyColorpickerInput]="colorPicker" | ||
/> | ||
</sky-colorpicker> | ||
</div> | ||
<sky-colorpicker #colorPicker stacked [labelText]="field"> | ||
<input | ||
type="text" | ||
[formControlName]="field" | ||
[skyColorpickerInput]="colorPicker" | ||
/> | ||
</sky-colorpicker> | ||
} | ||
@default { | ||
<sky-input-box [labelText]="field"> | ||
<sky-input-box stacked [labelText]="field"> | ||
<input type="text" [formControlName]="field" /> | ||
</sky-input-box> | ||
} | ||
} | ||
</ng-container> | ||
} | ||
</form> | ||
</sky-modal-content> | ||
<sky-modal-footer> | ||
<button | ||
class="sky-btn sky-btn-primary sky-margin-inline-sm" | ||
type="button" | ||
(click)="modalInstance.save()" | ||
> | ||
Save | ||
</button> | ||
<button | ||
class="sky-btn sky-btn-link" | ||
type="button" | ||
(click)="modalInstance.close()" | ||
> | ||
Close | ||
</button> | ||
</sky-modal-footer> | ||
</sky-modal> | ||
</sky-modal-content> | ||
<sky-modal-footer> | ||
<button | ||
class="sky-btn sky-btn-primary sky-margin-inline-sm" | ||
type="submit" | ||
> | ||
Save | ||
</button> | ||
<button | ||
class="sky-btn sky-btn-link" | ||
type="button" | ||
(click)="modalInstance.close()" | ||
> | ||
Close | ||
</button> | ||
</sky-modal-footer> | ||
</sky-modal> | ||
</form> |
70 changes: 70 additions & 0 deletions
70
apps/code-examples/src/app/code-examples/pages/action-hub/settings-modal.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,70 @@ | ||
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 { SkyModalHarness } from '@skyux/modals/testing'; | ||
import { SkyActionHubHarness } from '@skyux/pages/testing'; | ||
|
||
import { DemoComponent } from './demo.component'; | ||
import { MODAL_TITLE } from './modal-title-token'; | ||
|
||
describe('SettingsModalComponent', () => { | ||
async function setupTest(): Promise<{ | ||
actionHubHarness: SkyActionHubHarness; | ||
fixture: ComponentFixture<DemoComponent>; | ||
loader: HarnessLoader; | ||
rootLoader: HarnessLoader; | ||
}> { | ||
const fixture = TestBed.createComponent(DemoComponent); | ||
const loader = TestbedHarnessEnvironment.loader(fixture); | ||
const rootLoader = TestbedHarnessEnvironment.documentRootLoader(fixture); | ||
const actionHubHarness = await loader.getHarness( | ||
SkyActionHubHarness.with({ | ||
dataSkyId: 'action-hub', | ||
}), | ||
); | ||
|
||
return { actionHubHarness, rootLoader, fixture, loader }; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DemoComponent, NoopAnimationsModule], | ||
providers: [ | ||
{ | ||
provide: MODAL_TITLE, | ||
useValue: 'Settings Modal Test', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should show settings modal', async () => { | ||
const { actionHubHarness, rootLoader } = await setupTest(); | ||
const settingsLinksHarness = await actionHubHarness.getSettingsLinks(); | ||
const settingsLinks = await settingsLinksHarness.getListItems(); | ||
expect(settingsLinks).toHaveSize(2); | ||
await settingsLinks[1].click(); | ||
const modalHarness = await rootLoader.getHarness( | ||
SkyModalHarness.with({ | ||
dataSkyId: 'settings-modal', | ||
}), | ||
); | ||
expect(await modalHarness.getHeadingText()).toBe('Color'); | ||
const consoleSpy = spyOn(console, 'log').and.stub(); | ||
const modalElement = TestbedHarnessEnvironment.getNativeElement( | ||
await modalHarness.host(), | ||
); | ||
const submit = modalElement.querySelector('button[type="submit"]'); | ||
expect(submit).toBeTruthy(); | ||
expect(submit?.textContent?.trim()).toBe('Save'); | ||
(submit as HTMLButtonElement).click(); | ||
expect(consoleSpy).toHaveBeenCalledWith({ | ||
'Color 1': '', | ||
'Color 2': '', | ||
'Color 3': '', | ||
'Color 4': '', | ||
'Color 5': '', | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.