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

Enhance user actions UI and add disassociation confirmation in tests #593

Merged
merged 3 commits into from
Jan 16, 2025
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
15 changes: 11 additions & 4 deletions pycompanies/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_company_admin_should_have_no_matching_company_in_context(logged_client)
@pytest.mark.django_db
def test_company_disassociate_last_user_from_company(logged_client, user):
"""
Message in context should notice if is the last user associated to the company
Verifies that the message is correct and the profile is deleted when disassociating
"""
DISASSOCIATE_MESSAGE = ('Esta es la última persona vinculada a esta empresa '
'¿Estás seguro que deseas desvincularla?')
Expand All @@ -206,11 +206,18 @@ def test_company_disassociate_last_user_from_company(logged_client, user):
COMPANY_DISSASOCIATE_URL = reverse('companies:disassociate',
kwargs={'pk': user_company_profile.id})

response = logged_client.get(COMPANY_DISSASOCIATE_URL, data={'empresa': company_1})

assert 200 == response.status_code
# Simula la carga de la página de confirmación
response = logged_client.get(COMPANY_DISSASOCIATE_URL)
assert response.status_code == 200
assert DISASSOCIATE_MESSAGE == response.context_data['message']

# Simula la acción de desasociarse (esto es lo que realmente elimina el perfil)
response = logged_client.post(COMPANY_DISSASOCIATE_URL)

# Verifica redirección después de desasociarse
assert response.status_code == 302 # Redirección exitosa
assert not UserCompanyProfile.objects.filter(id=user_company_profile.id).exists()


@pytest.mark.django_db
def test_company_disassociate_one_user_from_company(logged_client, user):
Expand Down
25 changes: 18 additions & 7 deletions templates/companies/_user_actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@
</div>
</div>

<div class="list-group-item">
<a href="{% url 'joboffers:admin' %}" class="btn btn-default">
{% trans 'Administrar Ofertas' %}
</a>
<a href="{% url 'companies:analytics' own_company.id %}" class="btn btn-dark-green">
{% trans 'Analítica de Ofertas' %}
</a>
<div class="list-group-item text-center">
<div class="btn-group" role="group">
<a href="{% url 'joboffers:admin' %}" class="btn btn-default">
{% trans 'Administrar Ofertas' %}
</a>
<a href="{% url 'companies:analytics' own_company.id %}" class="btn btn-success">
{% trans 'Analítica de Ofertas' %}
</a>
</div>
<div style="margin-top: 10px;">
<form action="{% url 'companies:disassociate' user.company.first.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-danger">
{% trans 'Desasociarse' %}
</button>
</form>
</div>
</div>

{% else %}
<div class="list-group-item">
<div class="h4 list-group-item-heading flex-center">
Expand Down
Loading