What happens when you have insurance at the time of an accident and then it gets cancelled does the insurance still cover the accident?

Yes it does. The cancellation of an insurance policy is not retroactive.