-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* merge * refactor alert to accordion, add cypress test * revert change to business store for slim * fix lint * couple more fixes * fix merge error add padding to open alert * remove outdated component test for Alerts * fix lint * some tweaks from pr feedback, and add cypress screenshots to gitignore
- Loading branch information
1 parent
eec45a3
commit 2602e86
Showing
11 changed files
with
333 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ logs | |
|
||
# local ide stuff | ||
.vscode | ||
|
||
#Cypress screenshots | ||
cypress/screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
context('Business dashboard -> Alerts main component', () => { | ||
it('Alerts are rendered when business has alerts', () => { | ||
cy.visitBusinessDashFor('businessInfo/ben/active-frozen-not_in_good_standing.json') | ||
|
||
// the alerts exist | ||
cy.get('[data-cy="alerts-display"]').should('exist') | ||
cy.get('[data-cy="alert-display"]').should('have.length', 4) | ||
|
||
// accordion headers exist | ||
cy.get('[data-cy="alert-display"]').eq(0).contains('This business is frozen').should('be.visible') | ||
cy.get('[data-cy="alert-display"]').eq(2).contains('This business is not in good standing').should('be.visible') | ||
|
||
// expand the second item | ||
cy.get('[data-cy="alert-display"]').eq(2).find('[data-cy="alert-icon"]').click() | ||
|
||
cy.get('[data-cy="alert-description"]').eq(0).should('not.be.visible') | ||
cy.get('[data-cy="alert-description"]').eq(1).contains('Email').should('be.visible') | ||
}) | ||
|
||
it('Shouldn\'t show alerts when business has no alerts', () => { | ||
cy.visitBusinessDash('BC0871427', 'SP') | ||
|
||
cy.get('[data-cy="alerts-display"]').should('not.exist') | ||
cy.get('[data-cy="alert-display"]').should('not.exist') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<template> | ||
<div data-cy="alerts-display"> | ||
<UAccordion | ||
color="black" | ||
variant="outline" | ||
size="sm" | ||
:items="alerts" | ||
> | ||
<template #default="{ item, open }"> | ||
<BcrosAlert | ||
:alert="item" | ||
:open="open" | ||
:show-description="false" | ||
:contact="contact" | ||
/> | ||
</template> | ||
<template #item="{ item, open }"> | ||
<BcrosAlert :open="open" :alert="item" :show-header="false" :contact="contact" /> | ||
</template> | ||
</UAccordion> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
defineProps<{ alerts: Array<Partial<AlertI>>, contact: boolean }>() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<template> | ||
<div data-cy="alert-display" class="px-3 py-3"> | ||
<UIcon | ||
v-if="showHeader" | ||
:class="`${iconColour} mr-2 font-semibold`" | ||
:name="iconName" | ||
data-cy="alert-icon" | ||
/> | ||
<span v-if="showHeader" class="font-semibold flex-auto">{{ alertHeader }}</span> | ||
<UButton | ||
v-if="showHeader" | ||
color="primary" | ||
:icon="actualExpanded ? 'i-mdi-chevron-up' : 'i-mdi-chevron-down'" | ||
:label="actualExpanded ? 'Hide Details' : 'View Details'" | ||
trailing | ||
variant="ghost" | ||
class="float-right" | ||
:ui="{ icon: { base: 'transition-all' } }" | ||
@click="toggleExpanded()" | ||
/> | ||
<div v-if="actualExpanded && showDescription" data-cy="alert-description"> | ||
<p>{{ $t(alertDescription) }}</p> | ||
<p v-if="contact" class="mt-3"> | ||
{{ contact }}: | ||
</p> | ||
<p v-if="contact" class="mt-3"> | ||
<bcros-contact-info class="font-normal font-16 mt-4" :contacts="getContactInfo('registries')" /> | ||
</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { getAlertIcon, getAlertHeader, getAlertColour } from '~/utils/alert' | ||
interface Props { | ||
alert: Partial<AlertI>, | ||
contact: boolean, | ||
showHeader?: boolean, | ||
showDescription?: boolean, | ||
open?: boolean, | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
showHeader: true, | ||
showDescription: true | ||
}) | ||
const expanded = props.showHeader ? ref(false) : ref(true) | ||
const actualExpanded = computed((): boolean => { | ||
return expanded.value || props.open | ||
}) | ||
const toggleExpanded = () => { | ||
if (typeof props.open === 'boolean') { | ||
return | ||
} | ||
expanded.value = !expanded.value | ||
} | ||
const t = useNuxtApp().$i18n.t | ||
const iconName = computed((): string => { | ||
return getAlertIcon(props.alert) | ||
}) | ||
const iconColour = computed((): string => { | ||
return getAlertColour(props.alert) | ||
}) | ||
const alertHeader = computed((): string => { | ||
return getAlertHeader(props.alert) | ||
}) | ||
const alertDescription = computed((): string => { | ||
const date: string = props.alert?.date || 'unknown' | ||
const description = t(props.alert.alertType | ||
? 'alerts.descriptions.' + props.alert.alertType | ||
: props.alert.description) | ||
description.replaceAll('[date]', date) | ||
return description | ||
}) | ||
const contact = computed((): string => { | ||
// 1 - assistance | ||
// 2 - questions | ||
// 3 - must contact | ||
// 4 - action | ||
if (props.alert.alertType === AlertTypesE.AMALGAMATION) { | ||
return t('alerts.contact2') | ||
} | ||
if (props.alert.alertType === AlertTypesE.COMPLIANCE) { | ||
return t('alerts.contact3') | ||
} | ||
if ((props.alert.alertType === AlertTypesE.MISSINGINFO) || (props.alert.alertType === AlertTypesE.STANDING)) { | ||
return t('alerts.contact4') | ||
} | ||
return t('alerts.contact') | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** Alert Severities. */ | ||
export enum AlertSeverityE { | ||
SUCCESS = 'success', | ||
ERROR = 'error', | ||
INFO = 'info', | ||
WARNING = 'warning' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** Alert Types. */ | ||
export enum AlertTypesE { | ||
FROZEN = 'frozen', | ||
DISABLED = 'disabled', | ||
STANDING = 'standing', | ||
DISSOLUTION = 'dissolution', | ||
COMPLIANCE = 'compliance', | ||
MISSINGINFO = 'missinginfo', | ||
NONENTITY = 'nonentity', | ||
AMALGAMATION = 'amalgamation', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { AlertTypesE, AlertSeverityE } from '#imports' | ||
|
||
export interface AlertI { | ||
severity: AlertSeverityE | undefined | ||
alertType: AlertTypesE | undefined | ||
text: string | undefined | ||
description: string | undefined | ||
date: any | undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export const getAlertHeader = function(alert: Partial<AlertI>): string { | ||
const t = useNuxtApp().$i18n.t | ||
return t(alert.alertType ? 'alerts.headers.' + alert.alertType : alert.text) | ||
} | ||
|
||
export const getAlertIcon = function(alert: Partial<AlertI>): string { | ||
if (alert.alertType) { | ||
return 'i-mdi-alert' | ||
} | ||
|
||
switch (alert.severity?.toLowerCase()) { | ||
case 'error': | ||
return 'i-mdi-alert-circle' | ||
case 'warning': | ||
return 'i-mdi-alert' | ||
case 'info': | ||
return 'i-mdi-information' | ||
case 'success': | ||
return 'i-mdi-check' | ||
default: | ||
return 'i-mdi-alert-circle' | ||
} | ||
} | ||
|
||
export const getAlertColour = function(alert: Partial<AlertI>): string { | ||
if (alert.alertType) { | ||
return 'text-yellow-500' | ||
} | ||
|
||
switch (alert.severity?.toLowerCase()) { | ||
case 'error': | ||
return 'text-red-500' | ||
case 'warning': | ||
return 'text-yellow-500' | ||
case 'info': | ||
return 'text-blue-500' | ||
case 'success': | ||
return 'text-green-500' | ||
default: | ||
return 'text-yellow-500' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters