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

imports actualized #1338

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

TeterinaSvetlana
Copy link
Contributor

@TeterinaSvetlana TeterinaSvetlana commented Apr 1, 2022

#1337

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new attribute phone1IsRequired to enhance validation logic for phone number input.
  • Bug Fixes

    • Updated logging methods to utilize native console methods, improving error handling and logging consistency.
  • Refactor

    • Streamlined import statements across various components and services for improved clarity and modularity.
  • Documentation

    • Updated translation strings to reflect changes in logging methods.

These updates enhance the application's functionality, improve code maintainability, and ensure a more consistent user experience.

@TeterinaSvetlana TeterinaSvetlana changed the base branch from feature-ember-update to develop October 23, 2024 10:18
Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request involve several updates across different files, primarily focusing on improving import statements by replacing broad imports from the Ember namespace with specific imports from respective Ember modules. Notable modifications include the replacement of Ember.uuid() with a new utility function generateUniqueId for generating unique identifiers, as well as a shift from using Ember.Logger to native console methods for logging. Additionally, a new property phone1IsRequired was added to a model, enhancing its validation logic.

Changes

File Path Change Summary
addon/components/flexberry-file.js Replaced Ember.uuid() with generateUniqueId() for unique ID generation in _fileInputId.
addon/components/flexberry/validation-summary.js Replaced broad import of Ember with specific imports for Component and computed.
addon/services/compatibility-validations.js Replaced broad import of Ember with specific imports for Service, set, and getOwner.
addon/services/log.js Replaced Ember.Logger methods with native console methods for logging.
tests/acceptance/components/flexberry-groupedit/flexberry-groupedit-sort-test.js Updated imports to use specific modules and replaced Ember.A() with A().
tests/acceptance/components/flexberry-objectlistview/folv-user-settings-test.js Replaced Ember.set and Ember.run with specific imports for set and run.
tests/dummy/app/controllers/log-service-examples/settings-example.js Removed Ember.generateGuid and used generateUniqueId() instead.
tests/dummy/app/locales/en/translations.js Updated logging messages to use console methods instead of Ember logging methods.
tests/dummy/app/locales/ru/translations.js Updated Russian logging messages to use console methods instead of Ember logging methods.
tests/dummy/app/models/ember-flexberry-dummy-application-user.js Added new property phone1IsRequired to enhance validation logic for phone1.
tests/integration/components/flexberry/validation-summary-test.js Updated imports to use specific modules for A and run.
tests/unit/services/compatibility-validations-test.js Replaced import of get from Ember with direct import from @ember/object.
tests/unit/services/device-test.js Updated import of getOwner to use specific import from @ember/application.
tests/unit/services/user-settings-test.js Updated import of getOwner and modified stubs to use the new import.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FlexberryFileComponent
    participant UniqueIdGenerator

    User->>FlexberryFileComponent: Interacts with file input
    FlexberryFileComponent->>UniqueIdGenerator: Request unique ID
    UniqueIdGenerator-->>FlexberryFileComponent: Return unique ID
    FlexberryFileComponent-->>User: Display file input with unique ID
Loading

🐇 "In the code where rabbits hop,
Unique IDs now never stop!
With logs that console, clear and bright,
Our functions now take flight!
A phone check here, a tweak so neat,
Our code's now fast, oh what a treat!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Outside diff range and nitpick comments (11)
addon/services/compatibility-validations.js (1)

5-7: LGTM with minor spacing issue.

The migration to specific Ember imports is correct, but there's an extra space after 'from' in line 5.

-import Service from  '@ember/service';
+import Service from '@ember/service';
tests/unit/services/user-settings-test.js (2)

Line range hint 10-17: Fix inconsistent usage of getOwner stub.

There's an inconsistency between the stub creation and restoration. The beforeEach uses Ember.getOwner while the afterEach uses the imported getOwner.

Apply this diff to maintain consistency:

  beforeEach() {
-   sinon.stub(Ember, 'getOwner').returns(
+   sinon.stub(getOwner).returns(
      {
      resolveRegistration: () =>({ APP: { components: { flexberryObjectlistview: { defaultPerPage: 5 } } } }),
      factoryFor: () =>({ class: { APP: {} }})
      })
  },
  afterEach() {
     getOwner.restore();
  }

Also, consider fixing the indentation in the stub configuration for better readability:

  beforeEach() {
    sinon.stub(getOwner).returns({
      resolveRegistration: () => ({
        APP: {
          components: {
            flexberryObjectlistview: {
              defaultPerPage: 5
            }
          }
        }
      }),
      factoryFor: () => ({
        class: {
          APP: {}
        }
      })
    })
  },

4-4: Consider removing unused Ember import.

After updating the getOwner usage, the Ember import appears to be unused and can be removed.

-import Ember from 'ember';
tests/integration/components/flexberry/validation-summary-test.js (1)

1-2: Consider grouping related imports together.

For better organization, consider grouping the Ember-related imports together. This makes the imports more maintainable and easier to scan.

-import { A } from '@ember/array';
-import { run } from '@ember/runloop';
import { moduleForComponent, test } from 'ember-qunit';
+import { A } from '@ember/array';
+import { run } from '@ember/runloop';
import hbs from 'htmlbars-inline-precompile';
tests/unit/services/device-test.js (1)

Migration needed: Replace Ember.getOwner with imported getOwner in user-settings.js

The verification has revealed an inconsistency in addon/services/user-settings.js:

  • The file imports getOwner from @ember/application
  • But still uses the deprecated Ember.getOwner syntax

This needs to be updated to use the imported getOwner directly, similar to the change being made in the test file.

🔗 Analysis chain

Line range hint 1-14: Verify the impact of getOwner changes

Let's verify that there are no other instances of Ember.getOwner usage in the codebase that should be updated as part of this migration.


Let me check the specific usage of Ember.getOwner in the identified file to ensure we provide accurate guidance.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of Ember.getOwner
echo "Checking for remaining Ember.getOwner usage:"
rg "Ember\.getOwner" -l

# Search for imported getOwner usage to verify consistency
echo -e "\nChecking current getOwner import patterns:"
rg "import.*getOwner.*from '@ember/application'" -l

Length of output: 1145


Script:

#!/bin/bash
# Check the specific usage of Ember.getOwner in user-settings.js
echo "Checking Ember.getOwner usage in user-settings.js:"
rg "Ember\.getOwner" -A 3 -B 3 "addon/services/user-settings.js"

# Check if getOwner is also imported in the same file
echo -e "\nChecking getOwner import in the same file:"
rg "import.*getOwner" "addon/services/user-settings.js"

Length of output: 654

tests/dummy/app/controllers/log-service-examples/settings-example.js (2)

Line range hint 1-254: Update method names to reflect console-based logging.

Since Ember.Logger is being replaced with native console methods, the button action names should be updated to reflect this change:

-      buttonName: this.get('i18n').t('forms.log-service-examples.settings-example.ember-logger-error-button-caption'),
-      buttonAction: 'onEmberLoggerErrorButtonClick',
+      buttonName: this.get('i18n').t('forms.log-service-examples.settings-example.console-error-button-caption'),
+      buttonAction: 'onConsoleErrorButtonClick',

// Similar changes for other logger-related button actions

Remember to update the corresponding method names and i18n translations.


Based on the gathered information, I can now provide a final response:

Ember.Logger usage needs to be updated to modern logging approach

The codebase shows inconsistent logging patterns that need to be addressed:

  • The file under review (settings-example.js) still uses deprecated Ember.Logger methods
  • The log service (addon/services/log.js) has already migrated to using console methods directly (console.warn, console.log, etc.)
  • The CHANGELOG indicates a previous migration from Ember.Logger.xxx to Ember.xxx

Required changes:

  • Replace Ember.Logger.error with console.error
  • Replace Ember.Logger.warn with console.warn
  • Replace Ember.Logger.log with console.log
  • Replace Ember.Logger.info with console.info
  • Replace Ember.Logger.debug with console.debug

The changes should maintain consistency with the logging service implementation in addon/services/log.js which has already been modernized.

🔗 Analysis chain

Line range hint 1-254: Verify consistency of logging approach across the codebase.

Let's ensure the logging changes are consistent across the codebase.


Let me analyze the results and gather more specific information about the Ember.Logger usage to provide a concrete recommendation.

Let's see the actual implementation details to understand if there's a migration pattern we need to follow or if there are inconsistencies that need to be addressed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining Ember.Logger usage and verify logging approach consistency

# Test 1: Check for remaining Ember.Logger usage
echo "Checking for remaining Ember.Logger usage..."
rg "Ember\.Logger\." -l

# Test 2: Check for console logging patterns
echo "Checking for console logging patterns..."
rg "console\.(error|warn|info|log|debug)" -l

# Test 3: Check for generateUniqueId usage
echo "Checking for generateUniqueId usage patterns..."
rg "generateUniqueId" -l

Length of output: 2793


Script:

#!/bin/bash
# Get detailed context of remaining Ember.Logger usage

echo "Checking Ember.Logger usage in addon/services/log.js..."
rg "Ember\.Logger\." -A 3 -B 3 addon/services/log.js

echo -e "\nChecking Ember.Logger usage in tests/unit/services/log-test.js..."
rg "Ember\.Logger\." -A 3 -B 3 tests/unit/services/log-test.js

echo -e "\nChecking CHANGELOG.md for Logger-related changes..."
rg "Logger" -A 3 -B 3 CHANGELOG.md

Length of output: 4953

addon/components/flexberry-file.js (3)

4-4: Add tests for the file component.

The TODO comment indicates missing tests. Consider adding comprehensive tests covering:

  • File upload/download functionality
  • Error handling scenarios
  • Unique ID generation

Would you like me to help create a test suite for this component?


Line range hint 1012-1029: Consider enhancing error handling in uploadFile method.

The error handling could be improved by:

  1. Adding more specific error types
  2. Including better error context in the reject case
  3. Logging errors for debugging

Consider this enhancement:

 }).fail((jqXhr, textStatus, errorThrown) => {
-  let errorContent = this.showUploadErrorModalDialog(file.name, errorThrown ? ' (' + errorThrown + ')' : '');
+  let errorDetails = {
+    status: jqXhr.status,
+    statusText: jqXhr.statusText,
+    error: errorThrown || 'Unknown error'
+  };
+  let errorContent = this.showUploadErrorModalDialog(
+    file.name,
+    `(${errorDetails.status}: ${errorDetails.error})`
+  );
+  console.error('File upload failed:', errorDetails);
   if (!isNone(this.get('uploadFail'))) {
     this.get('uploadFail')({
       uploadData: uploadData,
       response: jqXhr,
+      error: errorDetails,
       value: this.get('value')
     });
   }
-  reject(new Error(errorContent));
+  reject(Object.assign(new Error(errorContent), { details: errorDetails }));
 })

Line range hint 32-38: Add JSDoc documentation for the _fileInputId computed property.

The computed property lacks proper documentation explaining its purpose and behavior.

Add documentation like this:

/**
 * Generates a unique identifier for the file input element.
 * @property _fileInputId
 * @type {String}
 * @private
 * @computed elementId
 * @returns {String} A unique identifier either based on the elementId or generated using generateUniqueId
 */
addon/services/log.js (1)

401-404: Avoid overriding global console.error method

Overriding the global console.error can have unintended side effects on other parts of the application and third-party libraries that rely on the original console methods.

Instead of overriding global methods, consider extending the console functionality or creating a separate logging service to handle custom logging needs without affecting global behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d1c7d81 and 1a9024f.

📒 Files selected for processing (14)
  • addon/components/flexberry-file.js (2 hunks)
  • addon/components/flexberry/validation-summary.js (1 hunks)
  • addon/services/compatibility-validations.js (1 hunks)
  • addon/services/log.js (2 hunks)
  • tests/acceptance/components/flexberry-groupedit/flexberry-groupedit-sort-test.js (3 hunks)
  • tests/acceptance/components/flexberry-objectlistview/folv-user-settings-test.js (6 hunks)
  • tests/dummy/app/controllers/log-service-examples/settings-example.js (2 hunks)
  • tests/dummy/app/locales/en/translations.js (1 hunks)
  • tests/dummy/app/locales/ru/translations.js (1 hunks)
  • tests/dummy/app/models/ember-flexberry-dummy-application-user.js (0 hunks)
  • tests/integration/components/flexberry/validation-summary-test.js (1 hunks)
  • tests/unit/services/compatibility-validations-test.js (1 hunks)
  • tests/unit/services/device-test.js (2 hunks)
  • tests/unit/services/user-settings-test.js (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/dummy/app/models/ember-flexberry-dummy-application-user.js
🧰 Additional context used
🔇 Additional comments (19)
tests/unit/services/user-settings-test.js (1)

5-5: LGTM! Good modernization of Ember imports.

The change to import getOwner from @ember/application aligns with modern Ember practices and helps with tree-shaking.

addon/components/flexberry/validation-summary.js (1)

5-6: LGTM! Import statements modernized correctly.

The changes follow Ember Octane's best practices by replacing the monolithic Ember import with specific module imports. This change enables better tree-shaking and aligns with modern Ember patterns.

Let's verify if there are any remaining legacy Ember imports in the component:

✅ Verification successful

Let me gather more information about the component's implementation to ensure there are no remaining legacy patterns that need modernization.

This will help us verify:

  1. If there are any remaining legacy Ember patterns
  2. If all imports are properly modernized
  3. If the component's functionality relies on any other Ember features that might need updating

Import modernization is complete and correct

After reviewing the complete component implementation, I can confirm that:

  1. All Ember imports are properly modernized using the new module syntax
  2. The component uses computed.notEmpty correctly through the imported computed from @ember/object
  3. There are no remaining legacy Ember.* patterns in the code
  4. The component follows modern Ember practices while maintaining its functionality

The original review comment was accurate in its assessment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Ember.* usage in the component
# that might need modernization

rg -A 2 "Ember\." "addon/components/flexberry/validation-summary.js"

Length of output: 68


Script:

#!/bin/bash
# Check the entire content of the validation-summary component
cat "addon/components/flexberry/validation-summary.js"

Length of output: 1498

tests/unit/services/compatibility-validations-test.js (3)

1-1: LGTM! Import modernization looks good.

The change from Ember.get to a direct import from @ember/object aligns with modern Ember practices and enables better tree-shaking.


Line range hint 19-35: Test structure and assertions look good.

The test case effectively verifies that all validators are properly cached in the service. The initialization and assertions are well-structured.


Line range hint 1-13: Consider modernizing remaining imports.

While we're updating imports, consider using the new module imports for the validation-related imports as well. Let's verify if newer import paths are available.

tests/integration/components/flexberry/validation-summary-test.js (1)

1-2: LGTM! Import modernization looks good.

The change from using the broad Ember import to specific imports from @ember/array and @ember/runloop follows modern Ember best practices and improves code maintainability.

tests/acceptance/components/flexberry-groupedit/flexberry-groupedit-sort-test.js (5)

1-2: LGTM! Import statements follow modern Ember practices.

The replacement of broad Ember imports with specific module imports from @ember/array and @ember/runloop improves code clarity and follows current Ember best practices.


23-23: LGTM! Proper run loop usage in cleanup.

The change from Ember.run to run correctly utilizes the imported function while maintaining the same cleanup functionality.


29-29: LGTM! Proper array creation using modern syntax.

The change from Ember.A to A correctly utilizes the imported function while maintaining the same array initialization functionality.


31-31: LGTM! Proper run loop usage in test setup.

The change from Ember.run to run correctly utilizes the imported function for handling async operations during test record creation.


Line range hint 133-137: LGTM! Proper run loop usage in test cleanup.

The change from Ember.run to run correctly utilizes the imported function for handling async operations during test record cleanup.

tests/acceptance/components/flexberry-objectlistview/folv-user-settings-test.js (3)

1-3: LGTM! Import changes follow modern Ember practices.

The replacement of Ember namespace imports with specific module imports improves code maintainability and follows current Ember best practices.


32-32: LGTM! Service property modifications are properly implemented.

The use of the imported set function for modifying service properties is consistent and correct. The changes maintain the test's functionality while following modern Ember patterns.

Also applies to: 37-37, 147-147


38-38: LGTM! Run loop usage is properly implemented.

The changes correctly utilize the imported run function for managing async operations and test cleanup. The implementation maintains proper test isolation and follows Ember's run loop best practices.

Also applies to: 54-54, 187-187

tests/dummy/app/controllers/log-service-examples/settings-example.js (1)

254-254: LGTM: Successful migration to generateUniqueId utility.

The replacement of Ember's guid generation with the new generateUniqueId utility is correct and aligns with the PR's goal of actualizing imports.

addon/components/flexberry-file.js (2)

5-5: LGTM: Import change aligns with modern practices.

The addition of generateUniqueId import from a dedicated utility module is a good practice, moving away from the Ember namespace.


65-67: LGTM: Clean implementation of unique ID generation.

The computed property correctly handles both cases:

  • Uses the provided elementId when available
  • Falls back to generateUniqueId() when elementId is blank
tests/dummy/app/locales/en/translations.js (1)

716-721: LGTM! Translation strings updated to reflect console method usage.

The changes correctly update the translation strings to match the transition from Ember.Logger to native console methods, maintaining consistency with the underlying implementation changes.

tests/dummy/app/locales/ru/translations.js (1)

716-721: LGTM! Logging message strings updated to reflect console methods.

The changes correctly update the Russian translation strings to reference the standard console methods instead of Ember.Logger, maintaining consistency with the modernized logging implementation.

Comment on lines +5 to +7
import Service from '@ember/service';
import { set } from '@ember/object';
import { getOwner } from '@ember/application';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Update remaining Ember namespace usage for consistency

The verification revealed two types of inconsistencies that need to be addressed:

  • In app-state.js and adv-limit.js: The Ember.Service references appear only in JSDoc comments and don't affect the actual code since both files are already using the imported Service.
  • In user-settings.js: There's an actual usage of Ember.getOwner that should be updated to use the imported version for consistency.

Specific locations needing attention:

  • addon/services/user-settings.js: Replace Ember.getOwner with the imported getOwner from '@ember/application'
🔗 Analysis chain

Verify consistency of import changes across the codebase.

Let's ensure these import changes are consistently applied across all files using these Ember features.


Let me check the specific usage in the files that still use the Ember namespace to determine if there are inconsistencies that need to be addressed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of Ember.Service, Ember.set, and Ember.getOwner
# that might need to be updated for consistency.

echo "Checking for remaining Ember namespace usage..."
rg -l "Ember\.(Service|set|getOwner)" --type js

echo "Verifying new import pattern usage..."
rg -l "import (Service|set|getOwner) from '@ember/" --type js

Length of output: 743


Script:

#!/bin/bash
# Check the actual usage context in files still using Ember namespace
echo "Checking app-state.js..."
rg "Ember\.(Service|set|getOwner)" addon/services/app-state.js -B 2 -A 2

echo -e "\nChecking adv-limit.js..."
rg "Ember\.(Service|set|getOwner)" addon/services/adv-limit.js -B 2 -A 2

echo -e "\nChecking user-settings.js..."
rg "Ember\.(Service|set|getOwner)" addon/services/user-settings.js -B 2 -A 2

Length of output: 985

@@ -10,7 +11,7 @@ module('Unit | Service | device', {
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Inconsistent usage of getOwner between setup and teardown

The code uses Ember.getOwner in beforeEach but getOwner in afterEach. This inconsistency should be resolved by using the imported getOwner consistently.

Update the beforeEach hook to use the imported getOwner:

  beforeEach() {
-   sinon.stub(Ember, 'getOwner').returns({ application: { deviceService: {} } });
+   sinon.stub(getOwner).returns({ application: { deviceService: {} } });
  },

Also applies to: 14-14

Comment on lines 1 to +2
import Ember from 'ember';
import { getOwner } from '@ember/application';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Complete the migration from Ember namespace imports

While you've added the specific import for getOwner, the code still relies on the global Ember import. This is inconsistent with the PR's objective of actualizing imports.

Consider updating the imports to fully migrate away from the global Ember namespace:

-import Ember from 'ember';
import { getOwner } from '@ember/application';

Committable suggestion was skipped due to low confidence.

Comment on lines +180 to 182
let $perPageElement = $('div.flexberry-dropdown div.text');
assert.equal($perPageElement.length, 1, "Элемент количества записей на странице найден.");
assert.equal($perPageElement.text(), expectedCount, `Количество элементов на странице равно заданному: ${expectedCount}.`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using data-test- selectors for more reliable tests.*

While the jQuery usage is correct, the selector 'div.flexberry-dropdown div.text' is somewhat fragile. Consider using dedicated test selectors for more reliable and maintainable tests.

-  let $perPageElement = $('div.flexberry-dropdown div.text');
+  let $perPageElement = $('[data-test-per-page-dropdown]');

Also update the corresponding component template to include the test selector:

<div class="flexberry-dropdown" data-test-per-page-dropdown>
  <div class="text">
    {{perPage}}
  </div>
</div>

Comment on lines +1 to +3
import Ember from 'ember'; //TODO Import Module. Replace Ember.Logger
// import { generateGuid } from '@ember/object/internals';
import generateUniqueId from 'ember-flexberry-data/utils/generate-unique-id';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Complete the TODO: Replace Ember.Logger usage with native console methods.

The TODO comment indicates that Ember.Logger needs to be replaced, but the file still uses Ember.Logger in multiple places. This is inconsistent with the PR's goal of actualizing imports.

Replace Ember.Logger with native console methods throughout the file. For example:

-Ember.Logger.error(...)
+console.error(...)

-Ember.Logger.log(...)
+console.log(...)

-Ember.Logger.info(...)
+console.info(...)

Committable suggestion was skipped due to low confidence.

Comment on lines +406 to +409
console.warn = function(warn) {
originalEmberLoggerError(warn);
_this._onError(warn, true);
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect use of originalEmberLoggerError in console method overrides

In the overridden console methods (warn, deprecated, log, info, debug), you're calling originalEmberLoggerError instead of the corresponding original methods. This causes all logs to be treated as errors, which may lead to incorrect logging levels and confusion.

To fix this, call the appropriate original console method in each override. Ensure that you've cached these original methods correctly.

Apply this diff to fix the issue:

// Override console.warn
console.warn = function(warn) {
-   originalEmberLoggerError(warn);
+   originalEmberLoggerWarn(warn);
    _this._onError(warn, true);
};

// Override console.deprecated
console.deprecated = function(deprecate) {
-   originalEmberLoggerError(deprecate);
+   originalEmberLoggerDeprecate(deprecate);
    _this._onError(deprecate, true);
};

// Override console.log
console.log = function(log) {
-   originalEmberLoggerError(log);
+   originalEmberLoggerLog(log);
    _this._onError(log, true);
};

// Override console.info
console.info = function(info) {
-   originalEmberLoggerError(info);
+   originalEmberLoggerInfo(info);
    _this._onError(info, true);
};

// Override console.debug
console.debug = function(debug) {
-   originalEmberLoggerError(debug);
+   originalEmberLoggerDebug(debug);
    _this._onError(debug, true);
};

Also applies to: 411-414, 416-419, 421-424, 426-429

Comment on lines +411 to +414
console.deprecated = function(deprecate) {
originalEmberLoggerError(deprecate);
_this._onError(deprecate, true);
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Usage of non-standard console.deprecated method

The console object does not have a standard deprecated method. Adding non-standard methods to the global console object may lead to confusion and compatibility issues.

Consider using console.warn with a clear deprecation message or creating a custom method within your logging service to handle deprecation notices.

Comment on lines +436 to +535
// }
// });
// };

// Extend Ember.Logger.log logic.
let originalEmberLoggerLog = Ember.Logger.log;
let originalEmberLoggerLog = console.log.bind;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'log',
methodReference: originalEmberLoggerLog
});

Ember.Logger.log = function() {
originalEmberLoggerLog(...arguments);
// Ember.Logger.log = function() {
// originalEmberLoggerLog(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.log, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.log, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };

// Extend Ember.Logger.info logic.
let originalEmberLoggerInfo = Ember.Logger.info;
let originalEmberLoggerInfo = console.info;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'info',
methodReference: originalEmberLoggerInfo
});

Ember.Logger.info = function() {
originalEmberLoggerInfo(...arguments);
// Ember.Logger.info = function() {
// originalEmberLoggerInfo(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.info, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.info, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };

// Extend Ember.Logger.debug logic.
let originalEmberLoggerDebug = Ember.Logger.debug;
let originalEmberLoggerDebug = console.debug;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'debug',
methodReference: originalEmberLoggerDebug
});

Ember.Logger.debug = function() {
originalEmberLoggerDebug(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.debug, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// Ember.Logger.debug = function() {
// originalEmberLoggerDebug(...arguments);

// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.debug, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove commented-out code for better maintainability

There are large blocks of commented-out code related to Ember.Logger methods from lines 436 to 535. Keeping obsolete code can clutter the codebase and reduce readability.

If this code is no longer needed, consider removing it to clean up the codebase.

Comment on lines +378 to +380
let originalEmberLoggerError = console.error;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure correct context when caching original console methods

When caching the original console methods, it's important to bind them to the console object to preserve the correct context, especially for methods like console.log.

Modify the caching of the original methods to include binding:

let originalEmberLoggerError = console.error;
+originalEmberLoggerError = originalEmberLoggerError.bind(console);
originalMethodsCache.pushObject({
  methodOwner: console,
  methodName: 'error',
  methodReference: originalEmberLoggerError
});

Repeat this binding for other console methods as needed.

Committable suggestion was skipped due to low confidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant