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

Account for accessibility change counts in UI #1145

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export interface Context {
testCount: number;
changeCount: number;
errorCount: number;
accessibilityChangeCount: number;
interactionTestFailuresCount: number;
inProgressCount?: number;
autoAcceptChanges: boolean;
Expand Down
13 changes: 13 additions & 0 deletions node-src/ui/messages/errors/buildHasChanges.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const context = {
build: {
number: 42,
changeCount: 2,
accessibilityChangeCount: 1,
webUrl: 'https://www.chromatic.com/build?appId=59c59bd0183bd100364e1d57&number=42',
app: {
setupUrl: 'https://www.chromatic.com/setup?appId=59c59bd0183bd100364e1d57',
Expand All @@ -19,5 +20,17 @@ const context = {

export const BuildHasChangesNotOnboarding = () => buildHasChanges(context);

export const BuildHasChangesVisualOnly = () =>
buildHasChanges({
...context,
build: { ...context.build, accessibilityChangeCount: 0 },
});

export const BuildHasChangesAccessibilityOnly = () =>
buildHasChanges({
...context,
build: { ...context.build, changeCount: 0 },
});

export const BuildHasChangesIsOnboarding = () =>
buildHasChanges({ ...context, isOnboarding: true });
21 changes: 17 additions & 4 deletions node-src/ui/messages/errors/buildHasChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@
import link from '../../components/link';

export default ({ build, exitCode, isOnboarding }) => {
const changes = pluralize('visual changes', build.changeCount, true);
const url = isOnboarding ? build.app.setupUrl : build.webUrl;

const changes: any[] = [];
if (build.changeCount > 0) {
changes.push(
chalk`${error} {bold Found ${pluralize('visual changes', build.changeCount, true)}}`
);
}
if (build.accessibilityChangeCount > 0) {
changes.push(
chalk`${error} {bold Found ${pluralize('accessibility changes', build.accessibilityChangeCount, true)}}`
);
}

Check warning on line 21 in node-src/ui/messages/errors/buildHasChanges.ts

View check run for this annotation

Codecov / codecov/patch

node-src/ui/messages/errors/buildHasChanges.ts#L18-L21

Added lines #L18 - L21 were not covered by tests

return dedent(chalk`
${error} {bold Found ${changes}}: Review the changes at ${link(
isOnboarding ? build.app.setupUrl : build.webUrl
)}
${changes.join('\n')}

Review the changes at ${link(url)}

${info} For CI/CD use cases, this command failed with exit code ${exitCode}
Pass {bold --exit-zero-on-changes} to succeed this command regardless of changes.
Expand Down
21 changes: 21 additions & 0 deletions node-src/ui/messages/info/buildPassed.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ export const BuildPassedWithChanges = () =>
number: 42,
webUrl: 'https://www.chromatic.com/build?appId=59c59bd0183bd100364e1d57&number=42',
changeCount: 2,
accessibilityChangeCount: 1,
},
} as any);

export const BuildPassedWithVisualChanges = () =>
buildPassed({
...ctx,
build: {
number: 42,
webUrl: 'https://www.chromatic.com/build?appId=59c59bd0183bd100364e1d57&number=42',
changeCount: 2,
},
} as any);

export const BuildPassedWithAccessibilityChanges = () =>
buildPassed({
...ctx,
build: {
number: 42,
webUrl: 'https://www.chromatic.com/build?appId=59c59bd0183bd100364e1d57&number=42',
accessibilityChangeCount: 1,
},
} as any);

Expand Down
20 changes: 15 additions & 5 deletions node-src/ui/messages/info/buildPassed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import { stats } from '../../tasks/snapshot';

export default (ctx: Context) => {
const { changes, snapshots, components, stories, e2eTests } = stats({ build: ctx.build });
const visualChanges = pluralize('visual changes', ctx.build.changeCount, true);
const { snapshots, components, stories, e2eTests } = stats({ build: ctx.build });

const totalChanges = (ctx.build.changeCount || 0) + (ctx.build.accessibilityChangeCount || 0);

if (ctx.isOnboarding) {
const foundString = isE2EBuild(ctx.options)
Expand All @@ -23,15 +24,24 @@
${info} Please continue setup at ${link(ctx.build.app.setupUrl)}
`);
}
return ctx.build.autoAcceptChanges && ctx.build.changeCount

const changes: any[] = [];
if (ctx.build.changeCount > 0) {
changes.push(pluralize('visual changes', ctx.build.changeCount, true));
}
if (ctx.build.accessibilityChangeCount > 0) {
changes.push(pluralize('accessibility changes', ctx.build.accessibilityChangeCount, true));
}

Check warning on line 34 in node-src/ui/messages/info/buildPassed.ts

View check run for this annotation

Codecov / codecov/patch

node-src/ui/messages/info/buildPassed.ts#L33-L34

Added lines #L33 - L34 were not covered by tests

return ctx.build.autoAcceptChanges && totalChanges > 0
? dedent(chalk`
${success} {bold Build ${ctx.build.number} passed!}
Auto-accepted ${changes}.
Auto-accepted ${pluralize('changes', totalChanges, true)}.

Check warning on line 39 in node-src/ui/messages/info/buildPassed.ts

View check run for this annotation

Codecov / codecov/patch

node-src/ui/messages/info/buildPassed.ts#L39

Added line #L39 was not covered by tests
${info} View build details at ${link(ctx.build.webUrl)}
`)
: dedent(chalk`
${success} {bold Build ${ctx.build.number} passed!}
${ctx.build.changeCount > 0 ? visualChanges : 'No visual changes'} were found in this build.
${totalChanges > 0 ? changes.join(' and ') : 'No changes'} ${pluralize('was', totalChanges, false)} found in this build.
${info} View build details at ${link(ctx.build.webUrl)}
`);
};
Loading