@contentful/field-editor-slug 2.2.2-canary.2 → 2.2.3-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
7
7
  const _react1 = require("@testing-library/react");
8
8
  require("@testing-library/jest-dom/extend-expect");
9
9
  const _SlugEditor = require("./SlugEditor");
10
+ const _SlugEditorField = require("./SlugEditorField");
10
11
  function _getRequireWildcardCache(nodeInterop) {
11
12
  if (typeof WeakMap !== "function") return null;
12
13
  var cacheBabelInterop = new WeakMap();
@@ -303,6 +304,26 @@ describe('SlugEditor', ()=>{
303
304
  expect(getByTestId('cf-ui-text-input')).not.toHaveAttribute('aria-invalid');
304
305
  });
305
306
  });
307
+ it('shows error and hides warning for duplicate slug when publish sets hasError', async ()=>{
308
+ const performUniqueCheck = jest.fn().mockResolvedValue(false);
309
+ const setValue = jest.fn();
310
+ const { queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_SlugEditorField.SlugEditorFieldStatic, {
311
+ hasError: true,
312
+ isUniqueValidationEnabled: false,
313
+ isOptionalLocaleWithFallback: false,
314
+ isDisabled: false,
315
+ value: "slug-value",
316
+ locale: "en-US",
317
+ titleValue: "Slug value",
318
+ createdAt: "2020-01-24T15:33:47.906Z",
319
+ setValue: setValue,
320
+ performUniqueCheck: performUniqueCheck
321
+ }));
322
+ await (0, _react1.waitFor)(()=>{
323
+ expect(queryByTestId('slug-editor-duplicate-error')).toBeInTheDocument();
324
+ expect(queryByTestId('slug-editor-duplicate-warning')).not.toBeInTheDocument();
325
+ });
326
+ });
306
327
  });
307
328
  describe('should react to title changes', ()=>{
308
329
  it('when field is disabled', async ()=>{
@@ -114,7 +114,8 @@ function SlugEditorFieldStatic(props) {
114
114
  const { hasError, isDisabled, value, setValue, onChange, onBlur, isUniqueValidationEnabled, id } = props;
115
115
  const status = useUniqueChecker(props);
116
116
  const hasDuplicate = status === 'duplicate';
117
- const shouldShowDuplicateAsError = hasDuplicate && isUniqueValidationEnabled;
117
+ const shouldShowDuplicateAsError = hasDuplicate && (isUniqueValidationEnabled || hasError);
118
+ const shouldShowDuplicateAsWarning = hasDuplicate && !shouldShowDuplicateAsError;
118
119
  return /*#__PURE__*/ _react.createElement("div", {
119
120
  className: _styles.inputContainer
120
121
  }, /*#__PURE__*/ _react.createElement(_f36icons.LinkSimpleIcon, {
@@ -140,13 +141,13 @@ function SlugEditorFieldStatic(props) {
140
141
  className: _styles.spinnerContainer
141
142
  }, /*#__PURE__*/ _react.createElement(_f36components.Spinner, {
142
143
  testId: "slug-editor-spinner"
143
- })), hasDuplicate && isUniqueValidationEnabled && /*#__PURE__*/ _react.createElement(_f36components.ValidationMessage, {
144
+ })), shouldShowDuplicateAsError && /*#__PURE__*/ _react.createElement(_f36components.ValidationMessage, {
144
145
  testId: "slug-editor-duplicate-error",
145
146
  className: _styles.uniqueValidationError
146
147
  }, _core.i18n._({
147
148
  id: "FieldEditors.Slug.SlugEditorField.DuplicateSlugError",
148
149
  message: "This slug has already been published in another entry"
149
- })), hasDuplicate && !isUniqueValidationEnabled && /*#__PURE__*/ _react.createElement(_f36note.Note, {
150
+ })), shouldShowDuplicateAsWarning && /*#__PURE__*/ _react.createElement(_f36note.Note, {
150
151
  variant: "warning",
151
152
  testId: "slug-editor-duplicate-warning",
152
153
  className: _styles.uniqueValidationError
@@ -3,6 +3,7 @@ import { createFakeFieldAPI, createFakeLocalesAPI } from '@contentful/field-edit
3
3
  import { cleanup, configure, fireEvent, render, waitFor } from '@testing-library/react';
4
4
  import '@testing-library/jest-dom/extend-expect';
5
5
  import { SlugEditor } from './SlugEditor';
6
+ import { SlugEditorFieldStatic } from './SlugEditorField';
6
7
  configure({
7
8
  testIdAttribute: 'data-test-id'
8
9
  });
@@ -258,6 +259,26 @@ describe('SlugEditor', ()=>{
258
259
  expect(getByTestId('cf-ui-text-input')).not.toHaveAttribute('aria-invalid');
259
260
  });
260
261
  });
262
+ it('shows error and hides warning for duplicate slug when publish sets hasError', async ()=>{
263
+ const performUniqueCheck = jest.fn().mockResolvedValue(false);
264
+ const setValue = jest.fn();
265
+ const { queryByTestId } = render(/*#__PURE__*/ React.createElement(SlugEditorFieldStatic, {
266
+ hasError: true,
267
+ isUniqueValidationEnabled: false,
268
+ isOptionalLocaleWithFallback: false,
269
+ isDisabled: false,
270
+ value: "slug-value",
271
+ locale: "en-US",
272
+ titleValue: "Slug value",
273
+ createdAt: "2020-01-24T15:33:47.906Z",
274
+ setValue: setValue,
275
+ performUniqueCheck: performUniqueCheck
276
+ }));
277
+ await waitFor(()=>{
278
+ expect(queryByTestId('slug-editor-duplicate-error')).toBeInTheDocument();
279
+ expect(queryByTestId('slug-editor-duplicate-warning')).not.toBeInTheDocument();
280
+ });
281
+ });
261
282
  });
262
283
  describe('should react to title changes', ()=>{
263
284
  it('when field is disabled', async ()=>{
@@ -55,7 +55,8 @@ export function SlugEditorFieldStatic(props) {
55
55
  const { hasError, isDisabled, value, setValue, onChange, onBlur, isUniqueValidationEnabled, id } = props;
56
56
  const status = useUniqueChecker(props);
57
57
  const hasDuplicate = status === 'duplicate';
58
- const shouldShowDuplicateAsError = hasDuplicate && isUniqueValidationEnabled;
58
+ const shouldShowDuplicateAsError = hasDuplicate && (isUniqueValidationEnabled || hasError);
59
+ const shouldShowDuplicateAsWarning = hasDuplicate && !shouldShowDuplicateAsError;
59
60
  return /*#__PURE__*/ React.createElement("div", {
60
61
  className: styles.inputContainer
61
62
  }, /*#__PURE__*/ React.createElement(LinkSimpleIcon, {
@@ -81,13 +82,13 @@ export function SlugEditorFieldStatic(props) {
81
82
  className: styles.spinnerContainer
82
83
  }, /*#__PURE__*/ React.createElement(Spinner, {
83
84
  testId: "slug-editor-spinner"
84
- })), hasDuplicate && isUniqueValidationEnabled && /*#__PURE__*/ React.createElement(ValidationMessage, {
85
+ })), shouldShowDuplicateAsError && /*#__PURE__*/ React.createElement(ValidationMessage, {
85
86
  testId: "slug-editor-duplicate-error",
86
87
  className: styles.uniqueValidationError
87
88
  }, $_i18n._({
88
89
  id: "FieldEditors.Slug.SlugEditorField.DuplicateSlugError",
89
90
  message: "This slug has already been published in another entry"
90
- })), hasDuplicate && !isUniqueValidationEnabled && /*#__PURE__*/ React.createElement(Note, {
91
+ })), shouldShowDuplicateAsWarning && /*#__PURE__*/ React.createElement(Note, {
91
92
  variant: "warning",
92
93
  testId: "slug-editor-duplicate-warning",
93
94
  className: styles.uniqueValidationError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-slug",
3
- "version": "2.2.2-canary.2+4797c8d5",
3
+ "version": "2.2.3-canary.0+bb4ffc6b",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "registry": "https://npm.pkg.github.com/"
61
61
  },
62
- "gitHead": "4797c8d502ae3dc55e22bf12f5aef2762f010a09"
62
+ "gitHead": "bb4ffc6b56516966c6dcfd8b7f24f9ca58196a86"
63
63
  }