mattermost-mobile-upstream/app/components/attribute_chip/index.test.tsx
Pablo Vélez 4d842026f6
Some checks failed
ci / lint-typecheck (push) Has been cancelled
ci / detox-lint-typecheck (push) Has been cancelled
ci / test (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Mm 70564 channel labels use in channel creation (#10146)
* MM-70516 - Add ability to edit channel attribute values from Channel Info

* Add API methods for patching property fields and setting channel attribute requirements

* Update channel attribute clearing behavior for required and non-required fields

* MM-70564 - use channel attributes on channel creation

* Fix undefined propertyValues and ternary formatting in channel attributes

* Fix spelling of "colour" to "color" in attribute chip tests and related comments

* Add visibility checks for channel attribute labels in tests

* Fix data-integrity, permission, and accessibility issues in channel attributes: scoped pruning, atomic writes, race serialization, required clear/stale-option guards

* Fix handling of null values in apiGetChannelAttributeValue and update test assertions for channel attributes

* Improve channel attribute editor sizing for long labels, keep Save visible, and prevent keyboard overlap on Android

* Address CodeRabbit feedback for nullable values, bottom-sheet state, async validation, and reliable E2E cleanup

* lock-safe field fetch, create-time gate recheck, scoped value pruning, and tappable header chips

* Address CodeRabbit feedback: drop queued attribute saves on channel switch and use page object selectors in E2E

* Respect the ChannelAttributesRequired flag on channel creation and enable it for channel attribute E2E

* Skip required channel attribute E2E tests and stop enabling ChannelAttributesRequired on the shared server until  they move to SITE_3

* Fix clearing channel attributes on iOS by sending an empty value instead of null, and stop E2E suites from turning  off the ChannelAttributes flag mid-run

* Refactor getEmptyPropertyValue to accept string type for fieldType parameter

* E2E: give channel attribute test fields a suite-unique suffix

Pool shards may only create optional property fields named <name>_<6 hex>; fixed names were blocked by the pool guard.

* E2E: restore channel attribute cleanup checks; name network error codes

Brings back the PR's afterEach/afterAll error handling that the main merge replaced, and makes a no-response error show its codes (an AggregateError has an empty message).

* E2E: run channel attribute creation and editing specs on server B

Their 11 required-attribute tests could not run on the shared servers. Both specs now run on the mutation server with ChannelAttributesRequired on for their run, and the tests are re-enabled. setChannelAttributesRequired moves to the shared helper.

* Check header chips instead of their wrapper and use toExist for the create screen in channel attribute E2E

---------

Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
2026-10-30 15:03:55 +01:00

128 lines
4.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
import AttributeChip from './index';
const LONG_VALUE = 'UNCLASSIFIED//FOUO//NOFORN';
describe('AttributeChip', () => {
it('should always render the value as text, so color is never the only carrier of meaning', () => {
const {getByText} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value='SECRET'
color='#FF0000'
/>,
);
expect(getByText('SECRET')).toBeTruthy();
});
it('should announce the attribute alongside the value by default', () => {
const {getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value='SECRET'
testID='chip'
/>,
);
expect(getByTestId('chip.value').props.accessibilityLabel).toBe('classification: SECRET');
});
it('should announce the value alone where the label is already visible beside it', () => {
const {getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value='SECRET'
announceLabel={false}
testID='chip'
/>,
);
expect(getByTestId('chip.value').props.accessibilityLabel).toBe('SECRET');
});
it('should truncate a long value in the header, where the row budget is fixed', () => {
const {getByText, getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value={LONG_VALUE}
variant='header'
testID='chip'
/>,
);
expect(getByText('UNCLASSIFIED//F…')).toBeTruthy();
expect(getByTestId('chip.value').props.numberOfLines).toBe(1);
expect(getByTestId('chip.value').props.ellipsizeMode).toBe('tail');
});
it('should render a long value in full in a picker, where two markings can share a prefix', () => {
const {getByText, getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value={LONG_VALUE}
variant='option'
testID='chip'
/>,
);
expect(getByText(LONG_VALUE)).toBeTruthy();
// getByText alone would still pass under native single-line truncation:
// RTL renders the full text content regardless of numberOfLines, which
// only clips on a real device. The props themselves are what has to be
// absent for the option variant to actually render untruncated.
expect(getByTestId('chip.value').props.numberOfLines).toBeUndefined();
expect(getByTestId('chip.value').props.ellipsizeMode).toBeUndefined();
});
it('should announce the untruncated value even when the text is truncated', () => {
const {getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value={LONG_VALUE}
variant='header'
testID='chip'
/>,
);
expect(getByTestId('chip.value').props.accessibilityLabel).toBe(`classification: ${LONG_VALUE}`);
});
it('should fall back to the neutral treatment for a malformed color', () => {
const {getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value='SECRET'
color='not-a-color'
testID='chip'
/>,
);
// The container must not take an unparseable background: an unknown
// foreground on an unknown background is the one unreadable outcome.
const style = getByTestId('chip').props.style.flat();
expect(style.some((s: {backgroundColor?: string}) => s?.backgroundColor === 'not-a-color')).toBe(false);
});
it('should use the option color as the background when it is valid', () => {
const {getByTestId} = renderWithIntlAndTheme(
<AttributeChip
label='classification'
value='SECRET'
color='#FF0000'
testID='chip'
/>,
);
const style = getByTestId('chip').props.style.flat();
expect(style.some((s: {backgroundColor?: string}) => s?.backgroundColor === '#FF0000')).toBe(true);
});
});