-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edit-content) fix test, added new test #28831
- Loading branch information
Showing
17 changed files
with
574 additions
and
98 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
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
97 changes: 84 additions & 13 deletions
97
...nents/dot-category-field-category-list/dot-category-field-category-list.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 |
---|---|---|
@@ -1,22 +1,93 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { expect } from '@jest/globals'; | ||
import { byTestId, createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
|
||
import { DotCategoryFieldCategoryListComponent } from './dot-category-field-category-list.component'; | ||
import { DotMessageService } from '@dotcms/data-access'; | ||
|
||
import { | ||
DotCategoryFieldCategoryListComponent, | ||
MINIMUM_CATEGORY_COLUMNS | ||
} from './dot-category-field-category-list.component'; | ||
|
||
import { CATEGORIES_MOCK, SELECTED_MOCK } from '../../mocks/category-field.mocks'; | ||
|
||
describe('DotCategoryFieldCategoryListComponent', () => { | ||
let component: DotCategoryFieldCategoryListComponent; | ||
let fixture: ComponentFixture<DotCategoryFieldCategoryListComponent>; | ||
let spectator: Spectator<DotCategoryFieldCategoryListComponent>; | ||
|
||
const createComponent = createComponentFactory({ | ||
component: DotCategoryFieldCategoryListComponent, | ||
providers: [mockProvider(DotMessageService)] | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent({ | ||
props: { | ||
categories: CATEGORIES_MOCK, | ||
selected: SELECTED_MOCK | ||
} | ||
}); | ||
|
||
spectator.detectChanges(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should render correct number of category columns', () => { | ||
expect(spectator.queryAll(byTestId('category-column')).length).toBe(CATEGORIES_MOCK.length); | ||
}); | ||
|
||
it('should render correct number of category items', () => { | ||
expect(spectator.queryAll(byTestId('category-item')).length).toBe( | ||
CATEGORIES_MOCK.flat().length | ||
); | ||
}); | ||
|
||
it('should render correct number of category item labels', () => { | ||
expect(spectator.queryAll(byTestId('category-item-label')).length).toBe( | ||
CATEGORIES_MOCK.flat().length | ||
); | ||
}); | ||
|
||
it('should render correct number of empty columns', () => { | ||
expect(spectator.queryAll(byTestId('category-column-empty')).length).toBe( | ||
MINIMUM_CATEGORY_COLUMNS - CATEGORIES_MOCK.length | ||
); | ||
}); | ||
|
||
it('should render one category item with child indicator', () => { | ||
expect(spectator.queryAll(byTestId('category-item-with-child')).length).toBe(1); | ||
}); | ||
|
||
it('should emit the correct item when clicked', () => { | ||
const emitSpy = jest.spyOn(spectator.component.itemClicked, 'emit'); | ||
const items = spectator.queryAll(byTestId('category-item')); | ||
spectator.click(items[0]); | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [DotCategoryFieldCategoryListComponent] | ||
}).compileComponents(); | ||
expect(emitSpy).toHaveBeenCalledWith({ | ||
index: 0, | ||
item: CATEGORIES_MOCK[0][0] | ||
}); | ||
}); | ||
|
||
fixture = TestBed.createComponent(DotCategoryFieldCategoryListComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
it('should apply selected class to the correct item', () => { | ||
const items = spectator.queryAll(byTestId('category-item')); | ||
expect(items[0].className).toContain('category-list__item--selected'); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
it('should not render any empty columns when there are enough categories', () => { | ||
const minColumns = 4; | ||
const testCategories = Array(minColumns).fill(CATEGORIES_MOCK[0]); | ||
|
||
spectator = createComponent({ | ||
props: { | ||
categories: testCategories, | ||
selected: SELECTED_MOCK | ||
} | ||
}); | ||
|
||
spectator.detectChanges(); | ||
|
||
expect(spectator.queryAll(byTestId('category-column-empty')).length).toBe(0); | ||
}); | ||
}); |
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.