forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(common): add e2e tests for the fill mode checks in the NgOptimiz…
…edImage directive (angular#48036) This commit adds extra e2e tests for the fill mode checks in the NgOptimizedImage directive to make sure a warning is logged in a console. PR Close angular#48036
- Loading branch information
1 parent
ff4a457
commit e962842
Showing
6 changed files
with
89 additions
and
3 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
45 changes: 45 additions & 0 deletions
45
packages/core/test/bundling/image-directive/e2e/fill-mode/fill-mode.e2e-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,45 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* tslint:disable:no-console */ | ||
import {browser} from 'protractor'; | ||
import {logging} from 'selenium-webdriver'; | ||
|
||
import {collectBrowserLogs} from '../browser-logs-util'; | ||
|
||
describe('NgOptimizedImage directive', () => { | ||
it('should not warn when an image in the fill mode is rendered correctly', async () => { | ||
await browser.get('/e2e/fill-mode-passing'); | ||
const logs = await collectBrowserLogs(logging.Level.WARNING); | ||
expect(logs.length).toEqual(0); | ||
}); | ||
|
||
it('should warn if an image in the fill mode has zero height after rendering', async () => { | ||
await browser.get('/e2e/fill-mode-failing'); | ||
const logs = await collectBrowserLogs(logging.Level.WARNING); | ||
|
||
expect(logs.length).toEqual(1); | ||
// Image loading order is not guaranteed, so all logs, rather than single entry | ||
// needs to be checked in order to test whether a given error message is present. | ||
const expectErrorMessageInLogs = (logs: logging.Entry[], message: string) => { | ||
expect(logs.some((log) => { | ||
return log.message.includes(message); | ||
})).toBeTruthy(); | ||
}; | ||
|
||
expectErrorMessageInLogs( | ||
logs, | ||
'NG02952: The NgOptimizedImage directive (activated on an \\u003Cimg> element ' + | ||
'with the `ngSrc=\\"/e2e/logo-500w.jpg\\"`) has detected that the height ' + | ||
'of the fill-mode image is zero. This is likely because the containing element ' + | ||
'does not have the CSS \'position\' property set to one of the following: ' + | ||
'\\"relative\\", \\"fixed\\", or \\"absolute\\". To fix this problem, ' + | ||
'make sure the container element has the CSS \'position\' ' + | ||
'property defined and the height of the element is not zero.'); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/core/test/bundling/image-directive/e2e/fill-mode/fill-mode.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,36 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {NgOptimizedImage} from '@angular/common'; | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'fill-mode-passing', | ||
standalone: true, | ||
imports: [NgOptimizedImage], | ||
template: ` | ||
<!-- Make sure an image in the fill mode has the size of a container --> | ||
<div style="position: absolute; width: 100px; height: 100px;"> | ||
<img ngSrc="/e2e/logo-500w.jpg" fill priority> | ||
</div> | ||
`, | ||
}) | ||
export class FillModePassingComponent { | ||
} | ||
@Component({ | ||
selector: 'fill-mode-failing', | ||
standalone: true, | ||
imports: [NgOptimizedImage], | ||
template: ` | ||
<div style="position: relative; width: 100%;"> | ||
<img ngSrc="/e2e/logo-500w.jpg" fill priority> | ||
</div> | ||
`, | ||
}) | ||
export class FillModeFailingComponent { | ||
} |
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