Skip to content

Commit

Permalink
Add toast type attribute support with IDL property and default styles
Browse files Browse the repository at this point in the history
This change adds the toast type attribute and property
according to the PR on the toast explainer here:
jackbsteinberg/std-toast#49

There is still work TODO on implementing this PR,
w.r.t the showToast type option, a11y behavior for warning / error,
and default features for those types (Infinity duration, closebutton, etc)

Additionally, a follow-up CL will come out to reconfigure the current
reflection tests for type and open to use established reflection test
methodology
(ex: https://cs.chromium.org/chromium/src/third_party/blink/web_tests/wpt_internal/std-switch/tentative/form-associated-basic.js)

Bug: 972945
Change-Id: I58c7079dc4f748928eea44103dece835e549986e
  • Loading branch information
Jack Steinberg authored and chromium-wpt-export-bot committed Jul 22, 2019
1 parent df83915 commit a6fed95
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
43 changes: 42 additions & 1 deletion std-toast/attributes.html
Expand Up @@ -115,7 +115,48 @@
}, 'toggling open attribute does not start timeout');

testToastElement((toast) => {
const permitted_properties = ['constructor', 'show', 'hide', 'toggle', 'open', 'action', 'closeButton'];
const permitted_properties = ['constructor', 'show', 'hide', 'toggle', 'open', 'action', 'closeButton', 'type'];
assert_array_equals(permitted_properties.sort(), Object.getOwnPropertyNames(toast.__proto__).sort());
}, 'toast only exposes certain properties');

testToastElement((toast) => {
assert_false(toast.hasAttribute('type'));
assert_equals(toast.type, '');
}, 'default type is empty string without attribute present');

testToastElement((toast) => {
toast.type = 'warning';
assert_equals(toast.getAttribute('type'), 'warning');
assert_equals(toast.type, 'warning');
}, 'setting type property to an enumerated value changes the type attribute to that value');

testToastElement((toast) => {
toast.type = 'WaRnInG';
assert_equals(toast.getAttribute('type'), 'WaRnInG');
assert_equals(toast.type, 'warning');
}, 'setting type property to an enumerated value is case-insensitive');

testToastElement((toast) => {
toast.type = ' WaRnInG ';
assert_equals(toast.getAttribute('type'), ' WaRnInG ');
assert_equals(toast.type, '');
}, 'setting type property to an enumerated value with whitespace does not work');

testToastElement((toast) => {
toast.type = 'test';
assert_equals(toast.type, '');
assert_equals(toast.getAttribute('type'), 'test');
}, 'setting type to a non-enumerated value sets the type property to empty string');

testToastElement((toast) => {
toast.setAttribute('type', 'test');
assert_equals(toast.type, '');
assert_equals(toast.getAttribute('type'), 'test');
}, 'setting type attribute to a non-enumerated value sets the type property to empty string');

testToastElement((toast) => {
toast.type = 'info';
assert_equals(toast.type, '');
assert_equals(toast.getAttribute('type'), 'info');
}, 'info is now an invalid type, and will return empty string');
</script>
38 changes: 37 additions & 1 deletion std-toast/styles.html
Expand Up @@ -61,4 +61,40 @@

assertComputedStyleMapsEqual(toast, mockToast);
}, 'the computed style map of a closed unstyled toast is the same as a span given toast defaults');
</script>

testToastElement((toast) => {
toast.type = 'error';

const styles = window.getComputedStyle(toast);
assert_equals(styles.borderColor, 'rgb(255, 0, 0)');
}, 'changing type to error changes the border color to red');

testToastElement((toast) => {
toast.type = 'warning';

const styles = window.getComputedStyle(toast);
assert_equals(styles.borderColor, 'rgb(255, 165, 0)');
}, 'changing type to warning changes the border color to orange');

testToastElement((toast) => {
toast.type = 'success';

const styles = window.getComputedStyle(toast);
assert_equals(styles.borderColor, 'rgb(0, 128, 0)');
}, 'changing type to success changes the border color to green');

testToastElement((toast) => {
const styler = document.createElement('style');
styler.append(`
[type=error i] {
border-color: pink;
}
`);
document.querySelector('main').appendChild(styler);

toast.type = 'error';

const styles = window.getComputedStyle(toast);
assert_equals(styles.borderColor, 'rgb(255, 192, 203)');
}, 'outside styles can set type styles');
</script>

0 comments on commit a6fed95

Please sign in to comment.