-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from ngxpert/fix/issue-9
Fix/issue 9
- Loading branch information
Showing
12 changed files
with
305 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Toast Grouping', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
cy.get('#grouping').scrollIntoView(); | ||
}); | ||
|
||
it('should show pre-grouped notifications', () => { | ||
// Click the pre-grouping example button | ||
cy.get('#grouping-pre').click(); | ||
|
||
// Check parent toast appears with retry and longer timeout | ||
cy.get('.hot-toast-bar-base', { timeout: 10000 }).should('be.visible'); | ||
cy.get('.hot-toast-bar-base').within(() => { | ||
cy.contains('New Activities', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('5 New Activities', { timeout: 5000 }).should('be.visible'); | ||
cy.contains("What's happening around you!", { timeout: 5000 }).should('be.visible'); | ||
}); | ||
|
||
// Check expand/collapse functionality with wait | ||
cy.get('.hot-toast-group-btn').should('be.visible').click(); | ||
cy.wait(500); // Wait for expansion animation | ||
|
||
// Verify all child notifications are visible | ||
cy.get('.hot-toast-bar-base-group').within(() => { | ||
cy.contains('New Message!', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Level Up!', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Reminder: Meeting Today', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Special Offer!', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Task Assigned', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Sarah sent you a message.', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Just Now', { timeout: 5000 }).should('be.visible'); | ||
}); | ||
|
||
// Test collapse with wait | ||
cy.get('.hot-toast-group-btn').should('be.visible').click(); | ||
cy.wait(500); // Wait for collapse animation | ||
|
||
// Verify collapsed state | ||
cy.get('.hot-toast-bar-base-group').within(() => { | ||
cy.contains('New Message!', { timeout: 5000 }).should('not.be.visible'); | ||
}); | ||
}); | ||
|
||
it('should handle dynamic notifications', () => { | ||
const titles = ['New Message!', 'Level Up!', 'Reminder: Meeting Today']; | ||
|
||
cy.get('#grouping-post').click(); | ||
cy.get('.hot-toast-bar-base', { timeout: 10000 }).should('be.visible'); | ||
|
||
titles.forEach(() => { | ||
cy.contains('Add notification').click(); | ||
cy.wait(200); | ||
}); | ||
|
||
cy.get('.hot-toast-group-btn').should('be.visible').click(); | ||
cy.wait(500); | ||
|
||
cy.get('.hot-toast-bar-base-group') | ||
.find('.hot-toast-bar-base') | ||
.should('have.length', titles.length) | ||
.each((el, index) => { | ||
expect(el).to.contain(titles[index]); | ||
}); | ||
}); | ||
|
||
it('should handle dismissible notifications', () => { | ||
// Force click the hidden test button | ||
cy.get('#test-dismissible-toasts').click({ force: true }); | ||
|
||
// Check parent toast appears with retry and longer timeout | ||
cy.get('.hot-toast-bar-base', { timeout: 10000 }).should('be.visible'); | ||
cy.get('.hot-toast-bar-base').within(() => { | ||
// Wait for all notifications to be added and visible | ||
cy.contains(/[0-5] New Activities/, { timeout: 10000 }).should('be.visible'); | ||
cy.contains("What's happening around you!", { timeout: 5000 }).should('be.visible'); | ||
cy.get('.hot-toast-close-btn').should('be.visible'); | ||
}); | ||
|
||
// Check expand/collapse functionality with wait | ||
cy.get('.hot-toast-group-btn').should('be.visible').click(); | ||
cy.wait(500); // Wait for expansion animation | ||
|
||
// Verify all child notifications are visible and have close buttons | ||
cy.get('.hot-toast-bar-base-group').within(() => { | ||
cy.contains('New Message!', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Level Up!', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Reminder: Meeting Today', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Special Offer!', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Task Assigned', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Sarah sent you a message.', { timeout: 5000 }).should('be.visible'); | ||
cy.contains('Just Now', { timeout: 5000 }).should('be.visible'); | ||
|
||
// Check close buttons in child notifications | ||
cy.get('.hot-toast-close-btn').should('have.length.at.least', 1); | ||
}); | ||
|
||
// Test close functionality | ||
cy.get('.hot-toast-bar-base-group').within(() => { | ||
cy.get('.hot-toast-close-btn').first().click(); | ||
cy.contains('New Message!', { timeout: 5000 }).should('not.exist'); | ||
}); | ||
|
||
// Test collapse with wait | ||
cy.get('.hot-toast-group-btn').should('be.visible').click(); | ||
cy.wait(500); // Wait for collapse animation | ||
|
||
// Verify collapsed state | ||
cy.get('.hot-toast-bar-base-group').within(() => { | ||
cy.contains('Level Up!', { timeout: 5000 }).should('not.be.visible'); | ||
}); | ||
}); | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Content } from '@ngneat/overview'; | ||
import { CreateHotToastRef, ToastOptions } from './hot-toast.model'; | ||
import { HotToastService } from './hot-toast.service'; | ||
import { Observable } from 'rxjs'; | ||
|
||
type ToastMethod = 'show' | 'success' | 'error' | 'warning' | 'info' | 'loading'; | ||
|
||
export class HotToastBuilder<DataType = unknown> { | ||
private options: ToastOptions<DataType>; | ||
private groupChildren: HotToastBuilder<unknown>[] = []; | ||
private toastRef: CreateHotToastRef<DataType>; | ||
|
||
constructor(private message: Content, private service: HotToastService) { | ||
this.options = {}; | ||
} | ||
|
||
setOptions(options: ToastOptions<DataType>): this { | ||
this.options = { ...this.options, ...options }; | ||
return this; | ||
} | ||
|
||
addChild(child: HotToastBuilder<unknown>): this { | ||
this.groupChildren.push(child); | ||
return this; | ||
} | ||
|
||
get afterGroupRefsAttached(): Observable<CreateHotToastRef<unknown>[]> { | ||
return this.toastRef?.afterGroupRefsAttached; | ||
} | ||
|
||
private addChildrenToOptions() { | ||
if (this.groupChildren.length > 0) { | ||
const children = this.groupChildren.map((child) => ({ | ||
options: { | ||
message: child.message, | ||
...child.options, | ||
}, | ||
})); | ||
|
||
this.options.group = { | ||
...this.options.group, | ||
children, | ||
}; | ||
} | ||
} | ||
|
||
// Create method that creates but doesn't show the toast. Call show() to show the toast. | ||
create(method: ToastMethod = 'show'): CreateHotToastRef<DataType> { | ||
this.addChildrenToOptions(); | ||
this.toastRef = this.service[method](this.message, { | ||
...this.options, | ||
...{ visible: false }, | ||
}) as CreateHotToastRef<DataType>; | ||
return this.toastRef; | ||
} | ||
|
||
private createToast(method: ToastMethod): CreateHotToastRef<DataType> { | ||
this.addChildrenToOptions(); | ||
this.toastRef = this.service[method](this.message, this.options) as CreateHotToastRef<DataType>; | ||
return this.toastRef; | ||
} | ||
|
||
show(): CreateHotToastRef<DataType> { | ||
return this.createToast('show'); | ||
} | ||
|
||
success(): CreateHotToastRef<DataType> { | ||
return this.createToast('success'); | ||
} | ||
|
||
error(): CreateHotToastRef<DataType> { | ||
return this.createToast('error'); | ||
} | ||
|
||
warning(): CreateHotToastRef<DataType> { | ||
return this.createToast('warning'); | ||
} | ||
|
||
info(): CreateHotToastRef<DataType> { | ||
return this.createToast('info'); | ||
} | ||
|
||
loading(): CreateHotToastRef<DataType> { | ||
return this.createToast('loading'); | ||
} | ||
} |
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
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.