Skip to content

Commit

Permalink
changes as per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SriHV committed Jan 14, 2025
1 parent 7e1b809 commit 37b6ab2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/message-list/_macro-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| fromLabel | string | true | The visually hidden screen reader “From” prefix for each message metadata information |
| dateLabel | string | true | The visually hidden screen reader “Sent” prefix for each message metadata information |
| hiddenReadLabel | string | true | The visually hidden screen reader “Read the message” prefix for each visually hidden link to the message conversation thread |
| bodyLabel | string | true | (NEW) The visually hidden screen reader "body" prefix for message body |
| bodyLabel | string | false | (NEW) The visually hidden screen reader "body" prefix for message body |
| messages | `Array<Message>` | true | Settings for each [message item](#message) |

## Message
Expand Down
5 changes: 3 additions & 2 deletions src/components/message-list/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
{{ message.dateText }}
</dd>
<dt class="ons-message-item__metadata-term ons-message-item__metadata-term--body ons-u-vh">
{% if params.ariaLabelMsg %}
{% if params.ariaLabelMsg and not params.bodyLabel %}
{{ params.ariaLabelMsg | default("Message text") }}:
{% else %}
{{ params.bodyLabel | default("Message text") }}:
{% endif %}
{{ params.bodyLabel | default("Message text") }}:
</dt>
<dd class="ons-message-item__metadata-value ons-message-item__metadata-value--body ons-u-fs-r ons-u-mt-s">
{{ message.body | safe }}
Expand Down
73 changes: 63 additions & 10 deletions src/components/message-list/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,45 @@ const EXAMPLE_MESSAGE_LIST = {
ariaLabelMetaData: 'Message information',
};

const EXAMPLE_MESSAGE_LIST_WITH_DEPRECATED_ariaLabelMsg_PARAM = {
...EXAMPLE_MESSAGE_LIST_MINIMAL,
ariaLabelMsg: 'Message Preview',
const EXAMPLE_MESSAGE_LIST_WITH_DEPRECATED_ARIALABELMSG_PARAM = {
unreadText: 'New',
fromLabel: 'From',
dateLabel: 'Date',
hiddenReadLabel: 'Read the message',
ariaLabelMsg: 'Aria Label Msg Preview',
messages: [
{
id: 'message1',
unread: true,
subject: {
url: 'https://example.com/message/1',
text: 'Example message subject',
},
fromText: 'Example Sender 1',
dateText: 'Tue 4 Jul 2020 at 7:47',
body: 'An example message.',
},
],
};

const EXAMPLE_MESSAGE_LIST_WIHTOUT_BODYLABEL_PARAM = {
unreadText: 'New',
fromLabel: 'From',
dateLabel: 'Date',
hiddenReadLabel: 'Read the message',
messages: [
{
id: 'message1',
unread: true,
subject: {
url: 'https://example.com/message/1',
text: 'Example message subject',
},
fromText: 'Example Sender 1',
dateText: 'Tue 4 Jul 2020 at 7:47',
body: 'An example message.',
},
],
};

describe('macro: message-list', () => {
Expand Down Expand Up @@ -97,22 +133,39 @@ describe('macro: message-list', () => {
expect($('.ons-message-item__metadata-term--date:first').text().trim()).toBe('Date:');
});

it('has visually hidden label `bodyLabel`', () => {
it('has visually hidden label `hiddenReadLabel`', () => {
const $ = cheerio.load(renderComponent('message-list', EXAMPLE_MESSAGE_LIST_MINIMAL));

expect($('.ons-message-item__metadata-term--body:first').text().trim()).toBe('Body:');
expect($('.ons-message-item__link:first').text()).toContain('Read the message: ');
});

it('has visually hidden label `hiddenReadLabel`', () => {
it('has visually hidden label `bodyLabel` when only `bodyLabel` is provided`', () => {
const $ = cheerio.load(renderComponent('message-list', EXAMPLE_MESSAGE_LIST_MINIMAL));

expect($('.ons-message-item__link:first').text()).toContain('Read the message: ');
expect($('.ons-message-item__metadata-term--body:first').text().trim()).toBe('Body:');
});

it('has visually hidden label `bodyLabel` when both `bodyLabel` and `ariaLabelMsg` are provided`', () => {
const $ = cheerio.load(
renderComponent('message-list', {
...EXAMPLE_MESSAGE_LIST_MINIMAL,
ariaLabelMsg: 'Aria Label Msg Preview',
}),
);

expect($('.ons-message-item__metadata-term--body:first').text().trim()).toBe('Body:');
});

it('has visually hidden deprecated label `ariaLabelMsg` when only `ariaLabelMsg` is provided', () => {
const $ = cheerio.load(renderComponent('message-list', EXAMPLE_MESSAGE_LIST_WITH_DEPRECATED_ARIALABELMSG_PARAM));

expect($('.ons-message-item__metadata-term--body:first').text().trim()).toBe('Aria Label Msg Preview:');
});

it('has visually hidden deprecated label `ariaLabelMsg`', () => {
const $ = cheerio.load(renderComponent('message-list', EXAMPLE_MESSAGE_LIST_WITH_DEPRECATED_ariaLabelMsg_PARAM));
it('has the defualt text for visually hidden label `bodyLabel` when both `bodyLabel` and `ariaLabelMsg` are not provided', () => {
const $ = cheerio.load(renderComponent('message-list', EXAMPLE_MESSAGE_LIST_WIHTOUT_BODYLABEL_PARAM));

expect($('.ons-message-item__metadata-term--body:first').text().trim()).toContain('Message Preview:');
expect($('.ons-message-item__metadata-term--body:first').text().trim()).toBe('Message text:');
});

it('has message as expected', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"fromLabel": "From",
"dateLabel": "Sent",
"hiddenReadLabel": "Read the message",
"bodyLabel": 'Message Preview',
"ariaLabelMetaData": "Message information",
"messages": [
{
Expand Down

0 comments on commit 37b6ab2

Please sign in to comment.