Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#25959 Added testing to the preview components
- Loading branch information
1 parent
e3c9eb9
commit 6495f18
Showing
6 changed files
with
137 additions
and
11 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
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
50 changes: 47 additions & 3 deletions
50
...ot-edit-page/seo/components/dot-seo-image-preview/dot-seo-image-preview.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,14 +1,58 @@ | ||
import { Spectator, createComponentFactory } from '@ngneat/spectator'; | ||
import { byTestId, createComponentFactory, Spectator } from '@ngneat/spectator'; | ||
|
||
import { DotMessageService } from '@dotcms/data-access'; | ||
import { MockDotMessageService } from '@dotcms/utils-testing'; | ||
|
||
import { DotSeoImagePreviewComponent } from './dot-seo-image-preview.component'; | ||
|
||
describe('DotSeoImagePreviewComponent', () => { | ||
let spectator: Spectator<DotSeoImagePreviewComponent>; | ||
const createComponent = createComponentFactory(DotSeoImagePreviewComponent); | ||
|
||
it('should create', () => { | ||
const createComponent = createComponentFactory({ | ||
component: DotSeoImagePreviewComponent, | ||
providers: [ | ||
{ | ||
provide: DotMessageService, | ||
useValue: new MockDotMessageService({ | ||
'seo.rules.media.preview.not.defined': 'Social Media Preview Image Not Defined!' | ||
}) | ||
} | ||
] | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(spectator.component).toBeTruthy(); | ||
}); | ||
|
||
it('should display an error message when noImageAvailable is true', () => { | ||
(spectator.component.noImageAvailable = true), spectator.detectComponentChanges(); | ||
|
||
const errorMessage = spectator.query(byTestId('seo-image-default')); | ||
expect(errorMessage).toBeTruthy(); | ||
}); | ||
|
||
it('should display an image when noImageAvailable is false', () => { | ||
(spectator.component.noImageAvailable = false), | ||
spectator.setInput({ | ||
image: 'sample-image-url.jpg' | ||
}); | ||
spectator.detectChanges(); | ||
|
||
const imageElement = spectator.query(byTestId('seo-image-preview')); | ||
expect(imageElement).toBeTruthy(); | ||
expect(imageElement.getAttribute('src')).toBe('sample-image-url.jpg'); | ||
}); | ||
|
||
it('should call onImageError() when the image fails to load', () => { | ||
const onImageErrorSpy = spyOn(spectator.component, 'onImageError'); | ||
const imageElement = spectator.query(byTestId('seo-image-preview')); | ||
|
||
spectator.dispatchFakeEvent(imageElement, 'error'); | ||
|
||
expect(onImageErrorSpy).toHaveBeenCalled(); | ||
}); | ||
}); |