test(tabs, tab-bar, tab-button): migrate to generators (#27356)

Issue number: N/A

---------

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Tabs, tab bar, and tab button are using legacy syntax

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Tabs, tab bar, and tab button are using modern syntax


962754d094

- A translucent screenshot test was written in `tab-bar/test/basic` but
it is already being tested in `tab-bar/test/translucent`, so I deleted
the duplicate test/screenshots.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
This commit is contained in:
Liam DeBeasi
2023-05-03 11:51:48 -04:00
committed by GitHub
parent b1369a94ae
commit ce0767bbb0
116 changed files with 401 additions and 393 deletions

View File

@ -1,32 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('tab-bar: basic', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
skip.mode('md', 'Translucent is only available in iOS mode');
});
test('should render tab bar', async ({ page }) => {
await page.setContent(`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-label>Favorites</ion-label>
<ion-badge>23</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-bar-basic-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -1,15 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('tab-bar: custom', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
});
test('should render custom tab bar', async ({ page }) => {
await page.goto('/src/components/tab-bar/test/custom');
const tabBar = page.locator('ion-tab-bar.custom-all');
await expect(tabBar).toHaveScreenshot(`tab-bar-custom-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,14 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('tab-bar: custom'), () => {
test('should render custom tab bar', async ({ page }) => {
await page.goto('/src/components/tab-bar/test/custom', config);
const tabBar = page.locator('ion-tab-bar.custom-all');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-bar-custom`));
});
});
});

View File

@ -1,37 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('tab-bar: translucent', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
skip.mode('md', 'Translucent is only available in iOS mode');
skip.browser('firefox', 'Firefox does not support translucent effect');
});
test('should render translucent tab bar', async ({ page }) => {
await page.setContent(`
<style>
body {
background: linear-gradient(to right, orange, yellow, green, cyan, blue, violet);
}
</style>
<ion-tab-bar translucent="true" selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Recents</ion-label>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-label>Favorites</ion-label>
<ion-badge>23</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-bar-translucent-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,43 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
/**
* Translucent is only available in iOS mode
*/
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('tab-bar: translucent'), () => {
test.beforeEach(({ skip }) => {
skip.browser('firefox', 'Firefox does not support translucent effect');
});
test('should render translucent tab bar', async ({ page }) => {
await page.setContent(
`
<style>
body {
background: linear-gradient(to right, orange, yellow, green, cyan, blue, violet);
}
</style>
<ion-tab-bar translucent="true" selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Recents</ion-label>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-label>Favorites</ion-label>
<ion-badge>23</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-bar-translucent`));
});
});
});

View File

@ -1,13 +0,0 @@
import AxeBuilder from '@axe-core/playwright';
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('tab-button: a11y', () => {
test('should not have any axe violations', async ({ page }) => {
await page.goto('/src/components/tab-button/test/a11y');
// TODO FW-3604
const results = await new AxeBuilder({ page }).disableRules('color-contrast').analyze();
expect(results.violations).toEqual([]);
});
});

View File

@ -0,0 +1,15 @@
import AxeBuilder from '@axe-core/playwright';
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs().forEach(({ title, config }) => {
test.describe(title('tab-button: a11y'), () => {
test('should not have any axe violations', async ({ page }) => {
await page.goto('/src/components/tab-button/test/a11y', config);
// TODO FW-3604
const results = await new AxeBuilder({ page }).disableRules('color-contrast').analyze();
expect(results.violations).toEqual([]);
});
});
});

View File

@ -1,85 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('tab-button: basic', () => {
test('should render tab button with label', async ({ page }) => {
await page.setContent(`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Recents</ion-label>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-label>Favorites</ion-label>
<ion-badge>23</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-label-${page.getSnapshotSettings()}.png`);
});
test('should render tab button with badges', async ({ page }) => {
await page.setContent(`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-icon name="heart"></ion-icon>
<ion-label>Favorites</ion-label>
<ion-badge color="danger"></ion-badge>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="4">
<ion-icon name="calendar"></ion-icon>
<ion-badge color="danger">47</ion-badge>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-badge-${page.getSnapshotSettings()}.png`);
});
test('should render tab button with icons', async ({ page }) => {
await page.setContent(`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-icon name="heart"></ion-icon>
<ion-label>Favorites</ion-label>
<ion-badge color="danger"></ion-badge>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="4">
<ion-icon name="calendar"></ion-icon>
<ion-badge color="danger">47</ion-badge>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-badge-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,96 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs().forEach(({ title, screenshot, config }) => {
test.describe(title('tab-button: basic'), () => {
test('should render tab button with label', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Recents</ion-label>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-label>Favorites</ion-label>
<ion-badge>23</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-label`));
});
test('should render tab button with badges', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-icon name="heart"></ion-icon>
<ion-label>Favorites</ion-label>
<ion-badge color="danger"></ion-badge>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="4">
<ion-icon name="calendar"></ion-icon>
<ion-badge color="danger">47</ion-badge>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-badge`));
});
test('should render tab button with icons', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar selected-tab="1">
<ion-tab-button tab="1">
<ion-icon name="heart"></ion-icon>
<ion-label>Favorites</ion-label>
<ion-badge color="danger"></ion-badge>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-icon name="musical-note"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-icon name="today"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="4">
<ion-icon name="calendar"></ion-icon>
<ion-badge color="danger">47</ion-badge>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-badge`));
});
});
});

View File

@ -1,133 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('tab-button: basic', () => {
test('should render tab button with icons left of text', async ({ page }) => {
await page.setContent(`
<ion-tab-bar color="light" selected-tab="1">
<ion-tab-button tab="1" layout="icon-start">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
<ion-badge color="danger">12</ion-badge>
</ion-tab-button>
<ion-tab-button tab="2" layout="icon-start">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-start">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-icon-left-${page.getSnapshotSettings()}.png`);
});
test('should render tab button with icons right of text', async ({ page }) => {
await page.setContent(`
<ion-tab-bar color="danger" selected-tab="1">
<ion-tab-button tab="1" layout="icon-end">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2" layout="icon-end">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
<ion-badge color="dark">33</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-end">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-icon-right-${page.getSnapshotSettings()}.png`);
});
test('should render tab button with icons below text', async ({ page }) => {
await page.setContent(`
<ion-tab-bar color="dark" selected-tab="1">
<ion-tab-button tab="1" layout="icon-bottom">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-badge>16</ion-badge>
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-bottom">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-icon-below-${page.getSnapshotSettings()}.png`);
});
test('should render tab button with icons on top of text', async ({ page }) => {
await page.setContent(`
<ion-tab-bar color="secondary" selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Location</ion-label>
<ion-icon name="navigate"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-badge color="danger">44</ion-badge>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Radio</ion-label>
<ion-icon name="musical-notes"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-icon-top-${page.getSnapshotSettings()}.png`);
});
test('should render tab button with no icons', async ({ page }) => {
await page.setContent(`
<ion-tab-bar color="primary" selected-tab="1">
<ion-tab-button tab="1" layout="icon-hide">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2" layout="icon-hide">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-hide">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
<ion-badge color="danger">2</ion-badge>
</ion-tab-button>
</ion-tab-bar>
`);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(`tab-button-no-icon-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,150 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs().forEach(({ title, screenshot, config }) => {
test.describe(title('tab-button: basic'), () => {
test('should render tab button with icons left of text', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar color="light" selected-tab="1">
<ion-tab-button tab="1" layout="icon-start">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
<ion-badge color="danger">12</ion-badge>
</ion-tab-button>
<ion-tab-button tab="2" layout="icon-start">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-start">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-icon-left`));
});
test('should render tab button with icons right of text', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar color="danger" selected-tab="1">
<ion-tab-button tab="1" layout="icon-end">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2" layout="icon-end">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
<ion-badge color="dark">33</ion-badge>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-end">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-icon-right`));
});
test('should render tab button with icons below text', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar color="dark" selected-tab="1">
<ion-tab-button tab="1" layout="icon-bottom">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-badge>16</ion-badge>
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-bottom">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-icon-below`));
});
test('should render tab button with icons on top of text', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar color="secondary" selected-tab="1">
<ion-tab-button tab="1">
<ion-label>Location</ion-label>
<ion-icon name="navigate"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2">
<ion-badge color="danger">44</ion-badge>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3">
<ion-label>Radio</ion-label>
<ion-icon name="musical-notes"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-icon-top`));
});
test('should render tab button with no icons', async ({ page }) => {
await page.setContent(
`
<ion-tab-bar color="primary" selected-tab="1">
<ion-tab-button tab="1" layout="icon-hide">
<ion-label>Recents</ion-label>
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="2" layout="icon-hide">
<ion-label>Favorites</ion-label>
<ion-icon name="heart"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="3" layout="icon-hide">
<ion-label>Settings</ion-label>
<ion-icon name="settings"></ion-icon>
<ion-badge color="danger">2</ion-badge>
</ion-tab-button>
</ion-tab-bar>
`,
config
);
const tabBar = page.locator('ion-tab-bar');
await expect(tabBar).toHaveScreenshot(screenshot(`tab-button-no-icon`));
});
});
});

Some files were not shown because too many files have changed in this diff Show More