diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index 197fedb3f7..356cbc8ebd 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -980,8 +980,9 @@ export class Datetime implements ComponentInterface { } private renderFooter() { + const { showDefaultButtons, showClearButton } = this; const hasSlottedButtons = this.el.querySelector('[slot="buttons"]') !== null; - if (!hasSlottedButtons && !this.showDefaultButtons) { return; } + if (!hasSlottedButtons && !showDefaultButtons && !showClearButton) { return; } const clearButtonClick = () => { this.reset(); @@ -1004,10 +1005,10 @@ export class Datetime implements ComponentInterface { }}> - this.cancel(true)}>{this.cancelText} + {showDefaultButtons && this.cancel(true)}>{this.cancelText}}
- {this.showClearButton && clearButtonClick()}>{this.clearText}} - this.confirm(true)}>{this.doneText} + {showClearButton && clearButtonClick()}>{this.clearText}} + {showDefaultButtons && this.confirm(true)}>{this.doneText}}
diff --git a/core/src/components/datetime/test/basic/e2e.ts b/core/src/components/datetime/test/basic/e2e.ts new file mode 100644 index 0000000000..4c29a12266 --- /dev/null +++ b/core/src/components/datetime/test/basic/e2e.ts @@ -0,0 +1,87 @@ +import { newE2EPage } from '@stencil/core/testing'; +import { Datetime } from '../../datetime'; + +describe('Footer', () => { + test('should render default buttons', async () => { + const page = await newE2EPage({ + components: [Datetime], + html: '' + }); + + const cancelButton = await page.find('ion-datetime >>> #cancel-button'); + expect(cancelButton).toEqualText('Cancel'); + + const confirmButton = await page.find('ion-datetime >>> #confirm-button'); + expect(confirmButton).toEqualText('Done'); + + expect(await page.compareScreenshot()).toMatchScreenshot(); + }); + + test('should render clear button', async () => { + const page = await newE2EPage({ + components: [Datetime], + html: '' + }); + + const clearButton = await page.find('ion-datetime >>> #clear-button'); + expect(clearButton).toEqualText('Clear'); + + expect(await page.compareScreenshot()).toMatchScreenshot(); + }); + + test('should render clear and default buttons', async () => { + const page = await newE2EPage({ + components: [Datetime], + html: '' + }); + + const cancelButton = await page.find('ion-datetime >>> #cancel-button'); + expect(cancelButton).toEqualText('Cancel'); + + const confirmButton = await page.find('ion-datetime >>> #confirm-button'); + expect(confirmButton).toEqualText('Done'); + + const clearButton = await page.find('ion-datetime >>> #clear-button'); + expect(clearButton).toEqualText('Clear'); + + expect(await page.compareScreenshot()).toMatchScreenshot(); + }); + + test('should render custom buttons', async () => { + const page = await newE2EPage({ + components: [Datetime], + html: ` + + + Hello! + + + ` + }); + + const customButton = await page.find('ion-datetime #custom-button'); + expect(customButton).not.toBeNull(); + + expect(await page.compareScreenshot()).toMatchScreenshot(); + }); + + test('should render custom buttons', async () => { + const page = await newE2EPage({ + components: [Datetime], + html: ` + + + Hello! + + + ` + }); + + const customButton = await page.find('ion-datetime #custom-button'); + expect(customButton).not.toBeNull(); + + expect(await page.compareScreenshot()).toMatchScreenshot(); + }); +}); + +