mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
refactor(): minor updates for next stencil version (#20787)
This commit is contained in:
@ -19,7 +19,6 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme';
|
||||
})
|
||||
export class BackButton implements ComponentInterface, ButtonInterface {
|
||||
|
||||
mode = getIonMode(this);
|
||||
@Element() el!: HTMLElement;
|
||||
|
||||
/**
|
||||
@ -61,7 +60,7 @@ export class BackButton implements ComponentInterface, ButtonInterface {
|
||||
return icon;
|
||||
}
|
||||
|
||||
if (this.mode === 'ios') {
|
||||
if (getIonMode(this) === 'ios') {
|
||||
// default ios back button icon
|
||||
return config.get('backButtonIcon', 'chevron-back');
|
||||
}
|
||||
@ -71,7 +70,7 @@ export class BackButton implements ComponentInterface, ButtonInterface {
|
||||
}
|
||||
|
||||
get backButtonText() {
|
||||
const defaultBackButtonText = this.mode === 'ios' ? 'Back' : null;
|
||||
const defaultBackButtonText = getIonMode(this) === 'ios' ? 'Back' : null;
|
||||
return this.text != null ? this.text : config.get('backButtonText', defaultBackButtonText);
|
||||
}
|
||||
|
||||
@ -100,8 +99,9 @@ export class BackButton implements ComponentInterface, ButtonInterface {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { color, defaultHref, disabled, type, mode, hasIconOnly, backButtonIcon, backButtonText } = this;
|
||||
const { color, defaultHref, disabled, type, hasIconOnly, backButtonIcon, backButtonText } = this;
|
||||
const showBackButton = defaultHref !== undefined;
|
||||
const mode = getIonMode(this);
|
||||
|
||||
return (
|
||||
<Host
|
||||
|
@ -1,18 +1,28 @@
|
||||
import { newSpecPage } from '@stencil/core/testing';
|
||||
import { BackButton } from "../back-button";
|
||||
import { config } from "../../../global/config";
|
||||
import { setMode } from '@stencil/core';
|
||||
|
||||
|
||||
describe('back button', () => {
|
||||
let bb: BackButton;
|
||||
|
||||
beforeEach(() => {
|
||||
config.reset({});
|
||||
bb = new BackButton();
|
||||
});
|
||||
|
||||
const newBackButton = async (mode: string = 'md'): Promise<BackButton> => {
|
||||
setMode(() => mode);
|
||||
const { rootInstance } = await newSpecPage({
|
||||
components: [BackButton],
|
||||
html: `<ion-back-button></ion-back-button>`
|
||||
})
|
||||
return rootInstance;
|
||||
};
|
||||
|
||||
|
||||
describe('backButtonIcon', () => {
|
||||
|
||||
it('set custom icon on the instance, override config', () => {
|
||||
it('set custom icon on the instance, override config', async () => {
|
||||
const bb = await newBackButton();
|
||||
bb.icon = 'custom-icon-instance';
|
||||
config.reset({
|
||||
backButtonIcon: 'custom-icon-config'
|
||||
@ -20,24 +30,27 @@ describe('back button', () => {
|
||||
expect(bb.backButtonIcon).toBe('custom-icon-instance');
|
||||
});
|
||||
|
||||
it('set custom icon in the config', () => {
|
||||
it('set custom icon in the config', async () => {
|
||||
const bb = await newBackButton();
|
||||
config.reset({
|
||||
backButtonIcon: 'custom-icon-config'
|
||||
});
|
||||
expect(bb.backButtonIcon).toBe('custom-icon-config');
|
||||
});
|
||||
|
||||
it('set custom icon on the instance', () => {
|
||||
it('set custom icon on the instance', async () => {
|
||||
const bb = await newBackButton();
|
||||
bb.icon = 'custom-icon-instance';
|
||||
expect(bb.backButtonIcon).toBe('custom-icon-instance');
|
||||
});
|
||||
|
||||
it('default icon for ios mode', () => {
|
||||
bb.mode = 'ios';
|
||||
it('default icon for ios mode', async () => {
|
||||
const bb = await newBackButton('ios');
|
||||
expect(bb.backButtonIcon).toBe('chevron-back');
|
||||
});
|
||||
|
||||
it('default icon', () => {
|
||||
it('default icon', async () => {
|
||||
const bb = await newBackButton();
|
||||
expect(bb.backButtonIcon).toBe('arrow-back-sharp');
|
||||
});
|
||||
|
||||
@ -45,12 +58,13 @@ describe('back button', () => {
|
||||
|
||||
describe('backButtonText', () => {
|
||||
|
||||
it('default text for ios mode', () => {
|
||||
bb.mode = 'ios';
|
||||
it('default text for ios mode', async () => {
|
||||
const bb = await newBackButton('ios');
|
||||
expect(bb.backButtonText).toBe('Back');
|
||||
});
|
||||
|
||||
it('default text', () => {
|
||||
it('default text', async () => {
|
||||
const bb = await newBackButton();
|
||||
expect(bb.backButtonText).toBe(null);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user