Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve coverage on collapsible tree node sibling test #893

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,7 @@ describe('CollapsibleTreeComponent', () => {
] as const satisfies readonly ExpandedTestCase[]
for (const testCase of EXPANDED_TEST_CASES) {
describe(`when ${testCase.name}`, () => {
let mockParentComponent: jasmine.SpyObj<CollapsibleTreeComponent>

beforeEach(() => {
mockParentComponent =
jasmine.createSpyObj<CollapsibleTreeComponent>('node', [
'collapseAllChildren',
])
component.parent = mockParentComponent
component.isExpanded = testCase.isExpanded

fixture.detectChanges()
Expand Down Expand Up @@ -250,21 +243,30 @@ describe('CollapsibleTreeComponent', () => {
'true',
)
})
})
}

it('should collapse rest of siblings when expanding a collapsed node', () => {
fixture.detectChanges()

if (testCase.name === 'collapsed') {
it('should collapse rest of siblings', () => {
const buttonElement = fixture.debugElement.query(BUTTON_PREDICATE)
buttonElement.triggerEventHandler('click')
const childrenComponents = fixture.debugElement
.queryAll(byComponent(CollapsibleTreeComponent))
.map((c) => c.componentInstance as CollapsibleTreeComponent)

fixture.detectChanges()
expect(childrenComponents.length).toEqual(DUMMY_CHILDREN.length)

expect(
mockParentComponent.collapseAllChildren,
).toHaveBeenCalledOnceWith({ except: component })
})
}
childrenComponents.forEach(
(child) => (child.collapse = jasmine.createSpy()),
)
const [firstChild, ...restChildrenComponents] = childrenComponents

firstChild.expand()

expect(firstChild.collapse).not.toHaveBeenCalled()
restChildrenComponents.forEach((child) => {
expect(child.collapse).toHaveBeenCalledOnceWith()
})
}
})
})

describe('when non collapsible', () => {
Expand Down