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

Adds response header handling and unit tests #12

Merged
merged 18 commits into from
Apr 20, 2024

Commits on Jan 29, 2024

  1. feat: Add TriggerStyle enum and HtmxResponse methods

    This commit adds a new file `TriggerStyle.cs` which contains the `TriggerStyle` enum. The enum defines three trigger styles for events in an HTMX response.
    
    In addition, this commit modifies the `HtmxResponse.cs` file to include several new methods:
    - `Location(string url)`: Sets the location header for client-side redirect.
    - `PushUrl(string url)`: Pushes a new URL onto the history stack.
    - `Redirect(string url)`: Sets the redirect header for client-side redirect.
    - `Refresh()`: Enables a client-side full refresh of the page.
    - `ReplaceUrl(string url)`: Replaces the current URL in the location bar.
    - `Reswap(SwapStyle swapStyle)`: Allows specifying how the response will be swapped.
    - `Retarget(string selector)`: Updates the target of content update to a different element on the page.
    - `Reselect(string selector)`: Allows choosing which part of the response is used to be swapped in.
    - `Trigger(string eventName, object? detail = null, TriggerStyle timing = TriggerStyle.Default)`: Triggers client-side events with optional event details and timing.
    
    These changes enhance functionality related to handling HTMX responses.
    tanczosm committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    1218d53 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6f60290 View commit details
    Browse the repository at this point in the history
  3. Switch from HashSet to retain event ordering

    Switch from HashSet to retain event ordering
    
    The code changes in this commit switch from using a HashSet to using a List in order to retain the ordering of events. This change ensures that the events are stored and outputted in the same order they were added, which is important for maintaining consistency. Additionally, a boolean variable "exists" is introduced to check if an event already exists before adding it to the list.
    tanczosm committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    12b9cd2 View commit details
    Browse the repository at this point in the history

Commits on Jan 30, 2024

  1. feat: Add HtmxResponse class tests

    This commit adds the HtmxResponse class implementation, which is responsible for handling HTTP responses in the Htmxor library. It includes methods for adding various response headers such as Location, PushUrl, Redirect, Refresh, ReplaceUrl, Reswap, Retarget, Reselect, and Trigger.
    
    The commit also includes unit tests for each of these methods to ensure their functionality. The tests cover scenarios such as adding different headers with different values and checking if the headers are correctly set in the response.
    
    Additionally, a MockHeaderDictionary class is added to provide a mock implementation of the IHeaderDictionary interface for testing purposes. This allows us to simulate HTTP headers in our unit tests without relying on actual HTTP requests or responses.
    
    Overall, this commit introduces the necessary code changes to support Htmx response handling and provides comprehensive test coverage for this functionality.
    tanczosm committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    2435f57 View commit details
    Browse the repository at this point in the history
  2. refactor: code cleanup

    tanczosm committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    413d468 View commit details
    Browse the repository at this point in the history
  3. Simplify property setting

    tanczosm committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    bbc37a5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    cd20c02 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    0da37bc View commit details
    Browse the repository at this point in the history
  6. refactor: refactor mock HTTP classes for testing purposes

    - Change access modifiers from internal to public in `MockHeaderDictionary`, `MockHttpContext`, `MockHttpRequest`, `MockHttpResponse`, and `MockResponseCookies` classes.
    tanczosm committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    26b32e0 View commit details
    Browse the repository at this point in the history
  7. fix: swapped tabs for spaces

    tanczosm committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    9defd75 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    e2da8bd View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    594a60e View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    88c3e4a View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    85c64b7 View commit details
    Browse the repository at this point in the history

Commits on Jan 31, 2024

  1. Configuration menu
    Copy the full SHA
    59b6c6a View commit details
    Browse the repository at this point in the history
  2. refactor: Update HtmxResponse.cs with a static JsonSerializerOptions

    - Make _serializerOptions field static for improved performance and memory usage.
    tanczosm committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    530bb1f View commit details
    Browse the repository at this point in the history
  3. refactor: simple aggregate of existing headers and merge event with d…

    …etail into the result
    
    This commit modifies the `MergeTrigger` method in the `HtmxResponse` class. It introduces changes to aggregate existing headers and merge events with details into the result. The code now uses a `StringBuilder` to build the JSON representation of aggregated properties across all header values for a given header key. Duplicate keys are not removed for performance reasons, as the produced JSON is still valid. This approach does not validate any syntax of existing headers as a performance consideration.
    tanczosm committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    aeac9cc View commit details
    Browse the repository at this point in the history

Commits on Apr 16, 2024

  1. Configuration menu
    Copy the full SHA
    988b09b View commit details
    Browse the repository at this point in the history