This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from WordPress/support-negation-operator-in-s…
…electors Support negation operator in selectors
- Loading branch information
Showing
5 changed files
with
90 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Negation Operator</title> | ||
<meta itemprop="wp-client-side-navigation" content="active" /> | ||
</head> | ||
<body> | ||
<button | ||
data-wp-on.click="actions.toggle" | ||
data-testid="toggle active value" | ||
> | ||
Toggle Active Value | ||
</button> | ||
|
||
<div | ||
data-wp-bind.hidden="!state.active" | ||
data-testid="add hidden attribute if state is not active" | ||
></div> | ||
|
||
<div | ||
data-wp-bind.hidden="!selectors.active" | ||
data-testid="add hidden attribute if selector is not active" | ||
></div> | ||
|
||
<script defer src="../../build/e2e/negation-operator.js"></script> | ||
<script defer src="../../build/runtime.js"></script> | ||
<script defer src="../../build/vendors.js"></script> | ||
</body> | ||
</html> |
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,17 @@ | ||
import { store } from '../../src/runtime/store'; | ||
|
||
store({ | ||
selectors: { | ||
active: ({ state }) => { | ||
return state.active; | ||
}, | ||
}, | ||
state: { | ||
active: false, | ||
}, | ||
actions: { | ||
toggle: ({ state }) => { | ||
state.active = !state.active; | ||
}, | ||
}, | ||
}); |
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,31 @@ | ||
import { test, expect } from '../tests'; | ||
|
||
test.describe('negation-operator', () => { | ||
test.beforeEach(async ({ goToFile }) => { | ||
await goToFile('negation-operator.html'); | ||
}); | ||
|
||
test('add hidden attribute when !state.active', async ({ page }) => { | ||
const el = page.getByTestId( | ||
'add hidden attribute if state is not active' | ||
); | ||
|
||
await expect(el).toHaveAttribute('hidden', ''); | ||
page.getByTestId('toggle active value').click(); | ||
await expect(el).not.toHaveAttribute('hidden', ''); | ||
page.getByTestId('toggle active value').click(); | ||
await expect(el).toHaveAttribute('hidden', ''); | ||
}); | ||
|
||
test('add hidden attribute when !selectors.active', async ({ page }) => { | ||
const el = page.getByTestId( | ||
'add hidden attribute if selector is not active' | ||
); | ||
|
||
await expect(el).toHaveAttribute('hidden', ''); | ||
page.getByTestId('toggle active value').click(); | ||
await expect(el).not.toHaveAttribute('hidden', ''); | ||
page.getByTestId('toggle active value').click(); | ||
await expect(el).toHaveAttribute('hidden', ''); | ||
}); | ||
}); |
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