Skip to content

Commit

Permalink
feat(FSADT1-1429): Unregistered business client type is only viewed b… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia authored Aug 14, 2024
1 parent bd34c52 commit 14c5949
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.bc.gov.app.dto.ValidationError;
import ca.bc.gov.app.dto.client.BusinessTypeEnum;
import ca.bc.gov.app.dto.client.ClientBusinessInformationDto;
import ca.bc.gov.app.dto.client.ClientTypeEnum;
import ca.bc.gov.app.dto.client.ValidationSourceEnum;
import ca.bc.gov.app.validator.ForestClientValidator;
import io.micrometer.observation.annotation.Observed;
Expand Down Expand Up @@ -44,8 +45,8 @@ public Mono<ValidationError> validate(ClientBusinessInformationDto target, Integ
}

if (
BusinessTypeEnum.U.equals(
BusinessTypeEnum.fromValue(target.businessType())
ClientTypeEnum.USP.equals(
ClientTypeEnum.fromValue(target.clientType())
) && !target.businessName().matches(".*\\s+.*")
) {
return Mono.just(
Expand Down
2 changes: 1 addition & 1 deletion backend/src/test/java/ca/bc/gov/app/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public class TestConstants {
"",
"forest1",
"U",
"I",
"USP",
"",
"SP",
LocalDate.of(1975, 1, 31),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void shouldSupportAllValidationSources(ValidationSourceEnum source, boolean supp
void shouldValidate(
String businessName,
String businessType,
String clientType,
String expectedMessage
) {

Expand All @@ -40,7 +41,7 @@ void shouldValidate(
StringUtils.EMPTY,
businessName,
businessType,
StringUtils.EMPTY,
clientType,
StringUtils.EMPTY,
StringUtils.EMPTY,
null,
Expand Down Expand Up @@ -75,12 +76,12 @@ void shouldValidate(
private static Stream<Arguments> validation() {
return
Stream.of(
Arguments.of(StringUtils.EMPTY, StringUtils.EMPTY, "You must enter a business name."),
Arguments.of(StringUtils.EMPTY, "R", "You must select your B.C. registered business name from the list."),
Arguments.of("Mainé", StringUtils.EMPTY, "Mainé has an invalid character."),
Arguments.of("Corporation".repeat(6), StringUtils.EMPTY, "This field has a 60 character limit."),
Arguments.of("Corporation", "U", "Business name must be composed of first and last name"),
Arguments.of("Corporation", "R", StringUtils.EMPTY)
Arguments.of(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, "You must enter a business name."),
Arguments.of(StringUtils.EMPTY, "R", StringUtils.EMPTY, "You must select your B.C. registered business name from the list."),
Arguments.of("Mainé", StringUtils.EMPTY, StringUtils.EMPTY, "Mainé has an invalid character."),
Arguments.of("Corporation".repeat(6), StringUtils.EMPTY, StringUtils.EMPTY, "This field has a 60 character limit."),
Arguments.of("Corporation", StringUtils.EMPTY, "USP", "Business name must be composed of first and last name"),
Arguments.of("Corporation", "R", StringUtils.EMPTY, StringUtils.EMPTY)
);
}

Expand Down
17 changes: 12 additions & 5 deletions frontend/src/pages/FormStaffPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ import LocationsWizardStep from "@/pages/staffform/LocationsWizardStep.vue";
import ContactsWizardStep from "@/pages/staffform/ContactsWizardStep.vue";
import ReviewWizardStep from "@/pages/staffform/ReviewWizardStep.vue";
// Session
import ForestClientUserSession from "@/helpers/ForestClientUserSession";
// @ts-ignore
import ArrowRight16 from "@carbon/icons-vue/es/arrow--right/16";
// @ts-ignore
import Check16 from "@carbon/icons-vue/es/checkmark/16";
const isAdminInd = ["CLIENT_ADMIN"].some(authority => ForestClientUserSession.authorities.includes(authority));
const clientTypesList: CodeNameType[] = [
{
code: "I",
Expand All @@ -76,12 +80,15 @@ const clientTypesList: CodeNameType[] = [
{
code: "F",
name: "Ministry of Forests",
},
{
}
];
if (isAdminInd) {
clientTypesList.push({
code: "U",
name: "Unregistered company",
},
];
});
}
const notificationBus = useEventBus<ValidationMessageType | undefined>(
"error-notification"
Expand Down
78 changes: 64 additions & 14 deletions frontend/tests/unittests/pages/FormStaffPage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,84 @@
import { createRouter, createMemoryHistory } from 'vue-router';
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import { mount } from '@vue/test-utils';
import FormStaffPage from '@/pages/FormStaffPage.vue';
import ForestClientUserSession from '@/helpers/ForestClientUserSession';

describe('FormStaffPage', () => {
// Mocking the ForestClientUserSession
vi.mock('@/helpers/ForestClientUserSession', () => ({
default: {
authorities: []
}
}));

it('renders the clientType dropdown with the expected order of elements', async () => {
const router = createRouter({
history: createMemoryHistory(),
routes: [{ path: '/', component: FormStaffPage },],
});
describe('FormStaffPage', () => {
const router = createRouter({
history: createMemoryHistory(),
routes: [{ path: '/', component: FormStaffPage }],
});

const wrapper = mount(FormStaffPage, {
const mountComponent = () => {
return mount(FormStaffPage, {
global: {
plugins: [router],
},
});
};

it('renders the clientType dropdown with the expected order of elements for a non-admin user', async () => {
// Mock as non-admin user
ForestClientUserSession.authorities = [];

const wrapper = mountComponent();
const clientTypeDropdown = wrapper.find('#clientType');

// Extract the innerHTML of the dropdown
const dropdownHTML = clientTypeDropdown.element.innerHTML;

// Parse the innerHTML to extract the text content of each dropdown item
const parser = new DOMParser();
const doc = parser.parseFromString(`<cds-combo-box>${dropdownHTML}</cds-combo-box>`, 'text/html');
const dropdownItems = doc.querySelectorAll('cds-combo-box-item');

const dropdownValues = Array.from(dropdownItems).map(item => item.textContent.trim());

const expectedDropdownValues = [
'Individual',
'BC registered business',
'First Nation',
'Government',
'Ministry of Forests',
];

expect(dropdownValues).toEqual(expectedDropdownValues);
});

it('renders the clientType dropdown with the expected order of elements for an admin user', async () => {
// Mock as admin user
ForestClientUserSession.authorities = ['CLIENT_ADMIN'];

const wrapper = mountComponent();
const clientTypeDropdown = wrapper.find('#clientType');

// Extract the innerHTML of the dropdown
const dropdownHTML = clientTypeDropdown.element.innerHTML;

// Parse the innerHTML to extract the text content of each dropdown item
const parser = new DOMParser();
const doc = parser.parseFromString(`<cds-combo-box>${dropdownHTML}</cds-combo-box>`, 'text/html');
const dropdownItems = doc.querySelectorAll('cds-combo-box-item');

// Extract the text content from each dropdown item
const dropdownValues = Array.from(dropdownItems).map(item => item.textContent.trim());

expect(dropdownValues).toEqual(['Individual','BC registered business','First Nation','Government','Ministry of Forests','Unregistered company']);

const expectedDropdownValues = [
'Individual',
'BC registered business',
'First Nation',
'Government',
'Ministry of Forests',
'Unregistered company',
];

expect(dropdownValues).toEqual(expectedDropdownValues);
});
});
});

0 comments on commit 14c5949

Please sign in to comment.