Skip to content

Commit

Permalink
Merge branch 'feature-8.5' into ROU-11112-checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-giulianasilva authored Jan 24, 2025
2 parents 80d4fa6 + ac4ea32 commit 66210e6
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 8 deletions.
5 changes: 4 additions & 1 deletion core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2001,4 +2001,7 @@ ion-toolbar,css-prop,--padding-end,md
ion-toolbar,css-prop,--padding-start,ios
ion-toolbar,css-prop,--padding-start,md
ion-toolbar,css-prop,--padding-top,ios
ion-toolbar,css-prop,--padding-top,md
ion-toolbar,css-prop,--padding-top,md
ion-toolbar,part,background
ion-toolbar,part,container
ion-toolbar,part,content
10 changes: 7 additions & 3 deletions core/src/components/toolbar/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import type { Color, CssClassMap, StyleEventDetail } from '../../interface';
* @slot secondary - Content is placed to the left of the toolbar text in `ios` mode, and directly to the right in `md` mode.
* @slot primary - Content is placed to the right of the toolbar text in `ios` mode, and to the far right in `md` mode.
* @slot end - Content is placed to the right of the toolbar text in LTR, and to the left in RTL.
*
* @part background - The background of the toolbar, covering the entire area behind the toolbar content.
* @part container - The container that wraps all toolbar content, including the default slot and named slot content.
* @part content - The container for the default slot, wrapping content provided without a named slot.
*/
@Component({
tag: 'ion-toolbar',
Expand Down Expand Up @@ -97,11 +101,11 @@ export class Toolbar implements ComponentInterface {
}),
}}
>
<div class="toolbar-background"></div>
<div class="toolbar-container">
<div class="toolbar-background" part="background"></div>
<div class="toolbar-container" part="container">
<slot name="start"></slot>
<slot name="secondary"></slot>
<div class="toolbar-content">
<div class="toolbar-content" part="content">
<slot></slot>
</div>
<slot name="primary"></slot>
Expand Down
10 changes: 10 additions & 0 deletions core/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { SpinnerTypes } from '../components/spinner/spinner-configs';
import type { TabButtonLayout } from '../components/tab-bar/tab-bar-interface';
import type { AnimationBuilder, Mode } from '../interface';

import type { LogLevel } from './logging';
import type { PlatformConfig } from './platform';

export interface IonicConfig {
Expand Down Expand Up @@ -220,6 +221,15 @@ export interface IonicConfig {
*/
experimentalCloseWatcher?: boolean;

/**
* Configures the logging level for Ionic Framework:
*
* - `'OFF'`: No errors or warnings are logged.
* - `'ERROR'`: Logs only errors.
* - `'WARN'`: Logs errors and warnings.
*/
logLevel?: LogLevel;

// PRIVATE configs
keyboardHeight?: number;
inputShims?: boolean;
Expand Down
22 changes: 18 additions & 4 deletions core/src/utils/logging/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import { config } from '@global/config';

export const enum LogLevel {
OFF = 'OFF',
ERROR = 'ERROR',
WARN = 'WARN',
}

/**
* Logs a warning to the console with an Ionic prefix
* to indicate the library that is warning the developer.
*
* @param message - The string message to be logged to the console.
*/
export const printIonWarning = (message: string, ...params: any[]) => {
return console.warn(`[Ionic Warning]: ${message}`, ...params);
const logLevel = config.get('logLevel', LogLevel.WARN);
if ([LogLevel.WARN].includes(logLevel)) {
return console.warn(`[Ionic Warning]: ${message}`, ...params);
}
};

/*
/**
* Logs an error to the console with an Ionic prefix
* to indicate the library that is warning the developer.
*
* @param message - The string message to be logged to the console.
* @param params - Additional arguments to supply to the console.error.
*/
export const printIonError = (message: string, ...params: any) => {
return console.error(`[Ionic Error]: ${message}`, ...params);
export const printIonError = (message: string, ...params: any[]) => {
const logLevel = config.get('logLevel', LogLevel.ERROR);
if ([LogLevel.ERROR, LogLevel.WARN].includes(logLevel)) {
return console.error(`[Ionic Error]: ${message}`, ...params);
}
};

/**
Expand Down
114 changes: 114 additions & 0 deletions core/src/utils/logging/test/logging.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { config } from '@global/config';
import { LogLevel } from '../index';

import { printIonError, printIonWarning } from '../index';

describe('Logging', () => {
describe('#printIonWarning', () => {
let consoleWarnSpy: jest.SpyInstance;

beforeEach(() => {
consoleWarnSpy = jest.spyOn(console, 'warn');
// Suppress console.warn output from polluting the test output
consoleWarnSpy.mockImplementation(() => {});
});

afterEach(() => {
consoleWarnSpy.mockRestore();
});

describe('when the logLevel configuration is not set', () => {
it('logs a warning to the console', () => {
config.set('logLevel', undefined);

printIonWarning('This is a warning message');

expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warning]: This is a warning message');
});
});

describe("when the logLevel configuration is set to 'WARN'", () => {
it('logs a warning to the console', () => {
config.set('logLevel', LogLevel.WARN);

printIonWarning('This is a warning message');

expect(consoleWarnSpy).toHaveBeenCalledWith('[Ionic Warning]: This is a warning message');
});
});

describe("when the logLevel configuration is set to 'ERROR'", () => {
it('does not log a warning to the console', () => {
config.set('logLevel', LogLevel.ERROR);

printIonWarning('This is a warning message');

expect(consoleWarnSpy).not.toHaveBeenCalled();
});
});

describe("when the logLevel configuration is set to 'OFF'", () => {
it('does not log a warning to the console', () => {
config.set('logLevel', LogLevel.OFF);

printIonWarning('This is a warning message');

expect(consoleWarnSpy).not.toHaveBeenCalled();
});
});
});

describe('#printIonError', () => {
let consoleErrorSpy: jest.SpyInstance;

beforeEach(() => {
consoleErrorSpy = jest.spyOn(console, 'error');
// Suppress console.error output from polluting the test output
consoleErrorSpy.mockImplementation(() => {});
});

afterEach(() => {
consoleErrorSpy.mockRestore();
});

describe('when the logLevel configuration is not set', () => {
it('logs an error to the console', () => {
config.set('logLevel', undefined);

printIonError('This is an error message');

expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message');
});
});

describe("when the logLevel configuration is set to 'ERROR'", () => {
it('logs an error to the console', () => {
config.set('logLevel', LogLevel.ERROR);

printIonError('This is an error message');

expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message');
});
});

describe("when the logLevel configuration is set to 'WARN'", () => {
it('logs an error to the console', () => {
config.set('logLevel', LogLevel.WARN);

printIonError('This is an error message');

expect(consoleErrorSpy).toHaveBeenCalledWith('[Ionic Error]: This is an error message');
});
});

describe("when the logLevel configuration is set to 'OFF'", () => {
it('does not log an error to the console', () => {
config.set('logLevel', LogLevel.OFF);

printIonError('This is an error message');

expect(consoleErrorSpy).not.toHaveBeenCalled();
});
});
});
});

0 comments on commit 66210e6

Please sign in to comment.