Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No links to needs-review doc pages? #7007 #7133

Merged
merged 20 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/components/cards/rule-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NarrowModeStatus } from 'DetailsView/components/narrow-mode-detector';
import * as React from 'react';

import { TargetAppData } from '../../../common/types/store-data/unified-data-interface';
import { InstanceOutcomeType } from '../../../reports/components/instance-outcome-type';
import { CardRuleResult } from '../../types/store-data/card-view-model';
import { UserConfigurationStoreData } from '../../types/store-data/user-configuration-store';
import { InstanceDetailsGroup, InstanceDetailsGroupDeps } from './instance-details-group';
Expand All @@ -20,6 +21,7 @@ export type RuleContentProps = {
targetAppInfo: TargetAppData;
cardSelectionMessageCreator?: CardSelectionMessageCreator;
narrowModeStatus?: NarrowModeStatus;
outcomeType: InstanceOutcomeType;
};

export const RuleContent = NamedFC<RuleContentProps>('RuleContent', props => {
Expand Down
84 changes: 48 additions & 36 deletions src/common/components/cards/rule-resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { UnifiedRule } from 'common/types/store-data/unified-data-interface';
import { isEmpty } from 'lodash';
import * as React from 'react';

import { InstanceOutcomeType } from '../../../reports/components/instance-outcome-type';
import {
getNeedsReviewRuleResourcesUrl,
isOutcomeNeedsReview,
v-sharmachir marked this conversation as resolved.
Show resolved Hide resolved
} from '../../configs/needs-review-rule-resources';
import styles from './rule-resources.scss';

export type RuleResourcesDeps = GuidanceTagsDeps & {
Expand All @@ -17,46 +22,53 @@ export type RuleResourcesDeps = GuidanceTagsDeps & {
export type RuleResourcesProps = {
deps: RuleResourcesDeps;
rule: UnifiedRule;
outcomeType: InstanceOutcomeType;
};

export const RuleResources = NamedFC<RuleResourcesProps>('RuleResources', ({ deps, rule }) => {
if (rule.url == null && isEmpty(rule.guidance)) {
return null;
}

const renderTitle = () => (
<div className={styles.moreResourcesTitle}>Resources for this rule</div>
);

const renderRuleLink = () => {
if (rule.url == null) {
export const RuleResources = NamedFC<RuleResourcesProps>(
'RuleResources',
({ deps, rule, outcomeType }) => {
if (rule.url == null && isEmpty(rule.guidance)) {
return null;
}

const ruleId = rule.id;
const ruleUrl = rule.url;
const renderTitle = () => (
<div className={styles.moreResourcesTitle}>Resources for this rule</div>
);

const renderRuleLink = () => {
if (rule.url == null) {
return null;
}

const ruleId = rule.id;
const ruleUrl = isOutcomeNeedsReview(ruleId, outcomeType)
? getNeedsReviewRuleResourcesUrl(ruleId)
: rule.url;

return (
<span className={styles.ruleDetailsId}>
<deps.LinkComponent href={ruleUrl}>
More information about {ruleId}
</deps.LinkComponent>
</span>
);
};

const renderGuidanceLinks = () => {
return <GuidanceLinks links={rule.guidance!} LinkComponent={deps.LinkComponent} />;
};
const renderGuidanceTags = () => <GuidanceTags deps={deps} links={rule.guidance!} />;

return (
<span className={styles.ruleDetailsId}>
<deps.LinkComponent href={ruleUrl}>
More information about {ruleId}
</deps.LinkComponent>
</span>
<div className={styles.ruleMoreResources}>
{renderTitle()}
{renderRuleLink()}
<span className={styles.ruleGuidance}>
{renderGuidanceLinks()}
{renderGuidanceTags()}
</span>
</div>
);
};

const renderGuidanceLinks = () => {
return <GuidanceLinks links={rule.guidance!} LinkComponent={deps.LinkComponent} />;
};
const renderGuidanceTags = () => <GuidanceTags deps={deps} links={rule.guidance!} />;

return (
<div className={styles.ruleMoreResources}>
{renderTitle()}
{renderRuleLink()}
<span className={styles.ruleGuidance}>
{renderGuidanceLinks()}
{renderGuidanceTags()}
</span>
</div>
);
});
},
);
1 change: 1 addition & 0 deletions src/common/components/cards/rules-with-instances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const RulesWithInstances = NamedFC<RulesWithInstancesProps>(
key={`${rule.id}-rule-group`}
deps={deps}
rule={rule}
outcomeType={outcomeType}
userConfigurationStoreData={userConfigurationStoreData}
targetAppInfo={targetAppInfo}
cardSelectionMessageCreator={cardSelectionMessageCreator}
Expand Down
21 changes: 21 additions & 0 deletions src/common/configs/needs-review-rule-resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const needsReviewRuleResourcesPath =
'https://accessibilityinsights.io/info-examples/web/needs-review';

export const isOutcomeNeedsReview = (ruleId: string, outcomeType: string) => {
return needsReviewRules.includes(ruleId) && outcomeType === 'review' ? true : false;
};
v-sharmachir marked this conversation as resolved.
Show resolved Hide resolved

export const getNeedsReviewRuleResourcesUrl = (ruleId: string) => {
v-sharmachir marked this conversation as resolved.
Show resolved Hide resolved
return `${needsReviewRuleResourcesPath}/${ruleId}`;
};

const needsReviewRules = [
'aria-input-field-name',
'color-contrast',
'th-has-data-cells',
'link-in-text-block',
'p-as-heading',
];
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`RulesWithInstances renders 1`] = `
"fixInstructionProcessor": [typemoq mock object],
}
}
outcomeType="pass"
rule={
{
"description": "sample-description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('RuleResources', () => {
deps: {
LinkComponent: linkComponents[testCase.linkComponent],
} as RuleResourcesDeps,
outcomeType: 'pass',
};

const wrapper = shallow(<RuleResources {...props} />);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import {
getNeedsReviewRuleResourcesUrl,
isOutcomeNeedsReview,
} from 'common/configs/needs-review-rule-resources';

describe(getNeedsReviewRuleResourcesUrl, () => {
const ruleId = 'rule-id';

it('for ruleId passed to get NeedsReviewRuleResourcesUrl', () => {
const needsReviewRuleResourcesPath =
'https://accessibilityinsights.io/info-examples/web/needs-review';

const expectedUrl = `${needsReviewRuleResourcesPath}/${ruleId}`;

const resourceUrl = getNeedsReviewRuleResourcesUrl(ruleId);

expect(resourceUrl).toBe(expectedUrl);
});
});

describe(isOutcomeNeedsReview, () => {
const ruleId = 'color-contrast';
const outcomeType = 'review';

it('for outcome that is review and ruleId is eligble for needsReview', () => {
const expectedBoolean = true;
v-sharmachir marked this conversation as resolved.
Show resolved Hide resolved

const result = isOutcomeNeedsReview(ruleId, outcomeType);

expect(result).toBe(expectedBoolean);
});

it('for outcome that is not review and ruleId is eligble for needsReview', () => {
const otherOutcomeType = 'issue';

const expectedBoolean = false;

const result = isOutcomeNeedsReview(ruleId, otherOutcomeType);

expect(result).toBe(expectedBoolean);
});

it('for outcome that is review and ruleId is not eligble for needsReview', () => {
const otherRuleId = 'rule-id';

const expectedBoolean = false;

const result = isOutcomeNeedsReview(otherRuleId, outcomeType);

expect(result).toBe(expectedBoolean);
});

it('for outcome that is not review and ruleId is not eligble for needsReview', () => {
const otherRuleId = 'rule-id';

const otherOutcomeType = 'issue';

const expectedBoolean = false;

const result = isOutcomeNeedsReview(otherRuleId, otherOutcomeType);

expect(result).toBe(expectedBoolean);
});
});